Merge pull request #7797 from JKingsnorth/CRM-17977
[civicrm-core.git] / tests / phpunit / api / v3 / MessageTemplateTest.php
CommitLineData
397e0e51
EC
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
397e0e51 5 +--------------------------------------------------------------------+
fa938177 6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 27
397e0e51
EC
28/**
29 * Test class for Template API - civicrm_msg_template*
30 *
6c6e6187 31 * @package CiviCRM_APIv3
acb109b7 32 * @group headless
397e0e51 33 */
63c9befe 34class api_v3_MessageTemplateTest extends CiviUnitTestCase {
397e0e51 35 /**
fe482240 36 * Assume empty database with just civicrm_data.
397e0e51 37 */
63c9befe 38 protected $entity = 'MessageTemplate';
397e0e51
EC
39 protected $params;
40
41
00be9182 42 public function setUp() {
397e0e51
EC
43 $this->_apiversion = 3;
44 parent::setUp();
ba399c15 45 $this->useTransaction(TRUE);
c6327d7d 46 $template = CRM_Core_DAO::createTestObject('CRM_Core_DAO_MessageTemplate')->toArray();
397e0e51
EC
47 $this->params = array(
48 'msg_title' => $template['msg_title'],
49 'msg_subject' => $template['msg_subject'],
50 'msg_text' => $template['msg_text'],
51 'msg_html' => $template['msg_html'],
52 'workflow_id' => $template['workflow_id'],
53 'is_default' => $template['is_default'],
54 'is_reserved' => $template['is_reserved'],
397e0e51
EC
55 );
56 }
397e0e51 57
6c6e6187 58 /**
eceb18cc 59 * Test create function succeeds.
397e0e51
EC
60 */
61 public function testCreate() {
63c9befe 62 $result = $this->callAPIAndDocument('MessageTemplate', 'create', $this->params, __FUNCTION__, __FILE__);
397e0e51
EC
63 $this->getAndCheck($this->params, $result['id'], $this->entity);
64 }
65
66 /**
fe482240
EM
67 * Test get function succeeds.
68 *
69 * This is actually largely tested in the get action on create.
70 *
71 * Add extra checks for any 'special' return values or
397e0e51 72 * behaviours
397e0e51
EC
73 */
74 public function testGet() {
63c9befe 75 $result = $this->callAPIAndDocument('MessageTemplate', 'get', $this->params, __FUNCTION__, __FILE__);
ba4a1892
TM
76 $this->assertEquals(1, $result['count']);
77 $this->assertNotNull($result['values'][$result['id']]['id']);
397e0e51
EC
78 }
79
6c6e6187 80 /**
eceb18cc 81 * Check the delete function succeeds.
6c6e6187 82 */
397e0e51
EC
83 public function testDelete() {
84 $entity = $this->createTestEntity();
63c9befe 85 $result = $this->callAPIAndDocument('MessageTemplate', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__);
397e0e51 86 $checkDeleted = $this->callAPISuccess($this->entity, 'get', array(
21dfd5f5 87 'id' => $entity['id'],
397e0e51 88 ));
ba4a1892 89 $this->assertEquals(0, $checkDeleted['count']);
397e0e51
EC
90 }
91
92}