tests/ - Remove get_info()
[civicrm-core.git] / tests / phpunit / api / v3 / MailingGroupTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26 */
27
28 require_once 'CiviTest/CiviUnitTestCase.php';
29
30 /**
31 * Test APIv3 civicrm_mailing_group_* functions
32 *
33 * @package CiviCRM
34 */
35 class api_v3_MailingGroupTest extends CiviUnitTestCase {
36 protected $_groupID;
37 protected $_email;
38 protected $_apiversion;
39
40 function setUp() {
41 parent::setUp();
42 $this->_apiversion = 3;
43 $this->_groupID = $this->groupCreate();
44 $this->_email = 'test@test.test';
45 }
46
47 function tearDown() {
48 $this->groupDelete($this->_groupID);
49 }
50
51 //---------- civicrm_mailing_event_subscribe methods ---------
52
53 /**
54 * Test civicrm_mailing_group_event_subscribe with wrong params.
55 */
56 public function testMailerGroupSubscribeWrongParams() {
57 $params = array(
58 'email' => $this->_email,
59 'group_id' => 'Wrong Group ID',
60 'contact_id' => '2121',
61 'time_stamp' => '20111111010101',
62 'hash' => 'sasa',
63 );
64 $result = $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
65 if ($result['error_message'] != 'Subscription failed') {
66 $this->assertEquals($result['error_message'], 'Invalid Group id', 'In line ' . __LINE__);
67 }
68 else {
69 $this->assertEquals($result['error_message'], 'Subscription failed', 'In line ' . __LINE__);
70 }
71 }
72
73 /**
74 * Test civicrm_mailing_group_event_subscribe with given contact ID.
75 */
76 public function testMailerGroupSubscribeGivenContactId() {
77 $params = array(
78 'first_name' => 'Test',
79 'last_name' => 'Test',
80 'email' => $this->_email,
81 'contact_type' => 'Individual',
82 );
83 $contactID = $this->individualCreate($params);
84
85 $params = array(
86 'email' => $this->_email,
87 'group_id' => $this->_groupID,
88 'contact_id' => $contactID,
89 'hash' => 'b15de8b64e2cec34',
90 'time_stamp' => '20101212121212',
91 );
92 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__);
93 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
94
95 $this->contactDelete($contactID);
96 }
97
98 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
99
100 /**
101 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
102 */
103 public function testMailerGroupUnsubscribeWrongParams() {
104 $params = array(
105 'job_id' => 'Wrong ID',
106 'event_queue_id' => 'Wrong ID',
107 'hash' => 'Wrong Hash',
108 'time_stamp' => '20101212121212',
109 );
110
111 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
112 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__);
113 }
114
115 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
116
117 /**
118 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
119 */
120 public function testMailerGroupDomainUnsubscribeWrongParams() {
121 $params = array(
122 'job_id' => 'Wrong ID',
123 'event_queue_id' => 'Wrong ID',
124 'hash' => 'Wrong Hash',
125 'org_unsubscribe' => 1,
126 'time_stamp' => '20101212121212',
127 );
128
129 $result = $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
130 $this->assertEquals($result['error_message'], 'Domain Queue event could not be found', 'In line ' . __LINE__);
131 }
132
133 //----------- civicrm_mailing_group_event_resubscribe methods--------
134
135 /**
136 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
137 */
138
139 /**
140 * Test civicrm_mailing_group_event_resubscribe with wrong params.
141 */
142 public function testMailerGroupResubscribeWrongParams() {
143 $params = array(
144 'job_id' => 'Wrong ID',
145 'event_queue_id' => 'Wrong ID',
146 'hash' => 'Wrong Hash',
147 'org_unsubscribe' => 'test',
148 'time_stamp' => '20101212121212',
149 );
150 $result = $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
151 $this->assertEquals($result['error_message'], 'Queue event could not be found', 'In line ' . __LINE__);
152 }
153
154 //------------------------ success case ---------------------
155
156 /**
157 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
158 */
159 public function testMailerProcess() {
160 $params = array(
161 'first_name' => 'Test',
162 'last_name' => 'Test',
163 'email' => $this->_email,
164 'contact_type' => 'Individual',
165 );
166 $contactID = $this->individualCreate($params);
167
168 $params = array(
169 'email' => $this->_email,
170 'group_id' => $this->_groupID,
171 'contact_id' => $contactID,
172 'hash' => 'b15de8b64e2cec34',
173 'time_stamp' => '20101212121212',
174 );
175 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
176
177 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
178
179 $params = array(
180 'contact_id' => $result['values'][$result['id']]['contact_id'],
181 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
182 'hash' => $result['values'][$result['id']]['hash'],
183 'time_stamp' => '20101212121212',
184 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
185 );
186
187 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
188 $this->contactDelete($contactID);
189 }
190 }
191