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 | |
00be9182 | 23 | public function setUp() { |
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() { | |
9099cab3 | 121 | $params = [ |
6a488035 TO |
122 | 'first_name' => 'Test', |
123 | 'last_name' => 'Test', | |
124 | 'email' => $this->_email, | |
ef170fe0 | 125 | 'contact_type' => 'Individual', |
9099cab3 | 126 | ]; |
6a488035 TO |
127 | $contactID = $this->individualCreate($params); |
128 | ||
9099cab3 | 129 | $params = [ |
6a488035 TO |
130 | 'email' => $this->_email, |
131 | 'group_id' => $this->_groupID, | |
ef170fe0 | 132 | 'contact_id' => $contactID, |
133 | 'hash' => 'b15de8b64e2cec34', | |
6a488035 | 134 | 'time_stamp' => '20101212121212', |
9099cab3 | 135 | ]; |
7f0eb6cb | 136 | $result = $this->callAPISuccess('mailing_event_subscribe', 'create', $params); |
6a488035 | 137 | |
9e23eadb | 138 | $this->assertEquals($result['values'][$result['id']]['contact_id'], $contactID); |
6a488035 | 139 | |
9099cab3 | 140 | $params = [ |
9e23eadb | 141 | 'contact_id' => $result['values'][$result['id']]['contact_id'], |
142 | 'subscribe_id' => $result['values'][$result['id']]['subscribe_id'], | |
ef170fe0 | 143 | 'hash' => $result['values'][$result['id']]['hash'], |
144 | 'time_stamp' => '20101212121212', | |
9e23eadb | 145 | 'event_subscribe_id' => $result['values'][$result['id']]['subscribe_id'], |
9099cab3 | 146 | ]; |
6a488035 | 147 | |
6f616e5c | 148 | $this->callAPISuccess('mailing_event_confirm', 'create', $params); |
6a488035 TO |
149 | $this->contactDelete($contactID); |
150 | } | |
96025800 | 151 | |
6a488035 | 152 | } |