Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
b6708aeb | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
b6708aeb | 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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 26 | */ |
6a488035 | 27 | |
6a488035 TO |
28 | /** |
29 | * Test APIv3 civicrm_mailing_group_* functions | |
30 | * | |
6c6e6187 | 31 | * @package CiviCRM |
acb109b7 | 32 | * @group headless |
6a488035 TO |
33 | */ |
34 | class api_v3_MailingGroupTest extends CiviUnitTestCase { | |
35 | protected $_groupID; | |
36 | protected $_email; | |
430ae6dd | 37 | protected $_apiversion; |
b7c9bc4c | 38 | |
00be9182 | 39 | public function setUp() { |
6a488035 | 40 | parent::setUp(); |
55941eb0 | 41 | $this->useTransaction(TRUE); |
6a488035 | 42 | $this->_apiversion = 3; |
fadb804f | 43 | $this->_groupID = $this->groupCreate(); |
ef170fe0 | 44 | $this->_email = 'test@test.test'; |
6a488035 TO |
45 | } |
46 | ||
6a488035 TO |
47 | //---------- civicrm_mailing_event_subscribe methods --------- |
48 | ||
49 | /** | |
50 | * Test civicrm_mailing_group_event_subscribe with wrong params. | |
51 | */ | |
52 | public function testMailerGroupSubscribeWrongParams() { | |
53 | $params = array( | |
54 | 'email' => $this->_email, | |
55 | 'group_id' => 'Wrong Group ID', | |
ef170fe0 | 56 | 'contact_id' => '2121', |
57 | 'time_stamp' => '20111111010101', | |
6a488035 TO |
58 | 'hash' => 'sasa', |
59 | ); | |
7bd9cc5f | 60 | $this->callAPIFailure('mailing_event_subscribe', 'create', $params); |
6a488035 TO |
61 | } |
62 | ||
63 | /** | |
64 | * Test civicrm_mailing_group_event_subscribe with given contact ID. | |
65 | */ | |
66 | public function testMailerGroupSubscribeGivenContactId() { | |
67 | $params = array( | |
68 | 'first_name' => 'Test', | |
69 | 'last_name' => 'Test', | |
70 | 'email' => $this->_email, | |
ef170fe0 | 71 | 'contact_type' => 'Individual', |
72 | ); | |
6a488035 TO |
73 | $contactID = $this->individualCreate($params); |
74 | ||
75 | $params = array( | |
76 | 'email' => $this->_email, | |
77 | 'group_id' => $this->_groupID, | |
9f1b81e0 | 78 | 'contact_id' => $contactID, |
79 | 'hash' => 'b15de8b64e2cec34', | |
6a488035 TO |
80 | 'time_stamp' => '20101212121212', |
81 | ); | |
7f0eb6cb | 82 | $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__); |
9e23eadb | 83 | $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID); |
6a488035 TO |
84 | |
85 | $this->contactDelete($contactID); | |
86 | } | |
87 | ||
88 | //-------- civicrm_mailing_group_event_unsubscribe methods----------- | |
89 | ||
90 | /** | |
91 | * Test civicrm_mailing_group_event_unsubscribe with wrong params. | |
92 | */ | |
93 | public function testMailerGroupUnsubscribeWrongParams() { | |
94 | $params = array( | |
95 | 'job_id' => 'Wrong ID', | |
96 | 'event_queue_id' => 'Wrong ID', | |
ef170fe0 | 97 | 'hash' => 'Wrong Hash', |
98 | 'time_stamp' => '20101212121212', | |
6a488035 TO |
99 | ); |
100 | ||
7bd9cc5f | 101 | $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params); |
6a488035 TO |
102 | } |
103 | ||
104 | //--------- civicrm_mailing_group_event_domain_unsubscribe methods ------- | |
105 | ||
106 | /** | |
107 | * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params. | |
108 | */ | |
109 | public function testMailerGroupDomainUnsubscribeWrongParams() { | |
110 | $params = array( | |
111 | 'job_id' => 'Wrong ID', | |
112 | 'event_queue_id' => 'Wrong ID', | |
113 | 'hash' => 'Wrong Hash', | |
ef170fe0 | 114 | 'org_unsubscribe' => 1, |
115 | 'time_stamp' => '20101212121212', | |
6a488035 TO |
116 | ); |
117 | ||
7bd9cc5f | 118 | $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params); |
6a488035 TO |
119 | } |
120 | ||
6a488035 TO |
121 | //----------- civicrm_mailing_group_event_resubscribe methods-------- |
122 | ||
123 | /** | |
124 | * Test civicrm_mailing_group_event_resubscribe with wrong params type. | |
125 | */ | |
126 | ||
127 | /** | |
128 | * Test civicrm_mailing_group_event_resubscribe with wrong params. | |
129 | */ | |
130 | public function testMailerGroupResubscribeWrongParams() { | |
131 | $params = array( | |
132 | 'job_id' => 'Wrong ID', | |
133 | 'event_queue_id' => 'Wrong ID', | |
134 | 'hash' => 'Wrong Hash', | |
ef170fe0 | 135 | 'org_unsubscribe' => 'test', |
136 | 'time_stamp' => '20101212121212', | |
6a488035 | 137 | ); |
7bd9cc5f | 138 | $this->callAPIFailure('mailing_event_resubscribe', 'create', $params); |
6a488035 TO |
139 | } |
140 | ||
141 | //------------------------ success case --------------------- | |
142 | ||
143 | /** | |
144 | * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected. | |
145 | */ | |
146 | public function testMailerProcess() { | |
147 | $params = array( | |
148 | 'first_name' => 'Test', | |
149 | 'last_name' => 'Test', | |
150 | 'email' => $this->_email, | |
ef170fe0 | 151 | 'contact_type' => 'Individual', |
152 | ); | |
6a488035 TO |
153 | $contactID = $this->individualCreate($params); |
154 | ||
155 | $params = array( | |
156 | 'email' => $this->_email, | |
157 | 'group_id' => $this->_groupID, | |
ef170fe0 | 158 | 'contact_id' => $contactID, |
159 | 'hash' => 'b15de8b64e2cec34', | |
6a488035 TO |
160 | 'time_stamp' => '20101212121212', |
161 | ); | |
7f0eb6cb | 162 | $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params); |
6a488035 | 163 | |
9e23eadb | 164 | $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID); |
6a488035 TO |
165 | |
166 | $params = array( | |
9e23eadb | 167 | 'contact_id' => $result['values'][$result['id']]['contact_id'], |
168 | 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'], | |
ef170fe0 | 169 | 'hash' => $result['values'][$result['id']]['hash'], |
170 | 'time_stamp' => '20101212121212', | |
9e23eadb | 171 | 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'], |
6a488035 TO |
172 | ); |
173 | ||
7f0eb6cb | 174 | $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params); |
6a488035 TO |
175 | $this->contactDelete($contactID); |
176 | } | |
96025800 | 177 | |
6a488035 | 178 | } |