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'; |
8891a36e | 40 | public $_eNoticeCompliant = TRUE; |
430ae6dd TO |
41 | |
42 | function get_info() { | |
6a488035 TO |
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(); | |
ef170fe0 | 52 | $this->_groupID = $this->groupCreate(NULL); |
53 | $this->_email = 'test@test.test'; | |
c43d01f3 | 54 | $this->_params = array( |
55 | 'subject' => 'maild', | |
56 | 'body_text' => 'bdkfhdskfhduew', | |
57 | 'name' => 'mailing name', | |
58 | 'created_id' => 1, | |
59 | ); | |
6a488035 TO |
60 | } |
61 | ||
62 | function tearDown() { | |
63 | $this->groupDelete($this->_groupID); | |
64 | } | |
65 | ||
66 | /** | |
67 | * Test civicrm_mailing_create | |
68 | */ | |
69 | public function testMailerCreateSuccess() { | |
c43d01f3 | 70 | $result = $this->callAPIAndDocument('mailing', 'create', $this->_params, __FUNCTION__, __FILE__); |
71 | $jobs = $this->callAPISuccess('mailing_job', 'get', array('mailing_id' => $result['id'])); | |
6a488035 | 72 | $this->assertEquals(1, $jobs['count']); |
ef170fe0 | 73 | unset($this->_params['created_id']); // return isn't working on this in getAndCheck so lets not check it for now |
e37b4b04 | 74 | $this->getAndCheck($this->_params, $result['id'], 'mailing'); |
6a488035 TO |
75 | } |
76 | ||
c43d01f3 | 77 | /** |
30d44db2 | 78 | * Test civicrm_mailing_delete |
c43d01f3 | 79 | */ |
80 | public function testMailerDeleteSuccess() { | |
e37b4b04 | 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']); | |
c43d01f3 | 84 | } |
6a488035 TO |
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. | |
e37b4b04 | 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 | |
6a488035 TO |
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...', | |
6a488035 TO |
102 | 'time_stamp' => '20111109212100', |
103 | ); | |
e37b4b04 | 104 | $result = $this->callAPIFailure('mailing_event', 'bounce', $params, |
30d44db2 | 105 | 'Queue event could not be found' |
106 | ); | |
6a488035 TO |
107 | } |
108 | ||
109 | //----------- civicrm_mailing_event_confirm methods ----------- | |
110 | ||
111 | /** | |
112 | * Test civicrm_mailing_event_confirm with wrong params. | |
e37b4b04 | 113 | * Note that tests like this are slightly better than no test but an |
114 | * api function cannot be considered supported / 'part of the api' without a | |
115 | * success test | |
6a488035 TO |
116 | */ |
117 | public function testMailerConfirmWrongParams() { | |
118 | $params = array( | |
119 | 'contact_id' => 'Wrong ID', | |
120 | 'subscribe_id' => 'Wrong ID', | |
121 | 'hash' => 'Wrong Hash', | |
122 | 'event_subscribe_id' => '123', | |
123 | 'time_stamp' => '20111111010101', | |
ef170fe0 | 124 | ); |
e37b4b04 | 125 | $result = $this->callAPIFailure('mailing_event', 'confirm', $params, |
126 | 'Confirmation failed' | |
127 | ); | |
6a488035 TO |
128 | } |
129 | ||
130 | //---------- civicrm_mailing_event_reply methods ----------- | |
131 | ||
132 | /** | |
133 | * Test civicrm_mailing_event_reply with wrong params. | |
e37b4b04 | 134 | * |
135 | * Note that tests like this are slightly better than no test but an | |
136 | * api function cannot be considered supported / 'part of the api' without a | |
137 | * success test | |
6a488035 TO |
138 | */ |
139 | public function testMailerReplyWrongParams() { | |
140 | $params = array( | |
141 | 'job_id' => 'Wrong ID', | |
142 | 'event_queue_id' => 'Wrong ID', | |
143 | 'hash' => 'Wrong Hash', | |
144 | 'bodyTxt' => 'Body...', | |
145 | 'replyTo' => $this->_email, | |
146 | 'time_stamp' => '20111111010101', | |
ef170fe0 | 147 | ); |
e37b4b04 | 148 | $result = $this->callAPIFailure('mailing_event', 'reply', $params, |
149 | 'Queue event could not be found' | |
30d44db2 | 150 | ); |
6a488035 TO |
151 | } |
152 | ||
153 | ||
154 | //----------- civicrm_mailing_event_forward methods ---------- | |
155 | ||
156 | /** | |
157 | * Test civicrm_mailing_event_forward with wrong params. | |
e37b4b04 | 158 | * Note that tests like this are slightly better than no test but an |
159 | * api function cannot be considered supported / 'part of the api' without a | |
160 | * success test | |
6a488035 TO |
161 | */ |
162 | public function testMailerForwardWrongParams() { | |
163 | $params = array( | |
164 | 'job_id' => 'Wrong ID', | |
165 | 'event_queue_id' => 'Wrong ID', | |
166 | 'hash' => 'Wrong Hash', | |
167 | 'email' => $this->_email, | |
168 | 'time_stamp' => '20111111010101', | |
ef170fe0 | 169 | ); |
e37b4b04 | 170 | $result = $this->callAPIFailure('mailing_event', 'forward', $params, |
171 | 'Queue event could not be found' | |
172 | ); | |
6a488035 TO |
173 | } |
174 | ||
6a488035 TO |
175 | //----------- civicrm_mailing_create ---------- |
176 | ||
177 | } |