Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
8891a36e | 2 | /* |
6a488035 TO |
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; | |
c43d01f3 | 37 | protected $_apiversion = 3; |
38 | protected $_params = array(); | |
e37b4b04 | 39 | protected $_entity = 'Mailing'; |
b7c9bc4c | 40 | |
430ae6dd | 41 | |
4cbe18b8 EM |
42 | /** |
43 | * @return array | |
44 | */ | |
430ae6dd | 45 | function get_info() { |
6a488035 TO |
46 | return array( |
47 | 'name' => 'Mailer', | |
48 | 'description' => 'Test all Mailer methods.', | |
49 | 'group' => 'CiviCRM API Tests', | |
50 | ); | |
51 | } | |
52 | ||
53 | function setUp() { | |
54 | parent::setUp(); | |
fadb804f | 55 | $this->_groupID = $this->groupCreate(); |
ef170fe0 | 56 | $this->_email = 'test@test.test'; |
c43d01f3 | 57 | $this->_params = array( |
58 | 'subject' => 'maild', | |
59 | 'body_text' => 'bdkfhdskfhduew', | |
60 | 'name' => 'mailing name', | |
61 | 'created_id' => 1, | |
62 | ); | |
6a488035 TO |
63 | } |
64 | ||
65 | function tearDown() { | |
66 | $this->groupDelete($this->_groupID); | |
67 | } | |
68 | ||
69 | /** | |
70 | * Test civicrm_mailing_create | |
71 | */ | |
72 | public function testMailerCreateSuccess() { | |
c43d01f3 | 73 | $result = $this->callAPIAndDocument('mailing', 'create', $this->_params, __FUNCTION__, __FILE__); |
74 | $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id'])); | |
6a488035 | 75 | $this->assertEquals(1, $jobs['count']); |
ef170fe0 | 76 | unset($this->_params['created_id']); // return isn't working on this in getAndCheck so lets not check it for now |
e37b4b04 | 77 | $this->getAndCheck($this->_params, $result['id'], 'mailing'); |
6a488035 TO |
78 | } |
79 | ||
c43d01f3 | 80 | /** |
30d44db2 | 81 | * Test civicrm_mailing_delete |
c43d01f3 | 82 | */ |
83 | public function testMailerDeleteSuccess() { | |
e37b4b04 | 84 | $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); |
85 | $jobs = $this->callAPIAndDocument($this->_entity, 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__); | |
86 | $this->assertAPIDeleted($this->_entity, $result['id']); | |
c43d01f3 | 87 | } |
6a488035 TO |
88 | |
89 | //@ todo tests below here are all failure tests which are not hugely useful - need success tests | |
90 | ||
91 | //------------ civicrm_mailing_event_bounce methods------------ | |
92 | ||
93 | /** | |
94 | * Test civicrm_mailing_event_bounce with wrong params. | |
e37b4b04 | 95 | * Note that tests like this are slightly better than no test but an |
96 | * api function cannot be considered supported / 'part of the api' without a | |
97 | * success test | |
6a488035 TO |
98 | */ |
99 | public function testMailerBounceWrongParams() { | |
100 | $params = array( | |
101 | 'job_id' => 'Wrong ID', | |
102 | 'event_queue_id' => 'Wrong ID', | |
103 | 'hash' => 'Wrong Hash', | |
104 | 'body' => 'Body...', | |
6a488035 TO |
105 | 'time_stamp' => '20111109212100', |
106 | ); | |
e37b4b04 | 107 | $result = $this->callAPIFailure('mailing_event', 'bounce', $params, |
30d44db2 | 108 | 'Queue event could not be found' |
109 | ); | |
6a488035 TO |
110 | } |
111 | ||
112 | //----------- civicrm_mailing_event_confirm methods ----------- | |
113 | ||
114 | /** | |
115 | * Test civicrm_mailing_event_confirm with wrong params. | |
e37b4b04 | 116 | * Note that tests like this are slightly better than no test but an |
117 | * api function cannot be considered supported / 'part of the api' without a | |
118 | * success test | |
6a488035 TO |
119 | */ |
120 | public function testMailerConfirmWrongParams() { | |
121 | $params = array( | |
122 | 'contact_id' => 'Wrong ID', | |
123 | 'subscribe_id' => 'Wrong ID', | |
124 | 'hash' => 'Wrong Hash', | |
125 | 'event_subscribe_id' => '123', | |
126 | 'time_stamp' => '20111111010101', | |
ef170fe0 | 127 | ); |
e37b4b04 | 128 | $result = $this->callAPIFailure('mailing_event', 'confirm', $params, |
129 | 'Confirmation failed' | |
130 | ); | |
6a488035 TO |
131 | } |
132 | ||
133 | //---------- civicrm_mailing_event_reply methods ----------- | |
134 | ||
135 | /** | |
136 | * Test civicrm_mailing_event_reply with wrong params. | |
e37b4b04 | 137 | * |
138 | * Note that tests like this are slightly better than no test but an | |
139 | * api function cannot be considered supported / 'part of the api' without a | |
140 | * success test | |
6a488035 TO |
141 | */ |
142 | public function testMailerReplyWrongParams() { | |
143 | $params = array( | |
144 | 'job_id' => 'Wrong ID', | |
145 | 'event_queue_id' => 'Wrong ID', | |
146 | 'hash' => 'Wrong Hash', | |
147 | 'bodyTxt' => 'Body...', | |
148 | 'replyTo' => $this->_email, | |
149 | 'time_stamp' => '20111111010101', | |
ef170fe0 | 150 | ); |
e37b4b04 | 151 | $result = $this->callAPIFailure('mailing_event', 'reply', $params, |
152 | 'Queue event could not be found' | |
30d44db2 | 153 | ); |
6a488035 TO |
154 | } |
155 | ||
156 | ||
157 | //----------- civicrm_mailing_event_forward methods ---------- | |
158 | ||
159 | /** | |
160 | * Test civicrm_mailing_event_forward with wrong params. | |
e37b4b04 | 161 | * Note that tests like this are slightly better than no test but an |
162 | * api function cannot be considered supported / 'part of the api' without a | |
163 | * success test | |
6a488035 TO |
164 | */ |
165 | public function testMailerForwardWrongParams() { | |
166 | $params = array( | |
167 | 'job_id' => 'Wrong ID', | |
168 | 'event_queue_id' => 'Wrong ID', | |
169 | 'hash' => 'Wrong Hash', | |
170 | 'email' => $this->_email, | |
171 | 'time_stamp' => '20111111010101', | |
ef170fe0 | 172 | ); |
e37b4b04 | 173 | $result = $this->callAPIFailure('mailing_event', 'forward', $params, |
174 | 'Queue event could not be found' | |
175 | ); | |
6a488035 TO |
176 | } |
177 | ||
6a488035 TO |
178 | //----------- civicrm_mailing_create ---------- |
179 | ||
180 | } |