Test fix
[civicrm-core.git] / tests / phpunit / api / v3 / MailingGroupTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 /**
29 * Test APIv3 civicrm_mailing_group_* functions
30 *
31 * @package CiviCRM
32 * @group headless
33 */
34 class api_v3_MailingGroupTest extends CiviUnitTestCase {
35 protected $_groupID;
36 protected $_email;
37 protected $_apiversion;
38
39 public function setUp() {
40 parent::setUp();
41 $this->useTransaction(TRUE);
42 $this->_apiversion = 3;
43 $this->_groupID = $this->groupCreate();
44 $this->_email = 'test@test.test';
45 }
46
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',
56 'contact_id' => '2121',
57 'time_stamp' => '20111111010101',
58 'hash' => 'sasa',
59 );
60 $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
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,
71 'contact_type' => 'Individual',
72 );
73 $contactID = $this->individualCreate($params);
74
75 $params = array(
76 'email' => $this->_email,
77 'group_id' => $this->_groupID,
78 'contact_id' => $contactID,
79 'hash' => 'b15de8b64e2cec34',
80 'time_stamp' => '20101212121212',
81 );
82 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__);
83 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
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',
97 'hash' => 'Wrong Hash',
98 'time_stamp' => '20101212121212',
99 );
100
101 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
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',
114 'org_unsubscribe' => 1,
115 'time_stamp' => '20101212121212',
116 );
117
118 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
119 }
120
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',
135 'org_unsubscribe' => 'test',
136 'time_stamp' => '20101212121212',
137 );
138 $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
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,
151 'contact_type' => 'Individual',
152 );
153 $contactID = $this->individualCreate($params);
154
155 $params = array(
156 'email' => $this->_email,
157 'group_id' => $this->_groupID,
158 'contact_id' => $contactID,
159 'hash' => 'b15de8b64e2cec34',
160 'time_stamp' => '20101212121212',
161 );
162 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
163
164 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
165
166 $params = array(
167 'contact_id' => $result['values'][$result['id']]['contact_id'],
168 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
169 'hash' => $result['values'][$result['id']]['hash'],
170 'time_stamp' => '20101212121212',
171 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
172 );
173
174 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
175 $this->contactDelete($contactID);
176 }
177
178 }