Merge pull request #15840 from yashodha/participant_edit
[civicrm-core.git] / tests / phpunit / api / v3 / MailingGroupTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Test APIv3 civicrm_mailing_group_* functions
14 *
15 * @package CiviCRM
16 * @group headless
17 */
18 class api_v3_MailingGroupTest extends CiviUnitTestCase {
19 protected $_groupID;
20 protected $_email;
21 protected $_apiversion;
22
23 public function setUp() {
24 parent::setUp();
25 $this->useTransaction(TRUE);
26 $this->_apiversion = 3;
27 $this->_groupID = $this->groupCreate();
28 $this->_email = 'test@test.test';
29 }
30
31 /**
32 * Test civicrm_mailing_group_event_subscribe with wrong params.
33 */
34 public function testMailerGroupSubscribeWrongParams() {
35 $params = [
36 'email' => $this->_email,
37 'group_id' => 'Wrong Group ID',
38 'contact_id' => '2121',
39 'time_stamp' => '20111111010101',
40 'hash' => 'sasa',
41 ];
42 $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
43 }
44
45 /**
46 * Test civicrm_mailing_group_event_subscribe with given contact ID.
47 */
48 public function testMailerGroupSubscribeGivenContactId() {
49 $params = [
50 'first_name' => 'Test',
51 'last_name' => 'Test',
52 'email' => $this->_email,
53 'contact_type' => 'Individual',
54 ];
55 $contactID = $this->individualCreate($params);
56
57 $params = [
58 'email' => $this->_email,
59 'group_id' => $this->_groupID,
60 'contact_id' => $contactID,
61 'hash' => 'b15de8b64e2cec34',
62 'time_stamp' => '20101212121212',
63 ];
64 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__);
65 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
66
67 $this->contactDelete($contactID);
68 }
69
70 /**
71 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
72 */
73 public function testMailerGroupUnsubscribeWrongParams() {
74 $params = [
75 'job_id' => 'Wrong ID',
76 'event_queue_id' => 'Wrong ID',
77 'hash' => 'Wrong Hash',
78 'time_stamp' => '20101212121212',
79 ];
80
81 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
82 }
83
84 /**
85 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
86 */
87 public function testMailerGroupDomainUnsubscribeWrongParams() {
88 $params = [
89 'job_id' => 'Wrong ID',
90 'event_queue_id' => 'Wrong ID',
91 'hash' => 'Wrong Hash',
92 'org_unsubscribe' => 1,
93 'time_stamp' => '20101212121212',
94 ];
95
96 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
97 }
98
99 /**
100 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
101 */
102
103 /**
104 * Test civicrm_mailing_group_event_resubscribe with wrong params.
105 */
106 public function testMailerGroupResubscribeWrongParams() {
107 $params = [
108 'job_id' => 'Wrong ID',
109 'event_queue_id' => 'Wrong ID',
110 'hash' => 'Wrong Hash',
111 'org_unsubscribe' => 'test',
112 'time_stamp' => '20101212121212',
113 ];
114 $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
115 }
116
117 /**
118 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
119 */
120 public function testMailerProcess() {
121 $params = [
122 'first_name' => 'Test',
123 'last_name' => 'Test',
124 'email' => $this->_email,
125 'contact_type' => 'Individual',
126 ];
127 $contactID = $this->individualCreate($params);
128
129 $params = [
130 'email' => $this->_email,
131 'group_id' => $this->_groupID,
132 'contact_id' => $contactID,
133 'hash' => 'b15de8b64e2cec34',
134 'time_stamp' => '20101212121212',
135 ];
136 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
137
138 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
139
140 $params = [
141 'contact_id' => $result['values'][$result['id']]['contact_id'],
142 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
143 'hash' => $result['values'][$result['id']]['hash'],
144 'time_stamp' => '20101212121212',
145 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
146 ];
147
148 $this->callAPISuccess('mailing_event_confirm', 'create', $params);
149 $this->contactDelete($contactID);
150 }
151
152 }