Merge pull request #12024 from yashodha/price_custom_search
[civicrm-core.git] / tests / phpunit / api / v3 / MailingGroupTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 /**
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',
54 'contact_id' => '2121',
55 'time_stamp' => '20111111010101',
56 'hash' => 'sasa',
57 );
58 $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
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,
69 'contact_type' => 'Individual',
70 );
71 $contactID = $this->individualCreate($params);
72
73 $params = array(
74 'email' => $this->_email,
75 'group_id' => $this->_groupID,
76 'contact_id' => $contactID,
77 'hash' => 'b15de8b64e2cec34',
78 'time_stamp' => '20101212121212',
79 );
80 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__);
81 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
82
83 $this->contactDelete($contactID);
84 }
85
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',
93 'hash' => 'Wrong Hash',
94 'time_stamp' => '20101212121212',
95 );
96
97 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
98 }
99
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',
108 'org_unsubscribe' => 1,
109 'time_stamp' => '20101212121212',
110 );
111
112 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
113 }
114
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',
127 'org_unsubscribe' => 'test',
128 'time_stamp' => '20101212121212',
129 );
130 $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
131 }
132
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,
141 'contact_type' => 'Individual',
142 );
143 $contactID = $this->individualCreate($params);
144
145 $params = array(
146 'email' => $this->_email,
147 'group_id' => $this->_groupID,
148 'contact_id' => $contactID,
149 'hash' => 'b15de8b64e2cec34',
150 'time_stamp' => '20101212121212',
151 );
152 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
153
154 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
155
156 $params = array(
157 'contact_id' => $result['values'][$result['id']]['contact_id'],
158 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
159 'hash' => $result['values'][$result['id']]['hash'],
160 'time_stamp' => '20101212121212',
161 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
162 );
163
164 $this->callAPISuccess('mailing_event_confirm', 'create', $params);
165 $this->contactDelete($contactID);
166 }
167
168 }