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