Merge pull request #4764 from rohankatkar/CRM-15615
[civicrm-core.git] / tests / phpunit / api / v3 / MessageTemplateTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26 */
27
28 require_once 'CiviTest/CiviUnitTestCase.php';
29
30 /**
31 * Test class for Template API - civicrm_msg_template*
32 *
33 * @package CiviCRM_APIv3
34 */
35 class api_v3_MessageTemplateTest extends CiviUnitTestCase {
36 /**
37 * Assume empty database with just civicrm_data
38 */
39 protected $entity = 'MessageTemplate';
40 protected $params;
41
42
43 function setUp() {
44 $this->_apiversion = 3;
45 parent::setUp();
46 $this->quickCleanup(array('civicrm_msg_template'));
47 $template = CRM_Core_DAO::createTestObject('CRM_Core_DAO_MessageTemplate')->toArray();
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'],
56 );
57 }
58 function tearDown() {}
59
60 /**
61 * Test create function succeeds
62 */
63 public function testCreate() {
64 $result = $this->callAPIAndDocument('MessageTemplate', 'create', $this->params, __FUNCTION__, __FILE__);
65 $this->getAndCheck($this->params, $result['id'], $this->entity);
66 }
67
68 /**
69 * Test get function succeeds (this is actually largely tested in the get
70 * action on create. Add extra checks for any 'special' return values or
71 * behaviours
72 *
73 */
74 public function testGet() {
75 $result = $this->callAPIAndDocument('MessageTemplate', 'get', $this->params, __FUNCTION__, __FILE__);
76 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
77 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
78 }
79
80 /**
81 * Check the delete function succeeds
82 */
83 public function testDelete() {
84 $entity = $this->createTestEntity();
85 $result = $this->callAPIAndDocument('MessageTemplate', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__);
86 $checkDeleted = $this->callAPISuccess($this->entity, 'get', array(
87 'id' => $entity['id']
88 ));
89 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
90 }
91
92 }
93