tests/phpunit/** - Remove unnecessary "require_once" statements
[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-2015 |
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 */
33 class api_v3_MailingGroupTest extends CiviUnitTestCase {
34 protected $_groupID;
35 protected $_email;
36 protected $_apiversion;
37
38 public function setUp() {
39 parent::setUp();
40 $this->useTransaction(TRUE);
41 $this->_apiversion = 3;
42 $this->_groupID = $this->groupCreate();
43 $this->_email = 'test@test.test';
44 }
45
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',
55 'contact_id' => '2121',
56 'time_stamp' => '20111111010101',
57 'hash' => 'sasa',
58 );
59 $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
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,
70 'contact_type' => 'Individual',
71 );
72 $contactID = $this->individualCreate($params);
73
74 $params = array(
75 'email' => $this->_email,
76 'group_id' => $this->_groupID,
77 'contact_id' => $contactID,
78 'hash' => 'b15de8b64e2cec34',
79 'time_stamp' => '20101212121212',
80 );
81 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__);
82 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
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',
96 'hash' => 'Wrong Hash',
97 'time_stamp' => '20101212121212',
98 );
99
100 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
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',
113 'org_unsubscribe' => 1,
114 'time_stamp' => '20101212121212',
115 );
116
117 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
118 }
119
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',
134 'org_unsubscribe' => 'test',
135 'time_stamp' => '20101212121212',
136 );
137 $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
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,
150 'contact_type' => 'Individual',
151 );
152 $contactID = $this->individualCreate($params);
153
154 $params = array(
155 'email' => $this->_email,
156 'group_id' => $this->_groupID,
157 'contact_id' => $contactID,
158 'hash' => 'b15de8b64e2cec34',
159 'time_stamp' => '20101212121212',
160 );
161 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
162
163 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
164
165 $params = array(
166 'contact_id' => $result['values'][$result['id']]['contact_id'],
167 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
168 'hash' => $result['values'][$result['id']]['hash'],
169 'time_stamp' => '20101212121212',
170 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
171 );
172
173 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
174 $this->contactDelete($contactID);
175 }
176
177 }