commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / tests / phpunit / api / v3 / MailingGroupTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 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 public function setUp() {
41 parent::setUp();
42 $this->useTransaction(TRUE);
43 $this->_apiversion = 3;
44 $this->_groupID = $this->groupCreate();
45 $this->_email = 'test@test.test';
46 }
47
48 //---------- civicrm_mailing_event_subscribe methods ---------
49
50 /**
51 * Test civicrm_mailing_group_event_subscribe with wrong params.
52 */
53 public function testMailerGroupSubscribeWrongParams() {
54 $params = array(
55 'email' => $this->_email,
56 'group_id' => 'Wrong Group ID',
57 'contact_id' => '2121',
58 'time_stamp' => '20111111010101',
59 'hash' => 'sasa',
60 );
61 $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
62 }
63
64 /**
65 * Test civicrm_mailing_group_event_subscribe with given contact ID.
66 */
67 public function testMailerGroupSubscribeGivenContactId() {
68 $params = array(
69 'first_name' => 'Test',
70 'last_name' => 'Test',
71 'email' => $this->_email,
72 'contact_type' => 'Individual',
73 );
74 $contactID = $this->individualCreate($params);
75
76 $params = array(
77 'email' => $this->_email,
78 'group_id' => $this->_groupID,
79 'contact_id' => $contactID,
80 'hash' => 'b15de8b64e2cec34',
81 'time_stamp' => '20101212121212',
82 );
83 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__);
84 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
85
86 $this->contactDelete($contactID);
87 }
88
89 //-------- civicrm_mailing_group_event_unsubscribe methods-----------
90
91 /**
92 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
93 */
94 public function testMailerGroupUnsubscribeWrongParams() {
95 $params = array(
96 'job_id' => 'Wrong ID',
97 'event_queue_id' => 'Wrong ID',
98 'hash' => 'Wrong Hash',
99 'time_stamp' => '20101212121212',
100 );
101
102 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
103 }
104
105 //--------- civicrm_mailing_group_event_domain_unsubscribe methods -------
106
107 /**
108 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
109 */
110 public function testMailerGroupDomainUnsubscribeWrongParams() {
111 $params = array(
112 'job_id' => 'Wrong ID',
113 'event_queue_id' => 'Wrong ID',
114 'hash' => 'Wrong Hash',
115 'org_unsubscribe' => 1,
116 'time_stamp' => '20101212121212',
117 );
118
119 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
120 }
121
122 //----------- civicrm_mailing_group_event_resubscribe methods--------
123
124 /**
125 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
126 */
127
128 /**
129 * Test civicrm_mailing_group_event_resubscribe with wrong params.
130 */
131 public function testMailerGroupResubscribeWrongParams() {
132 $params = array(
133 'job_id' => 'Wrong ID',
134 'event_queue_id' => 'Wrong ID',
135 'hash' => 'Wrong Hash',
136 'org_unsubscribe' => 'test',
137 'time_stamp' => '20101212121212',
138 );
139 $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
140 }
141
142 //------------------------ success case ---------------------
143
144 /**
145 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
146 */
147 public function testMailerProcess() {
148 $params = array(
149 'first_name' => 'Test',
150 'last_name' => 'Test',
151 'email' => $this->_email,
152 'contact_type' => 'Individual',
153 );
154 $contactID = $this->individualCreate($params);
155
156 $params = array(
157 'email' => $this->_email,
158 'group_id' => $this->_groupID,
159 'contact_id' => $contactID,
160 'hash' => 'b15de8b64e2cec34',
161 'time_stamp' => '20101212121212',
162 );
163 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
164
165 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
166
167 $params = array(
168 'contact_id' => $result['values'][$result['id']]['contact_id'],
169 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
170 'hash' => $result['values'][$result['id']]['hash'],
171 'time_stamp' => '20101212121212',
172 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
173 );
174
175 $result = $this->callAPISuccess('mailing_event_confirm', 'create', $params);
176 $this->contactDelete($contactID);
177 }
178
179 }