Enotice compliance for mailing test
[civicrm-core.git] / tests / phpunit / api / v3 / MailingTest.php
1 <?php
2 /*
3 * File for the TestMailing class
4 *
5 * (PHP 5)
6 *
7 * @package CiviCRM
8 *
9 * This file is part of CiviCRM
10 *
11 * CiviCRM is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Affero General Public License
13 * as published by the Free Software Foundation; either version 3 of
14 * the License, or (at your option) any later version.
15 *
16 * CiviCRM is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Affero General Public License for more details.
20 *
21 * You should have received a copy of the GNU Affero General Public
22 * License along with this program. If not, see
23 * <http://www.gnu.org/licenses/>.
24 */
25
26 require_once 'CiviTest/CiviUnitTestCase.php';
27
28
29 /**
30 * Test APIv3 civicrm_mailing_* functions
31 *
32 * @package CiviCRM
33 */
34 class api_v3_MailingTest extends CiviUnitTestCase {
35 protected $_groupID;
36 protected $_email;
37 protected $_apiversion = 3;
38 protected $_params = array();
39 protected $_entity = 'Mailing';
40 public $_eNoticeCompliant = TRUE;
41
42 function get_info() {
43 return array(
44 'name' => 'Mailer',
45 'description' => 'Test all Mailer methods.',
46 'group' => 'CiviCRM API Tests',
47 );
48 }
49
50 function setUp() {
51 parent::setUp();
52 $this->_groupID = $this->groupCreate(NULL);
53 $this->_email = 'test@test.test';
54 $this->_params = array(
55 'subject' => 'maild',
56 'body_text' => 'bdkfhdskfhduew',
57 'name' => 'mailing name',
58 'created_id' => 1,
59 );
60 }
61
62 function tearDown() {
63 $this->groupDelete($this->_groupID);
64 }
65
66 /**
67 * Test civicrm_mailing_create
68 */
69 public function testMailerCreateSuccess() {
70 $result = $this->callAPIAndDocument('mailing', 'create', $this->_params, __FUNCTION__, __FILE__);
71 $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id']));
72 $this->assertEquals(1, $jobs['count']);
73 unset($this->_params['created_id']);// return isn't working on this in getAndCheck so lets not check it for now
74 $this->getAndCheck($this->_params, $result['id'], 'mailing');
75 }
76
77 /**
78 * Test civicrm_mailing_create
79 */
80 public function testMailerDeleteSuccess() {
81 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
82 $jobs = $this->callAPIAndDocument($this->_entity, 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__);
83 $this->assertAPIDeleted($this->_entity, $result['id']);
84 }
85
86 //@ todo tests below here are all failure tests which are not hugely useful - need success tests
87
88 //------------ civicrm_mailing_event_bounce methods------------
89
90 /**
91 * Test civicrm_mailing_event_bounce with wrong params.
92 * Note that tests like this are slightly better than no test but an
93 * api function cannot be considered supported / 'part of the api' without a
94 * success test
95 */
96 public function testMailerBounceWrongParams() {
97 $params = array(
98 'job_id' => 'Wrong ID',
99 'event_queue_id' => 'Wrong ID',
100 'hash' => 'Wrong Hash',
101 'body' => 'Body...',
102 'time_stamp' => '20111109212100',
103 );
104 $result = $this->callAPIFailure('mailing_event', 'bounce', $params,
105 'Queue event could not be found');
106 }
107
108 //----------- civicrm_mailing_event_confirm methods -----------
109
110 /**
111 * Test civicrm_mailing_event_confirm with wrong params.
112 * Note that tests like this are slightly better than no test but an
113 * api function cannot be considered supported / 'part of the api' without a
114 * success test
115 */
116 public function testMailerConfirmWrongParams() {
117 $params = array(
118 'contact_id' => 'Wrong ID',
119 'subscribe_id' => 'Wrong ID',
120 'hash' => 'Wrong Hash',
121 'event_subscribe_id' => '123',
122 'time_stamp' => '20111111010101',
123 );
124 $result = $this->callAPIFailure('mailing_event', 'confirm', $params,
125 'Confirmation failed'
126 );
127 }
128
129 //---------- civicrm_mailing_event_reply methods -----------
130
131 /**
132 * Test civicrm_mailing_event_reply with wrong params.
133 *
134 * Note that tests like this are slightly better than no test but an
135 * api function cannot be considered supported / 'part of the api' without a
136 * success test
137 */
138 public function testMailerReplyWrongParams() {
139 $params = array(
140 'job_id' => 'Wrong ID',
141 'event_queue_id' => 'Wrong ID',
142 'hash' => 'Wrong Hash',
143 'bodyTxt' => 'Body...',
144 'replyTo' => $this->_email,
145 'time_stamp' => '20111111010101',
146 );
147 $result = $this->callAPIFailure('mailing_event', 'reply', $params,
148 'Queue event could not be found'
149 );
150 }
151
152
153 //----------- civicrm_mailing_event_forward methods ----------
154
155 /**
156 * Test civicrm_mailing_event_forward with wrong params.
157 * Note that tests like this are slightly better than no test but an
158 * api function cannot be considered supported / 'part of the api' without a
159 * success test
160 */
161 public function testMailerForwardWrongParams() {
162 $params = array(
163 'job_id' => 'Wrong ID',
164 'event_queue_id' => 'Wrong ID',
165 'hash' => 'Wrong Hash',
166 'email' => $this->_email,
167 'time_stamp' => '20111111010101',
168 );
169 $result = $this->callAPIFailure('mailing_event', 'forward', $params,
170 'Queue event could not be found'
171 );
172 }
173
174
175 //----------- civicrm_mailing_create ----------
176
177 }