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