Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
7d61e75f TO |
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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 10 | */ |
6a488035 | 11 | |
6a488035 TO |
12 | /** |
13 | * Test APIv3 civicrm_mailing_group_* functions | |
14 | * | |
6c6e6187 | 15 | * @package CiviCRM |
acb109b7 | 16 | * @group headless |
6a488035 TO |
17 | */ |
18 | class api_v3_MailingGroupTest extends CiviUnitTestCase { | |
19 | protected $_groupID; | |
20 | protected $_email; | |
430ae6dd | 21 | protected $_apiversion; |
b7c9bc4c | 22 | |
7ef12efc | 23 | public function setUp(): void { |
6a488035 | 24 | parent::setUp(); |
55941eb0 | 25 | $this->useTransaction(TRUE); |
6a488035 | 26 | $this->_apiversion = 3; |
fadb804f | 27 | $this->_groupID = $this->groupCreate(); |
ef170fe0 | 28 | $this->_email = 'test@test.test'; |
6a488035 TO |
29 | } |
30 | ||
6a488035 TO |
31 | /** |
32 | * Test civicrm_mailing_group_event_subscribe with wrong params. | |
33 | */ | |
34 | public function testMailerGroupSubscribeWrongParams() { | |
9099cab3 | 35 | $params = [ |
6a488035 TO |
36 | 'email' => $this->_email, |
37 | 'group_id' => 'Wrong Group ID', | |
ef170fe0 | 38 | 'contact_id' => '2121', |
39 | 'time_stamp' => '20111111010101', | |
6a488035 | 40 | 'hash' => 'sasa', |
9099cab3 | 41 | ]; |
7bd9cc5f | 42 | $this->callAPIFailure('mailing_event_subscribe', 'create', $params); |
6a488035 TO |
43 | } |
44 | ||
45 | /** | |
46 | * Test civicrm_mailing_group_event_subscribe with given contact ID. | |
47 | */ | |
48 | public function testMailerGroupSubscribeGivenContactId() { | |
9099cab3 | 49 | $params = [ |
6a488035 TO |
50 | 'first_name' => 'Test', |
51 | 'last_name' => 'Test', | |
52 | 'email' => $this->_email, | |
ef170fe0 | 53 | 'contact_type' => 'Individual', |
9099cab3 | 54 | ]; |
6a488035 TO |
55 | $contactID = $this->individualCreate($params); |
56 | ||
9099cab3 | 57 | $params = [ |
6a488035 TO |
58 | 'email' => $this->_email, |
59 | 'group_id' => $this->_groupID, | |
9f1b81e0 | 60 | 'contact_id' => $contactID, |
61 | 'hash' => 'b15de8b64e2cec34', | |
6a488035 | 62 | 'time_stamp' => '20101212121212', |
9099cab3 | 63 | ]; |
7f0eb6cb | 64 | $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__, __FILE__); |
9e23eadb | 65 | $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID); |
6a488035 TO |
66 | |
67 | $this->contactDelete($contactID); | |
68 | } | |
69 | ||
6a488035 TO |
70 | /** |
71 | * Test civicrm_mailing_group_event_unsubscribe with wrong params. | |
72 | */ | |
73 | public function testMailerGroupUnsubscribeWrongParams() { | |
9099cab3 | 74 | $params = [ |
6a488035 TO |
75 | 'job_id' => 'Wrong ID', |
76 | 'event_queue_id' => 'Wrong ID', | |
ef170fe0 | 77 | 'hash' => 'Wrong Hash', |
78 | 'time_stamp' => '20101212121212', | |
9099cab3 | 79 | ]; |
6a488035 | 80 | |
7bd9cc5f | 81 | $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params); |
6a488035 TO |
82 | } |
83 | ||
6a488035 TO |
84 | /** |
85 | * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params. | |
86 | */ | |
87 | public function testMailerGroupDomainUnsubscribeWrongParams() { | |
9099cab3 | 88 | $params = [ |
6a488035 TO |
89 | 'job_id' => 'Wrong ID', |
90 | 'event_queue_id' => 'Wrong ID', | |
91 | 'hash' => 'Wrong Hash', | |
ef170fe0 | 92 | 'org_unsubscribe' => 1, |
93 | 'time_stamp' => '20101212121212', | |
9099cab3 | 94 | ]; |
6a488035 | 95 | |
7bd9cc5f | 96 | $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params); |
6a488035 TO |
97 | } |
98 | ||
6a488035 TO |
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() { | |
9099cab3 | 107 | $params = [ |
6a488035 TO |
108 | 'job_id' => 'Wrong ID', |
109 | 'event_queue_id' => 'Wrong ID', | |
110 | 'hash' => 'Wrong Hash', | |
ef170fe0 | 111 | 'org_unsubscribe' => 'test', |
112 | 'time_stamp' => '20101212121212', | |
9099cab3 | 113 | ]; |
7bd9cc5f | 114 | $this->callAPIFailure('mailing_event_resubscribe', 'create', $params); |
6a488035 TO |
115 | } |
116 | ||
6a488035 TO |
117 | /** |
118 | * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected. | |
119 | */ | |
120 | public function testMailerProcess() { | |
52f4ecb2 SL |
121 | $this->callAPISuccess('MailSettings', 'create', [ |
122 | 'domain_id' => 1, | |
123 | 'name' => "my mail setting", | |
124 | 'domain' => 'setting.com', | |
125 | 'localpart' => 'civicrm+', | |
126 | 'server' => "localhost", | |
127 | 'username' => 'sue', | |
128 | 'password' => 'pass', | |
129 | 'is_default' => 1, | |
130 | ]); | |
131 | $mut = new CiviMailUtils($this, TRUE); | |
132 | Civi::settings()->set('include_message_id', 1); | |
9099cab3 | 133 | $params = [ |
6a488035 TO |
134 | 'first_name' => 'Test', |
135 | 'last_name' => 'Test', | |
136 | 'email' => $this->_email, | |
ef170fe0 | 137 | 'contact_type' => 'Individual', |
9099cab3 | 138 | ]; |
6a488035 TO |
139 | $contactID = $this->individualCreate($params); |
140 | ||
9099cab3 | 141 | $params = [ |
6a488035 TO |
142 | 'email' => $this->_email, |
143 | 'group_id' => $this->_groupID, | |
ef170fe0 | 144 | 'contact_id' => $contactID, |
145 | 'hash' => 'b15de8b64e2cec34', | |
6a488035 | 146 | 'time_stamp' => '20101212121212', |
9099cab3 | 147 | ]; |
7f0eb6cb | 148 | $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params); |
52f4ecb2 SL |
149 | // Check that subscription email has been sent. |
150 | $msgs = $mut->getAllMessages(); | |
151 | $this->assertCount(1, $msgs, 'Subscription email failed to send'); | |
152 | $mut->checkMailLog([ | |
153 | 'Message-ID: <civicrm+s', | |
154 | 'To confirm this subscription, reply to this email or click', | |
155 | ]); | |
6a488035 | 156 | |
9e23eadb | 157 | $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID); |
6a488035 | 158 | |
9099cab3 | 159 | $params = [ |
9e23eadb | 160 | 'contact_id' => $result['values'][$result['id']]['contact_id'], |
161 | 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'], | |
ef170fe0 | 162 | 'hash' => $result['values'][$result['id']]['hash'], |
163 | 'time_stamp' => '20101212121212', | |
9e23eadb | 164 | 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'], |
9099cab3 | 165 | ]; |
6a488035 | 166 | |
6f616e5c | 167 | $this->callAPISuccess('mailing_event_confirm', 'create', $params); |
6a488035 | 168 | $this->contactDelete($contactID); |
52f4ecb2 | 169 | Civi::settings()->set('include_message_id', 0); |
6a488035 | 170 | } |
96025800 | 171 | |
6a488035 | 172 | } |