3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * Test APIv3 civicrm_mailing_group_* functions
18 class api_v3_MailingGroupTest
extends CiviUnitTestCase
{
21 protected $_apiversion;
23 public function setUp() {
25 $this->useTransaction(TRUE);
26 $this->_apiversion
= 3;
27 $this->_groupID
= $this->groupCreate();
28 $this->_email
= 'test@test.test';
32 * Test civicrm_mailing_group_event_subscribe with wrong params.
34 public function testMailerGroupSubscribeWrongParams() {
36 'email' => $this->_email
,
37 'group_id' => 'Wrong Group ID',
38 'contact_id' => '2121',
39 'time_stamp' => '20111111010101',
42 $this->callAPIFailure('mailing_event_subscribe', 'create', $params);
46 * Test civicrm_mailing_group_event_subscribe with given contact ID.
48 public function testMailerGroupSubscribeGivenContactId() {
50 'first_name' => 'Test',
51 'last_name' => 'Test',
52 'email' => $this->_email
,
53 'contact_type' => 'Individual',
55 $contactID = $this->individualCreate($params);
58 'email' => $this->_email
,
59 'group_id' => $this->_groupID
,
60 'contact_id' => $contactID,
61 'hash' => 'b15de8b64e2cec34',
62 'time_stamp' => '20101212121212',
64 $result = $this->callAPIAndDocument('mailing_event_subscribe', 'create', $params, __FUNCTION__
, __FILE__
);
65 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
67 $this->contactDelete($contactID);
71 * Test civicrm_mailing_group_event_unsubscribe with wrong params.
73 public function testMailerGroupUnsubscribeWrongParams() {
75 'job_id' => 'Wrong ID',
76 'event_queue_id' => 'Wrong ID',
77 'hash' => 'Wrong Hash',
78 'time_stamp' => '20101212121212',
81 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
85 * Test civicrm_mailing_group_event_domain_unsubscribe with wrong params.
87 public function testMailerGroupDomainUnsubscribeWrongParams() {
89 'job_id' => 'Wrong ID',
90 'event_queue_id' => 'Wrong ID',
91 'hash' => 'Wrong Hash',
92 'org_unsubscribe' => 1,
93 'time_stamp' => '20101212121212',
96 $this->callAPIFailure('mailing_event_unsubscribe', 'create', $params);
100 * Test civicrm_mailing_group_event_resubscribe with wrong params type.
104 * Test civicrm_mailing_group_event_resubscribe with wrong params.
106 public function testMailerGroupResubscribeWrongParams() {
108 'job_id' => 'Wrong ID',
109 'event_queue_id' => 'Wrong ID',
110 'hash' => 'Wrong Hash',
111 'org_unsubscribe' => 'test',
112 'time_stamp' => '20101212121212',
114 $this->callAPIFailure('mailing_event_resubscribe', 'create', $params);
118 * Test civicrm_mailing_group_event_subscribe and civicrm_mailing_event_confirm functions - success expected.
120 public function testMailerProcess() {
121 $this->callAPISuccess('MailSettings', 'create', [
123 'name' => "my mail setting",
124 'domain' => 'setting.com',
125 'localpart' => 'civicrm+',
126 'server' => "localhost",
128 'password' => 'pass',
131 $mut = new CiviMailUtils($this, TRUE);
132 Civi
::settings()->set('include_message_id', 1);
134 'first_name' => 'Test',
135 'last_name' => 'Test',
136 'email' => $this->_email
,
137 'contact_type' => 'Individual',
139 $contactID = $this->individualCreate($params);
142 'email' => $this->_email
,
143 'group_id' => $this->_groupID
,
144 'contact_id' => $contactID,
145 'hash' => 'b15de8b64e2cec34',
146 'time_stamp' => '20101212121212',
148 $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params);
149 // Check that subscription email has been sent.
150 $msgs = $mut->getAllMessages();
151 $this->assertCount(1, $msgs, 'Subscription email failed to send');
153 'Message-ID: <civicrm+s',
154 'To confirm this subscription, reply to this email or click',
157 $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID);
160 'contact_id' => $result['values'][$result['id']]['contact_id'],
161 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
162 'hash' => $result['values'][$result['id']]['hash'],
163 'time_stamp' => '20101212121212',
164 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'],
167 $this->callAPISuccess('mailing_event_confirm', 'create', $params);
168 $this->contactDelete($contactID);
169 Civi
::settings()->set('include_message_id', 0);