Merge pull request #11965 from colemanw/CRM-21855
[civicrm-core.git] / tests / phpunit / api / v3 / MailingGroupTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2/*
3 +--------------------------------------------------------------------+
81621fee 4| CiviCRM version 4.7 |
b6708aeb 5+--------------------------------------------------------------------+
8c9251b3 6| Copyright CiviCRM LLC (c) 2004-2018 |
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 */
34class 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 /**
48 * Test civicrm_mailing_group_event_subscribe with wrong params.
49 */
50 public function testMailerGroupSubscribeWrongParams() {
51 $params = array(
52 'email' => $this->_email,
53 'group_id' => 'Wrong Group ID',
ef170fe0 54 'contact_id' => '2121',
55 'time_stamp' => '20111111010101',
6a488035
TO
56 'hash' => 'sasa',
57 );
7bd9cc5f 58 $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
6a488035
TO
59 }
60
61 /**
62 * Test civicrm_mailing_group_event_subscribe with given contact ID.
63 */
64 public function testMailerGroupSubscribeGivenContactId() {
65 $params = array(
66 'first_name' => 'Test',
67 'last_name' => 'Test',
68 'email' => $this->_email,
ef170fe0 69 'contact_type' => 'Individual',
70 );
6a488035
TO
71 $contactID = $this->individualCreate($params);
72
73 $params = array(
74 'email' => $this->_email,
75 'group_id' => $this->_groupID,
9f1b81e0 76 'contact_id' => $contactID,
77 'hash' => 'b15de8b64e2cec34',
6a488035
TO
78 'time_stamp' => '20101212121212',
79 );
7f0eb6cb 80 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__);
9e23eadb 81 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
6a488035
TO
82
83 $this->contactDelete($contactID);
84 }
85
6a488035
TO
86 /**
87 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
88 */
89 public function testMailerGroupUnsubscribeWrongParams() {
90 $params = array(
91 'job_id' => 'Wrong ID',
92 'event_queue_id' => 'Wrong ID',
ef170fe0 93 'hash' => 'Wrong Hash',
94 'time_stamp' => '20101212121212',
6a488035
TO
95 );
96
7bd9cc5f 97 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
6a488035
TO
98 }
99
6a488035
TO
100 /**
101 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
102 */
103 public function testMailerGroupDomainUnsubscribeWrongParams() {
104 $params = array(
105 'job_id' => 'Wrong ID',
106 'event_queue_id' => 'Wrong ID',
107 'hash' => 'Wrong Hash',
ef170fe0 108 'org_unsubscribe' => 1,
109 'time_stamp' => '20101212121212',
6a488035
TO
110 );
111
7bd9cc5f 112 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
6a488035
TO
113 }
114
6a488035
TO
115 /**
116 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
117 */
118
119 /**
120 * Test civicrm_mailing_group_event_resubscribe with wrong params.
121 */
122 public function testMailerGroupResubscribeWrongParams() {
123 $params = array(
124 'job_id' => 'Wrong ID',
125 'event_queue_id' => 'Wrong ID',
126 'hash' => 'Wrong Hash',
ef170fe0 127 'org_unsubscribe' => 'test',
128 'time_stamp' => '20101212121212',
6a488035 129 );
7bd9cc5f 130 $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
6a488035
TO
131 }
132
6a488035
TO
133 /**
134 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
135 */
136 public function testMailerProcess() {
137 $params = array(
138 'first_name' => 'Test',
139 'last_name' => 'Test',
140 'email' => $this->_email,
ef170fe0 141 'contact_type' => 'Individual',
142 );
6a488035
TO
143 $contactID = $this->individualCreate($params);
144
145 $params = array(
146 'email' => $this->_email,
147 'group_id' => $this->_groupID,
ef170fe0 148 'contact_id' => $contactID,
149 'hash' => 'b15de8b64e2cec34',
6a488035
TO
150 'time_stamp' => '20101212121212',
151 );
7f0eb6cb 152 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
6a488035 153
9e23eadb 154 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
6a488035
TO
155
156 $params = array(
9e23eadb 157 'contact_id' => $result['values'][$result['id']]['contact_id'],
158 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
ef170fe0 159 'hash' => $result['values'][$result['id']]['hash'],
160 'time_stamp' => '20101212121212',
9e23eadb 161 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
6a488035
TO
162 );
163
6f616e5c 164 $this->callAPISuccess('mailing_event_confirm', 'create', $params);
6a488035
TO
165 $this->contactDelete($contactID);
166 }
96025800 167
6a488035 168}