Merge pull request #5536 from totten/4.5-httpclient
[civicrm-core.git] / tests / phpunit / api / v3 / MessageTemplateTest.php
CommitLineData
397e0e51
EC
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
397e0e51 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
397e0e51
EC
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
397e0e51
EC
27
28require_once 'CiviTest/CiviUnitTestCase.php';
29
30/**
31 * Test class for Template API - civicrm_msg_template*
32 *
6c6e6187 33 * @package CiviCRM_APIv3
397e0e51 34 */
63c9befe 35class api_v3_MessageTemplateTest extends CiviUnitTestCase {
397e0e51 36 /**
fe482240 37 * Assume empty database with just civicrm_data.
397e0e51 38 */
63c9befe 39 protected $entity = 'MessageTemplate';
397e0e51
EC
40 protected $params;
41
42
00be9182 43 public function setUp() {
397e0e51
EC
44 $this->_apiversion = 3;
45 parent::setUp();
ba399c15 46 $this->useTransaction(TRUE);
c6327d7d 47 $template = CRM_Core_DAO::createTestObject('CRM_Core_DAO_MessageTemplate')->toArray();
397e0e51
EC
48 $this->params = array(
49 'msg_title' => $template['msg_title'],
50 'msg_subject' => $template['msg_subject'],
51 'msg_text' => $template['msg_text'],
52 'msg_html' => $template['msg_html'],
53 'workflow_id' => $template['workflow_id'],
54 'is_default' => $template['is_default'],
55 'is_reserved' => $template['is_reserved'],
397e0e51
EC
56 );
57 }
397e0e51 58
6c6e6187 59 /**
eceb18cc 60 * Test create function succeeds.
397e0e51
EC
61 */
62 public function testCreate() {
63c9befe 63 $result = $this->callAPIAndDocument('MessageTemplate', 'create', $this->params, __FUNCTION__, __FILE__);
397e0e51
EC
64 $this->getAndCheck($this->params, $result['id'], $this->entity);
65 }
66
67 /**
fe482240
EM
68 * Test get function succeeds.
69 *
70 * This is actually largely tested in the get action on create.
71 *
72 * Add extra checks for any 'special' return values or
397e0e51 73 * behaviours
397e0e51
EC
74 */
75 public function testGet() {
63c9befe 76 $result = $this->callAPIAndDocument('MessageTemplate', 'get', $this->params, __FUNCTION__, __FILE__);
397e0e51
EC
77 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
78 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
79 }
80
6c6e6187 81 /**
eceb18cc 82 * Check the delete function succeeds.
6c6e6187 83 */
397e0e51
EC
84 public function testDelete() {
85 $entity = $this->createTestEntity();
63c9befe 86 $result = $this->callAPIAndDocument('MessageTemplate', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__);
397e0e51 87 $checkDeleted = $this->callAPISuccess($this->entity, 'get', array(
21dfd5f5 88 'id' => $entity['id'],
397e0e51
EC
89 ));
90 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
91 }
92
93}