Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
4cbe18b8 EM |
28 | /** |
29 | * Class CRM_Member_BAO_MembershipTest | |
acb109b7 | 30 | * @group headless |
4cbe18b8 | 31 | */ |
6a488035 | 32 | class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { |
6a488035 | 33 | |
00be9182 | 34 | public function setUp() { |
6a488035 TO |
35 | parent::setUp(); |
36 | // FIXME: something NULLs $GLOBALS['_HTML_QuickForm_registered_rules'] when the tests are ran all together | |
9099cab3 CW |
37 | $GLOBALS['_HTML_QuickForm_registered_rules'] = [ |
38 | 'required' => ['html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'], | |
39 | 'maxlength' => ['html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'], | |
40 | 'minlength' => ['html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'], | |
41 | 'rangelength' => ['html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'], | |
42 | 'email' => ['html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'], | |
43 | 'regex' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'], | |
44 | 'lettersonly' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'], | |
45 | 'alphanumeric' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'], | |
46 | 'numeric' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'], | |
47 | 'nopunctuation' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'], | |
48 | 'nonzero' => ['html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'], | |
49 | 'callback' => ['html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'], | |
50 | 'compare' => ['html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php'], | |
51 | ]; | |
6a488035 TO |
52 | |
53 | $this->_contactID = $this->organizationCreate(); | |
9099cab3 | 54 | $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]); |
6a488035 TO |
55 | // add a random number to avoid silly conflicts with old data |
56 | $this->_membershipStatusID = $this->membershipStatusCreate('test status' . rand(1, 1000)); | |
57 | } | |
58 | ||
59 | /** | |
60 | * Tears down the fixture, for example, closes a network connection. | |
61 | * This method is called after a test is executed. | |
6a488035 | 62 | */ |
00be9182 | 63 | public function tearDown() { |
9099cab3 | 64 | $this->membershipTypeDelete(['id' => $this->_membershipTypeID]); |
481a74f4 | 65 | $this->membershipStatusDelete($this->_membershipStatusID); |
93ac19cd | 66 | $this->contactDelete($this->_contactID); |
6a488035 | 67 | |
6c6e6187 | 68 | $this->_contactID = $this->_membershipStatusID = $this->_membershipTypeID = NULL; |
6a488035 TO |
69 | } |
70 | ||
5c3a7abf AP |
71 | /** |
72 | * Create membership type using given organization id. | |
73 | * @param $organizationId | |
39b959db | 74 | * @param bool $withRelationship |
5c3a7abf AP |
75 | * @return array|int |
76 | */ | |
77 | private function createMembershipType($organizationId, $withRelationship = FALSE) { | |
9099cab3 | 78 | $membershipType = $this->callAPISuccess('MembershipType', 'create', [ |
39b959db SL |
79 | //Default domain ID |
80 | 'domain_id' => 1, | |
5c3a7abf AP |
81 | 'member_of_contact_id' => $organizationId, |
82 | 'financial_type_id' => "Member Dues", | |
83 | 'duration_unit' => "year", | |
84 | 'duration_interval' => 1, | |
85 | 'period_type' => "rolling", | |
86 | 'name' => "Organiation Membership Type", | |
87 | 'relationship_type_id' => ($withRelationship) ? 5 : NULL, | |
88 | 'relationship_direction' => ($withRelationship) ? 'b_a' : NULL, | |
9099cab3 | 89 | ]); |
5c3a7abf AP |
90 | return $membershipType["values"][$membershipType["id"]]; |
91 | } | |
92 | ||
93 | /** | |
94 | * Get count of related memberships by parent membership id. | |
95 | * @param $membershipId | |
96 | * @return array|int | |
97 | */ | |
98 | private function getRelatedMembershipsCount($membershipId) { | |
9099cab3 | 99 | return $this->callAPISuccess("Membership", "getcount", [ |
5c3a7abf | 100 | 'owner_membership_id' => $membershipId, |
9099cab3 | 101 | ]); |
5c3a7abf AP |
102 | } |
103 | ||
104 | /** | |
105 | * Test to delete related membership when type of parent memebrship is changed which does not have relation type associated. | |
106 | * @throws CRM_Core_Exception | |
107 | */ | |
108 | public function testDeleteRelatedMembershipsOnParentTypeChanged() { | |
109 | ||
110 | $contactId = $this->individualCreate(); | |
111 | $membershipOrganizationId = $this->organizationCreate(); | |
112 | $organizationId = $this->organizationCreate(); | |
113 | ||
114 | // Create relationship between organization and individual contact | |
9099cab3 | 115 | $this->callAPISuccess('Relationship', 'create', [ |
39b959db SL |
116 | // Employer of relationship |
117 | 'relationship_type_id' => 5, | |
5c3a7abf AP |
118 | 'contact_id_a' => $contactId, |
119 | 'contact_id_b' => $organizationId, | |
120 | 'is_active' => 1, | |
9099cab3 | 121 | ]); |
5c3a7abf AP |
122 | |
123 | // Create two membership types one with relationship and one without. | |
124 | $membershipTypeWithRelationship = $this->createMembershipType($membershipOrganizationId, TRUE); | |
125 | $membershipTypeWithoutRelationship = $this->createMembershipType($membershipOrganizationId); | |
126 | ||
127 | // Creating membership of organisation | |
9099cab3 | 128 | $membership = $this->callAPISuccess("Membership", "create", [ |
5c3a7abf AP |
129 | 'membership_type_id' => $membershipTypeWithRelationship["id"], |
130 | 'contact_id' => $organizationId, | |
131 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 | 132 | ]); |
5c3a7abf AP |
133 | |
134 | $membership = $membership["values"][$membership["id"]]; | |
135 | ||
136 | // Check count of related memberships. It should be one for individual contact. | |
137 | $relatedMembershipsCount = $this->getRelatedMembershipsCount($membership["id"]); | |
138 | $this->assertEquals(1, $relatedMembershipsCount, 'Related membership count should be 1.'); | |
139 | ||
140 | // Update membership by changing it's type. New membership type is without relationship. | |
141 | $membership["membership_type_id"] = $membershipTypeWithoutRelationship["id"]; | |
142 | $updatedMembership = $this->callAPISuccess("Membership", "create", $membership); | |
143 | ||
144 | // Check count of related memberships again. It should be zero as we changed the membership type. | |
145 | $relatedMembershipsCount = $this->getRelatedMembershipsCount($membership["id"]); | |
146 | $this->assertEquals(0, $relatedMembershipsCount, 'Related membership count should be 0.'); | |
147 | ||
148 | // Clean up: Delete membership | |
149 | $this->membershipDelete($membership["id"]); | |
150 | } | |
151 | ||
00be9182 | 152 | public function testCreate() { |
6a488035 | 153 | |
6ae19242 | 154 | $contactId = $this->individualCreate(); |
6a488035 | 155 | |
9099cab3 | 156 | $params = [ |
6a488035 TO |
157 | 'contact_id' => $contactId, |
158 | 'membership_type_id' => $this->_membershipTypeID, | |
6c6e6187 TO |
159 | 'join_date' => date('Ymd', strtotime('2006-01-21')), |
160 | 'start_date' => date('Ymd', strtotime('2006-01-21')), | |
161 | 'end_date' => date('Ymd', strtotime('2006-12-21')), | |
6a488035 TO |
162 | 'source' => 'Payment', |
163 | 'is_override' => 1, | |
164 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
165 | ]; |
166 | $ids = []; | |
6a488035 TO |
167 | CRM_Member_BAO_Membership::create($params, $ids); |
168 | ||
169 | $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', | |
170 | 'contact_id', 'Database check for created membership.' | |
171 | ); | |
172 | ||
173 | // Now call create() to modify an existing Membership | |
174 | ||
9099cab3 CW |
175 | $params = []; |
176 | $params = [ | |
6a488035 TO |
177 | 'contact_id' => $contactId, |
178 | 'membership_type_id' => $this->_membershipTypeID, | |
6c6e6187 TO |
179 | 'join_date' => date('Ymd', strtotime('2006-01-21')), |
180 | 'start_date' => date('Ymd', strtotime('2006-01-21')), | |
181 | 'end_date' => date('Ymd', strtotime('2006-12-21')), | |
6a488035 TO |
182 | 'source' => 'Payment', |
183 | 'is_override' => 1, | |
184 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
185 | ]; |
186 | $ids = [ | |
6a488035 | 187 | 'membership' => $membershipId, |
9099cab3 | 188 | ]; |
6a488035 TO |
189 | CRM_Member_BAO_Membership::create($params, $ids); |
190 | ||
191 | $membershipTypeId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, | |
192 | 'membership_type_id', 'contact_id', | |
193 | 'Database check on updated membership record.' | |
194 | ); | |
195 | $this->assertEquals($membershipTypeId, $this->_membershipTypeID, 'Verify membership type id is fetched.'); | |
196 | ||
197 | $this->membershipDelete($membershipId); | |
93ac19cd | 198 | $this->contactDelete($contactId); |
6a488035 TO |
199 | } |
200 | ||
00be9182 | 201 | public function testGetValues() { |
6a488035 TO |
202 | // $this->markTestSkipped( 'causes mysterious exit, needs fixing!' ); |
203 | // Calculate membership dates based on the current date | |
204 | $now = time(); | |
205 | $year_from_now = $now + (365 * 24 * 60 * 60); | |
206 | $last_month = $now - (30 * 24 * 60 * 60); | |
207 | $year_from_last_month = $last_month + (365 * 24 * 60 * 60); | |
208 | ||
6ae19242 | 209 | $contactId = $this->individualCreate(); |
6a488035 | 210 | |
9099cab3 | 211 | $params = [ |
6a488035 TO |
212 | 'contact_id' => $contactId, |
213 | 'membership_type_id' => $this->_membershipTypeID, | |
214 | 'join_date' => date('Ymd'), | |
215 | 'start_date' => date('Ymd'), | |
216 | 'end_date' => date('Ymd', $year_from_now), | |
217 | 'source' => 'Payment', | |
218 | 'is_override' => 1, | |
219 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 | 220 | ]; |
6a488035 | 221 | |
9099cab3 | 222 | $ids = []; |
6a488035 TO |
223 | CRM_Member_BAO_Membership::create($params, $ids); |
224 | ||
225 | $membershipId1 = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', | |
226 | 'contact_id', 'Database check for created membership.' | |
227 | ); | |
228 | ||
9099cab3 | 229 | $params = [ |
6a488035 TO |
230 | 'contact_id' => $contactId, |
231 | 'membership_type_id' => $this->_membershipTypeID, | |
232 | 'join_date' => date('Ymd', $last_month), | |
233 | 'start_date' => date('Ymd', $last_month), | |
234 | 'end_date' => date('Ymd', $year_from_last_month), | |
235 | 'source' => 'Source123', | |
236 | 'is_override' => 0, | |
237 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
238 | ]; |
239 | $ids = []; | |
6a488035 TO |
240 | CRM_Member_BAO_Membership::create($params, $ids); |
241 | ||
242 | $membershipId2 = $this->assertDBNotNull('CRM_Member_BAO_Membership', 'source123', 'id', | |
243 | 'source', 'Database check for created membership.' | |
244 | ); | |
245 | ||
9099cab3 CW |
246 | $membership = ['contact_id' => $contactId]; |
247 | $membershipValues = []; | |
6a488035 TO |
248 | CRM_Member_BAO_Membership::getValues($membership, $membershipValues, TRUE); |
249 | ||
250 | $this->assertEquals($membershipValues[$membershipId1]['membership_id'], $membershipId1, 'Verify membership record 1 is fetched.'); | |
251 | ||
252 | $this->assertEquals($membershipValues[$membershipId2]['membership_id'], $membershipId2, 'Verify membership record 2 is fetched.'); | |
253 | ||
254 | $this->membershipDelete($membershipId1); | |
255 | $this->membershipDelete($membershipId2); | |
93ac19cd | 256 | $this->contactDelete($contactId); |
6a488035 TO |
257 | } |
258 | ||
00be9182 | 259 | public function testRetrieve() { |
6ae19242 | 260 | $contactId = $this->individualCreate(); |
6a488035 | 261 | |
9099cab3 | 262 | $params = [ |
6a488035 TO |
263 | 'contact_id' => $contactId, |
264 | 'membership_type_id' => $this->_membershipTypeID, | |
6c6e6187 TO |
265 | 'join_date' => date('Ymd', strtotime('2006-01-21')), |
266 | 'start_date' => date('Ymd', strtotime('2006-01-21')), | |
267 | 'end_date' => date('Ymd', strtotime('2006-12-21')), | |
6a488035 TO |
268 | 'source' => 'Payment', |
269 | 'is_override' => 1, | |
270 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
271 | ]; |
272 | $ids = []; | |
6a488035 TO |
273 | CRM_Member_BAO_Membership::create($params, $ids); |
274 | ||
275 | $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', | |
276 | 'contact_id', 'Database check for created membership.' | |
277 | ); | |
9099cab3 CW |
278 | $params = ['id' => $membershipId]; |
279 | $values = []; | |
6a488035 TO |
280 | CRM_Member_BAO_Membership::retrieve($params, $values); |
281 | $this->assertEquals($values['id'], $membershipId, 'Verify membership record is retrieved.'); | |
282 | ||
283 | $this->membershipDelete($membershipId); | |
284 | $this->contactDelete($contactId); | |
285 | } | |
286 | ||
00be9182 | 287 | public function testActiveMembers() { |
6ae19242 | 288 | $contactId = $this->individualCreate(); |
6a488035 | 289 | |
9099cab3 | 290 | $params = [ |
6a488035 TO |
291 | 'contact_id' => $contactId, |
292 | 'membership_type_id' => $this->_membershipTypeID, | |
6c6e6187 TO |
293 | 'join_date' => date('Ymd', strtotime('2006-01-21')), |
294 | 'start_date' => date('Ymd', strtotime('2006-01-21')), | |
295 | 'end_date' => date('Ymd', strtotime('2006-12-21')), | |
6a488035 TO |
296 | 'source' => 'Payment', |
297 | 'is_override' => 1, | |
298 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
299 | ]; |
300 | $ids = []; | |
6a488035 TO |
301 | CRM_Member_BAO_Membership::create($params, $ids); |
302 | ||
303 | $membershipId1 = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', | |
304 | 'contact_id', 'Database check for created membership.' | |
305 | ); | |
306 | ||
9099cab3 CW |
307 | $params = ['id' => $membershipId1]; |
308 | $values1 = []; | |
6a488035 | 309 | CRM_Member_BAO_Membership::retrieve($params, $values1); |
9099cab3 | 310 | $membership = [$membershipId1 => $values1]; |
6a488035 | 311 | |
9099cab3 | 312 | $params = [ |
6a488035 TO |
313 | 'contact_id' => $contactId, |
314 | 'membership_type_id' => $this->_membershipTypeID, | |
6c6e6187 TO |
315 | 'join_date' => date('Ymd', strtotime('2006-01-21')), |
316 | 'start_date' => date('Ymd', strtotime('2006-01-21')), | |
317 | 'end_date' => date('Ymd', strtotime('2006-12-21')), | |
6a488035 TO |
318 | 'source' => 'PaySource', |
319 | 'is_override' => 1, | |
320 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
321 | ]; |
322 | $ids = []; | |
6a488035 TO |
323 | CRM_Member_BAO_Membership::create($params, $ids); |
324 | ||
325 | $membershipId2 = $this->assertDBNotNull('CRM_Member_BAO_Membership', 'PaySource', 'id', | |
326 | 'source', 'Database check for created membership.' | |
327 | ); | |
328 | ||
9099cab3 CW |
329 | $params = ['id' => $membershipId2]; |
330 | $values2 = []; | |
6a488035 TO |
331 | CRM_Member_BAO_Membership::retrieve($params, $values2); |
332 | $membership[$membershipId2] = $values2; | |
333 | ||
334 | $activeMembers = CRM_Member_BAO_Membership::activeMembers($membership); | |
335 | $inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive'); | |
336 | ||
337 | $this->assertEquals($activeMembers[$membershipId1]['id'], $membership[$membershipId1]['id'], 'Verify active membership record is retrieved.'); | |
338 | $this->assertEquals($activeMembers[$membershipId2]['id'], $membership[$membershipId2]['id'], 'Verify active membership record is retrieved.'); | |
339 | ||
340 | $this->assertEquals(0, count($inActiveMembers), 'Verify No inactive membership record is retrieved.'); | |
341 | ||
342 | $this->membershipDelete($membershipId1); | |
343 | $this->membershipDelete($membershipId2); | |
93ac19cd | 344 | $this->contactDelete($contactId); |
6a488035 TO |
345 | } |
346 | ||
00be9182 | 347 | public function testDeleteMembership() { |
6ae19242 | 348 | $contactId = $this->individualCreate(); |
6a488035 | 349 | |
9099cab3 | 350 | $params = [ |
6a488035 TO |
351 | 'contact_id' => $contactId, |
352 | 'membership_type_id' => $this->_membershipTypeID, | |
6c6e6187 TO |
353 | 'join_date' => date('Ymd', strtotime('2006-01-21')), |
354 | 'start_date' => date('Ymd', strtotime('2006-01-21')), | |
355 | 'end_date' => date('Ymd', strtotime('2006-12-21')), | |
6a488035 TO |
356 | 'source' => 'Payment', |
357 | 'is_override' => 1, | |
358 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
359 | ]; |
360 | $ids = []; | |
6a488035 TO |
361 | CRM_Member_BAO_Membership::create($params, $ids); |
362 | ||
363 | $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', | |
364 | 'contact_id', 'Database check for created membership.' | |
365 | ); | |
3506b6cd | 366 | CRM_Member_BAO_Membership::del($membershipId); |
6a488035 | 367 | |
93ac19cd | 368 | $this->assertDBNull('CRM_Member_BAO_Membership', $contactId, 'id', |
6a488035 TO |
369 | 'contact_id', 'Database check for deleted membership.' |
370 | ); | |
93ac19cd | 371 | $this->contactDelete($contactId); |
6a488035 TO |
372 | } |
373 | ||
00be9182 | 374 | public function testGetContactMembership() { |
6ae19242 | 375 | $contactId = $this->individualCreate(); |
6a488035 | 376 | |
9099cab3 | 377 | $params = [ |
6a488035 TO |
378 | 'contact_id' => $contactId, |
379 | 'membership_type_id' => $this->_membershipTypeID, | |
6c6e6187 TO |
380 | 'join_date' => date('Ymd', strtotime('2006-01-21')), |
381 | 'start_date' => date('Ymd', strtotime('2006-01-21')), | |
382 | 'end_date' => date('Ymd', strtotime('2006-12-21')), | |
6a488035 TO |
383 | 'source' => 'Payment', |
384 | 'is_override' => 1, | |
385 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
386 | ]; |
387 | $ids = []; | |
6a488035 TO |
388 | CRM_Member_BAO_Membership::create($params, $ids); |
389 | ||
390 | $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', | |
391 | 'contact_id', 'Database check for created membership.' | |
392 | ); | |
393 | ||
394 | $membership = CRM_Member_BAO_Membership::getContactMembership($contactId, $this->_membershipTypeID, FALSE); | |
395 | ||
396 | $this->assertEquals($membership['id'], $membershipId, 'Verify membership record is retrieved.'); | |
397 | ||
398 | $this->membershipDelete($membershipId); | |
93ac19cd | 399 | $this->contactDelete($contactId); |
6a488035 TO |
400 | } |
401 | ||
c490a46a | 402 | /** |
eceb18cc | 403 | * Get the contribution. |
c490a46a CW |
404 | * page id from the membership record |
405 | */ | |
00be9182 | 406 | public function testgetContributionPageId() { |
6ae19242 | 407 | $contactId = $this->individualCreate(); |
6a488035 | 408 | |
9099cab3 | 409 | $params = [ |
6a488035 TO |
410 | 'contact_id' => $contactId, |
411 | 'membership_type_id' => $this->_membershipTypeID, | |
6c6e6187 TO |
412 | 'join_date' => date('Ymd', strtotime('2006-01-21')), |
413 | 'start_date' => date('Ymd', strtotime('2006-01-21')), | |
414 | 'end_date' => date('Ymd', strtotime('2006-12-21')), | |
6a488035 TO |
415 | 'source' => 'Payment', |
416 | 'is_override' => 1, | |
417 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
418 | ]; |
419 | $ids = []; | |
6a488035 TO |
420 | CRM_Member_BAO_Membership::create($params, $ids); |
421 | ||
6a488035 TO |
422 | $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', |
423 | 'contact_id', 'Database check for created membership.' | |
424 | ); | |
425 | $membership[$membershipId]['renewPageId'] = CRM_Member_BAO_Membership::getContributionPageId($membershipId); | |
426 | ||
427 | $this->membershipDelete($membershipId); | |
93ac19cd | 428 | $this->contactDelete($contactId); |
6a488035 | 429 | } |
92915c55 | 430 | |
c490a46a CW |
431 | /** |
432 | * Get membership joins/renewals | |
433 | * for a specified membership | |
434 | * type. | |
c490a46a | 435 | */ |
00be9182 | 436 | public function testgetMembershipStarts() { |
6ae19242 | 437 | $contactId = $this->individualCreate(); |
6a488035 | 438 | |
9099cab3 | 439 | $params = [ |
6a488035 TO |
440 | 'contact_id' => $contactId, |
441 | 'membership_type_id' => $this->_membershipTypeID, | |
6c6e6187 TO |
442 | 'join_date' => date('Ymd', strtotime('2006-01-21')), |
443 | 'start_date' => date('Ymd', strtotime('2006-01-21')), | |
444 | 'end_date' => date('Ymd', strtotime('2006-12-21')), | |
6a488035 TO |
445 | 'source' => 'Payment', |
446 | 'is_override' => 1, | |
447 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
448 | ]; |
449 | $ids = []; | |
6a488035 TO |
450 | CRM_Member_BAO_Membership::create($params, $ids); |
451 | ||
452 | $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', | |
453 | 'contact_id', 'Database check for created membership.' | |
454 | ); | |
455 | $yearStart = date('Y') . '0101'; | |
456 | $currentDate = date('Ymd'); | |
457 | CRM_Member_BAO_Membership::getMembershipStarts($this->_membershipTypeID, $yearStart, $currentDate); | |
458 | ||
459 | $this->membershipDelete($membershipId); | |
93ac19cd | 460 | $this->contactDelete($contactId); |
6a488035 TO |
461 | } |
462 | ||
c490a46a CW |
463 | /** |
464 | * Get a count of membership for a specified membership type, | |
465 | * optionally for a specified date. | |
c490a46a | 466 | */ |
00be9182 | 467 | public function testGetMembershipCount() { |
6ae19242 | 468 | $contactId = $this->individualCreate(); |
6a488035 | 469 | |
9099cab3 | 470 | $params = [ |
6a488035 TO |
471 | 'contact_id' => $contactId, |
472 | 'membership_type_id' => $this->_membershipTypeID, | |
6c6e6187 TO |
473 | 'join_date' => date('Ymd', strtotime('2006-01-21')), |
474 | 'start_date' => date('Ymd', strtotime('2006-01-21')), | |
475 | 'end_date' => date('Ymd', strtotime('2006-12-21')), | |
6a488035 TO |
476 | 'source' => 'Payment', |
477 | 'is_override' => 1, | |
478 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
479 | ]; |
480 | $ids = []; | |
6a488035 TO |
481 | CRM_Member_BAO_Membership::create($params, $ids); |
482 | ||
483 | $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', | |
484 | 'contact_id', 'Database check for created membership.' | |
485 | ); | |
486 | $currentDate = date('Ymd'); | |
487 | $test = 0; | |
488 | CRM_Member_BAO_Membership::getMembershipCount($this->_membershipTypeID, $currentDate, $test); | |
489 | ||
490 | $this->membershipDelete($membershipId); | |
93ac19cd | 491 | $this->contactDelete($contactId); |
6a488035 TO |
492 | } |
493 | ||
c490a46a | 494 | /** |
e4649817 | 495 | * Checkup sort name function. |
c490a46a | 496 | */ |
e4649817 | 497 | public function testSortName() { |
498 | $contactId = $this->individualCreate(); | |
6a488035 | 499 | |
9099cab3 | 500 | $params = [ |
6a488035 TO |
501 | 'contact_id' => $contactId, |
502 | 'membership_type_id' => $this->_membershipTypeID, | |
e4649817 | 503 | 'join_date' => '2006-01-21', |
504 | 'start_date' => '2006-01-21', | |
505 | 'end_date' => '2006-12-21', | |
6a488035 TO |
506 | 'source' => 'Payment', |
507 | 'is_override' => 1, | |
508 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 | 509 | ]; |
6a488035 | 510 | |
e4649817 | 511 | $membership = $this->callAPISuccess('Membership', 'create', $params); |
6a488035 | 512 | |
e4649817 | 513 | $this->assertEquals('Anderson, Anthony', CRM_Member_BAO_Membership::sortName($membership['id'])); |
6a488035 | 514 | |
e4649817 | 515 | $this->membershipDelete($membership['id']); |
93ac19cd | 516 | $this->contactDelete($contactId); |
6a488035 TO |
517 | } |
518 | ||
c490a46a | 519 | /** |
eceb18cc | 520 | * Delete related memberships. |
c490a46a | 521 | */ |
00be9182 | 522 | public function testdeleteRelatedMemberships() { |
e4649817 | 523 | $contactId = $this->individualCreate(); |
6a488035 | 524 | |
9099cab3 | 525 | $params = [ |
6a488035 TO |
526 | 'contact_id' => $contactId, |
527 | 'membership_type_id' => $this->_membershipTypeID, | |
6c6e6187 TO |
528 | 'join_date' => date('Ymd', strtotime('2006-01-21')), |
529 | 'start_date' => date('Ymd', strtotime('2006-01-21')), | |
530 | 'end_date' => date('Ymd', strtotime('2006-12-21')), | |
6a488035 TO |
531 | 'source' => 'Payment', |
532 | 'is_override' => 1, | |
533 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
534 | ]; |
535 | $ids = []; | |
6a488035 TO |
536 | |
537 | CRM_Member_BAO_Membership::create($params, $ids); | |
538 | ||
539 | $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', | |
540 | 'contact_id', 'Database check for created membership.' | |
541 | ); | |
542 | ||
543 | CRM_Member_BAO_Membership::deleteRelatedMemberships($membershipId); | |
544 | ||
545 | $this->membershipDelete($membershipId); | |
93ac19cd | 546 | $this->contactDelete($contactId); |
6a488035 TO |
547 | } |
548 | ||
c490a46a | 549 | /** |
eceb18cc | 550 | * Renew membership with change in membership type. |
c490a46a | 551 | */ |
00be9182 | 552 | public function testRenewMembership() { |
e4649817 | 553 | $contactId = $this->individualCreate(); |
92915c55 TO |
554 | $joinDate = $startDate = date("Ymd", strtotime(date("Ymd") . " -6 month")); |
555 | $endDate = date("Ymd", strtotime($joinDate . " +1 year -1 day")); | |
9099cab3 | 556 | $params = [ |
6a488035 TO |
557 | 'contact_id' => $contactId, |
558 | 'membership_type_id' => $this->_membershipTypeID, | |
559 | 'join_date' => $joinDate, | |
560 | 'start_date' => $startDate, | |
561 | 'end_date' => $endDate, | |
562 | 'source' => 'Payment', | |
563 | 'is_override' => 1, | |
564 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
565 | ]; |
566 | $ids = []; | |
92915c55 | 567 | $membership = CRM_Member_BAO_Membership::create($params, $ids); |
6a488035 TO |
568 | $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', |
569 | 'contact_id', 'Database check for created membership.' | |
570 | ); | |
571 | ||
572 | $this->assertDBNotNull('CRM_Member_BAO_MembershipLog', | |
573 | $membership->id, | |
574 | 'id', | |
575 | 'membership_id', | |
576 | 'Database checked on membershiplog record.' | |
577 | ); | |
578 | ||
579 | // this is a test and we dont want qfKey generation / validation | |
580 | // easier to suppress it, than change core code | |
581 | $config = CRM_Core_Config::singleton(); | |
582 | $config->keyDisable = TRUE; | |
583 | ||
6a488035 | 584 | $isTestMembership = 0; |
356bfcaf | 585 | list($MembershipRenew) = CRM_Member_BAO_Membership::processMembership( |
ae5ffbb7 TO |
586 | $contactId, |
587 | $this->_membershipTypeID, | |
588 | $isTestMembership, | |
ae5ffbb7 | 589 | NULL, |
595f9e7c EM |
590 | NULL, |
591 | NULL, | |
592 | 1, | |
66e83bf5 | 593 | FALSE, |
594 | NULL, | |
595 | NULL, | |
596 | FALSE, | |
595f9e7c | 597 | NULL, |
66e83bf5 | 598 | NULL |
ae5ffbb7 | 599 | ); |
6a488035 TO |
600 | $endDate = date("Y-m-d", strtotime($membership->end_date . " +1 year")); |
601 | ||
602 | $this->assertDBNotNull('CRM_Member_BAO_MembershipLog', | |
603 | $MembershipRenew->id, | |
604 | 'id', | |
605 | 'membership_id', | |
606 | 'Database checked on membershiplog record.' | |
607 | ); | |
1038ea01 EM |
608 | $this->assertEquals($this->_membershipTypeID, $MembershipRenew->membership_type_id, 'Verify membership type is changed during renewal.'); |
609 | $this->assertEquals($endDate, $MembershipRenew->end_date, 'Verify correct end date is calculated after membership renewal'); | |
6a488035 TO |
610 | |
611 | $this->membershipDelete($membershipId); | |
93ac19cd | 612 | $this->contactDelete($contactId); |
6a488035 TO |
613 | } |
614 | ||
c490a46a | 615 | /** |
eceb18cc | 616 | * Renew stale membership. |
c490a46a | 617 | */ |
00be9182 | 618 | public function testStaleMembership() { |
92915c55 | 619 | $statusId = 3; |
e4649817 | 620 | $contactId = $this->individualCreate(); |
92915c55 TO |
621 | $joinDate = $startDate = date("Ymd", strtotime(date("Ymd") . " -1 year -15 days")); |
622 | $endDate = date("Ymd", strtotime($joinDate . " +1 year -1 day")); | |
9099cab3 | 623 | $params = [ |
6a488035 TO |
624 | 'contact_id' => $contactId, |
625 | 'membership_type_id' => $this->_membershipTypeID, | |
626 | 'join_date' => $joinDate, | |
627 | 'start_date' => $startDate, | |
628 | 'end_date' => $endDate, | |
629 | 'source' => 'Payment', | |
630 | 'status_id' => $statusId, | |
9099cab3 | 631 | ]; |
6a488035 | 632 | |
9099cab3 | 633 | $ids = []; |
6a488035 TO |
634 | $membership = CRM_Member_BAO_Membership::create($params, $ids); |
635 | ||
636 | $membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id', | |
637 | 'contact_id', 'Database check for created membership.' | |
638 | ); | |
639 | ||
640 | $this->assertEquals($membership->status_id, $statusId, 'Verify correct status id is calculated.'); | |
641 | $this->assertEquals($membership->membership_type_id, $this->_membershipTypeID, | |
642 | 'Verify correct membership type id.' | |
643 | ); | |
644 | ||
645 | //verify all dates. | |
9099cab3 | 646 | $dates = [ |
6a488035 TO |
647 | 'startDate' => 'start_date', |
648 | 'joinDate' => 'join_date', | |
649 | 'endDate' => 'end_date', | |
9099cab3 | 650 | ]; |
6a488035 TO |
651 | |
652 | foreach ($dates as $date => $dbDate) { | |
653 | $this->assertEquals($membership->$dbDate, $$date, | |
654 | "Verify correct {$date} is present." | |
655 | ); | |
656 | } | |
657 | ||
658 | $this->assertDBNotNull('CRM_Member_BAO_MembershipLog', | |
659 | $membership->id, | |
660 | 'id', | |
661 | 'membership_id', | |
662 | 'Database checked on membershiplog record.' | |
663 | ); | |
664 | ||
665 | // this is a test and we dont want qfKey generation / validation | |
666 | // easier to suppress it, than change core code | |
667 | $config = CRM_Core_Config::singleton(); | |
668 | $config->keyDisable = TRUE; | |
669 | ||
ae5ffbb7 TO |
670 | $membershipRenewal = new CRM_Core_Form(); |
671 | $membershipRenewal->controller = new CRM_Core_Controller(); | |
356bfcaf | 672 | list($MembershipRenew) = CRM_Member_BAO_Membership::processMembership( |
595f9e7c EM |
673 | $contactId, |
674 | $this->_membershipTypeID, | |
61767a1d | 675 | FALSE, |
595f9e7c EM |
676 | $membershipRenewal, |
677 | NULL, | |
678 | NULL, | |
679 | NULL, | |
680 | 1, | |
681 | NULL, | |
66e83bf5 | 682 | NULL, |
683 | NULL, | |
684 | FALSE, | |
685 | NULL | |
686 | ); | |
6a488035 TO |
687 | |
688 | $this->assertDBNotNull('CRM_Member_BAO_MembershipLog', | |
689 | $MembershipRenew->id, | |
690 | 'id', | |
691 | 'membership_id', | |
692 | 'Database checked on membershiplog record.' | |
693 | ); | |
694 | ||
695 | $this->membershipDelete($membershipId); | |
93ac19cd | 696 | $this->contactDelete($contactId); |
6a488035 | 697 | } |
96025800 | 698 | |
e136f704 | 699 | public function testUpdateAllMembershipStatusConvertExpiredOverriddenStatusToNormal() { |
9099cab3 | 700 | $params = [ |
e136f704 O |
701 | 'contact_id' => $this->individualCreate(), |
702 | 'membership_type_id' => $this->_membershipTypeID, | |
703 | 'join_date' => date('Ymd', time()), | |
704 | 'start_date' => date('Ymd', time()), | |
705 | 'end_date' => date('Ymd', strtotime('+1 year')), | |
706 | 'source' => 'Payment', | |
707 | 'is_override' => 1, | |
708 | 'status_override_end_date' => date('Ymd', strtotime('-1 day')), | |
709 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
710 | ]; |
711 | $ids = []; | |
e136f704 O |
712 | $createdMembership = CRM_Member_BAO_Membership::create($params, $ids); |
713 | ||
714 | CRM_Member_BAO_Membership::updateAllMembershipStatus(); | |
715 | ||
9099cab3 | 716 | $membershipAfterProcess = civicrm_api3('Membership', 'get', [ |
e136f704 O |
717 | 'sequential' => 1, |
718 | 'id' => $createdMembership->id, | |
9099cab3 CW |
719 | 'return' => ['id', 'is_override', 'status_override_end_date'], |
720 | ])['values'][0]; | |
e136f704 O |
721 | |
722 | $this->assertEquals($createdMembership->id, $membershipAfterProcess['id']); | |
723 | $this->assertArrayNotHasKey('is_override', $membershipAfterProcess); | |
724 | $this->assertArrayNotHasKey('status_override_end_date', $membershipAfterProcess); | |
725 | } | |
726 | ||
727 | public function testUpdateAllMembershipStatusHandleOverriddenWithEndOverrideDateEqualTodayAsExpired() { | |
9099cab3 | 728 | $params = [ |
e136f704 O |
729 | 'contact_id' => $this->individualCreate(), |
730 | 'membership_type_id' => $this->_membershipTypeID, | |
731 | 'join_date' => date('Ymd', time()), | |
732 | 'start_date' => date('Ymd', time()), | |
733 | 'end_date' => date('Ymd', strtotime('+1 year')), | |
734 | 'source' => 'Payment', | |
735 | 'is_override' => 1, | |
736 | 'status_override_end_date' => date('Ymd', time()), | |
737 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
738 | ]; |
739 | $ids = []; | |
e136f704 O |
740 | $createdMembership = CRM_Member_BAO_Membership::create($params, $ids); |
741 | ||
742 | CRM_Member_BAO_Membership::updateAllMembershipStatus(); | |
743 | ||
9099cab3 | 744 | $membershipAfterProcess = civicrm_api3('Membership', 'get', [ |
e136f704 O |
745 | 'sequential' => 1, |
746 | 'id' => $createdMembership->id, | |
9099cab3 CW |
747 | 'return' => ['id', 'is_override', 'status_override_end_date'], |
748 | ])['values'][0]; | |
e136f704 O |
749 | |
750 | $this->assertEquals($createdMembership->id, $membershipAfterProcess['id']); | |
751 | $this->assertArrayNotHasKey('is_override', $membershipAfterProcess); | |
752 | $this->assertArrayNotHasKey('status_override_end_date', $membershipAfterProcess); | |
753 | } | |
754 | ||
755 | public function testUpdateAllMembershipStatusDoesNotConvertOverridenMembershipWithoutEndOverrideDateToNormal() { | |
9099cab3 | 756 | $params = [ |
e136f704 O |
757 | 'contact_id' => $this->individualCreate(), |
758 | 'membership_type_id' => $this->_membershipTypeID, | |
759 | 'join_date' => date('Ymd', time()), | |
760 | 'start_date' => date('Ymd', time()), | |
761 | 'end_date' => date('Ymd', strtotime('+1 year')), | |
762 | 'source' => 'Payment', | |
763 | 'is_override' => 1, | |
764 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 CW |
765 | ]; |
766 | $ids = []; | |
e136f704 O |
767 | $createdMembership = CRM_Member_BAO_Membership::create($params, $ids); |
768 | ||
769 | CRM_Member_BAO_Membership::updateAllMembershipStatus(); | |
770 | ||
9099cab3 | 771 | $membershipAfterProcess = civicrm_api3('Membership', 'get', [ |
e136f704 O |
772 | 'sequential' => 1, |
773 | 'id' => $createdMembership->id, | |
9099cab3 CW |
774 | 'return' => ['id', 'is_override', 'status_override_end_date'], |
775 | ])['values'][0]; | |
e136f704 O |
776 | |
777 | $this->assertEquals($createdMembership->id, $membershipAfterProcess['id']); | |
778 | $this->assertEquals(1, $membershipAfterProcess['is_override']); | |
779 | } | |
780 | ||
a9f44ffb | 781 | /** |
782 | * @throws \CRM_Core_Exception | |
783 | */ | |
784 | public function testMembershipPaymentForSingleContributionMultipleMembership() { | |
785 | $membershipTypeID1 = $this->membershipTypeCreate(['name' => 'Parent']); | |
786 | $membershipTypeID2 = $this->membershipTypeCreate(['name' => 'Child']); | |
787 | $financialTypeId = $this->getFinancialTypeId('Member Dues'); | |
788 | $priceSet = $this->callAPISuccess('price_set', 'create', [ | |
789 | 'is_quick_config' => 0, | |
790 | 'extends' => 'CiviMember', | |
791 | 'financial_type_id' => $financialTypeId, | |
792 | 'title' => 'Family Membership', | |
793 | ]); | |
794 | $priceSetID = $priceSet['id']; | |
795 | $priceField = $this->callAPISuccess('price_field', 'create', [ | |
796 | 'price_set_id' => $priceSetID, | |
797 | 'label' => 'Memberships', | |
798 | 'html_type' => 'Radio', | |
799 | ]); | |
800 | $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ | |
801 | 'price_set_id' => $priceSetID, | |
802 | 'price_field_id' => $priceField['id'], | |
803 | 'label' => 'Parent', | |
804 | 'amount' => 100, | |
805 | 'financial_type_id' => $financialTypeId, | |
806 | 'membership_type_id' => $membershipTypeID1, | |
807 | 'membership_num_terms' => 1, | |
808 | ]); | |
809 | $priceFieldValueId = [1 => $priceFieldValue['id']]; | |
810 | $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [ | |
811 | 'price_set_id' => $priceSetID, | |
812 | 'price_field_id' => $priceField['id'], | |
813 | 'label' => 'Child', | |
814 | 'amount' => 50, | |
815 | 'financial_type_id' => $financialTypeId, | |
816 | 'membership_type_id' => $membershipTypeID2, | |
817 | 'membership_num_terms' => 1, | |
818 | ]); | |
819 | $priceFieldValueId[2] = $priceFieldValue['id']; | |
820 | $parentContactId = $this->individualCreate(); | |
821 | $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', [ | |
822 | 'contact_id' => $parentContactId, | |
823 | 'amount' => 200, | |
824 | 'frequency_unit' => 'day', | |
825 | 'frequency_interval' => 1, | |
826 | 'installments' => 2, | |
827 | 'start_date' => 'yesterday', | |
828 | 'create_date' => 'yesterday', | |
829 | 'modified_date' => 'yesterday', | |
830 | 'cancel_date' => NULL, | |
831 | 'end_date' => '+ 2 weeks', | |
832 | 'processor_id' => '643411460836', | |
833 | 'trxn_id' => 'e0d0808e26f3e661c6c18eb7c039d363', | |
834 | 'invoice_id' => 'e0d0808e26f3e661c6c18eb7c039d363', | |
835 | 'contribution_status_id' => 'In Progress', | |
836 | 'cycle_day' => 1, | |
837 | 'next_sched_contribution_date' => '+ 1 week', | |
838 | 'auto_renew' => 0, | |
839 | 'currency' => 'USD', | |
840 | 'payment_processor_id' => $this->paymentProcessorCreate(), | |
841 | 'financial_type_id' => $financialTypeId, | |
842 | 'payment_instrument_id' => 'Credit Card', | |
843 | ]); | |
844 | $contribution = $this->callAPISuccess('contribution', 'create', [ | |
845 | 'total_amount' => 200, | |
846 | 'contribution_recur_id' => $contributionRecur['id'], | |
847 | 'currency' => 'USD', | |
848 | 'contact_id' => $parentContactId, | |
849 | 'financial_type_id' => $financialTypeId, | |
850 | 'contribution_status_id' => 'Completed', | |
851 | 'skipLineItem' => TRUE, | |
852 | 'is_recur' => TRUE, | |
853 | ]); | |
854 | $params[] = [ | |
855 | 'contact_id' => $parentContactId, | |
856 | 'membership_type_id' => $membershipTypeID1, | |
857 | 'contribution_recur_id' => $contributionRecur['id'], | |
858 | 'join_date' => date('Ymd', time()), | |
859 | 'start_date' => date('Ymd', time()), | |
860 | 'end_date' => date('Ymd', strtotime('+1 year')), | |
861 | 'skipLineItem' => TRUE, | |
862 | 'source' => 'Payment', | |
863 | 'line_items' => [ | |
864 | 'price_field_id' => $priceField['id'], | |
865 | 'price_field_value_id' => $priceFieldValueId[1], | |
866 | 'label' => 'Parent', | |
867 | 'contribution_id' => $contribution['id'], | |
868 | 'membership_type_id' => $membershipTypeID1, | |
869 | 'qty' => 1, | |
870 | 'unit_price' => 100, | |
871 | 'line_total' => 100, | |
872 | 'financial_type_id' => $financialTypeId, | |
873 | 'entity_table' => 'civicrm_membership', | |
874 | ], | |
875 | ]; | |
876 | $params[] = [ | |
877 | 'contact_id' => $this->individualCreate(), | |
878 | 'membership_type_id' => $membershipTypeID2, | |
879 | 'contribution_recur_id' => $contributionRecur['id'], | |
880 | 'join_date' => date('Ymd', time()), | |
881 | 'start_date' => date('Ymd', time()), | |
882 | 'end_date' => date('Ymd', strtotime('+1 year')), | |
883 | 'skipLineItem' => TRUE, | |
884 | 'source' => 'Payment', | |
885 | 'line_items' => [ | |
886 | 'price_field_id' => $priceField['id'], | |
887 | 'price_field_value_id' => $priceFieldValueId[2], | |
888 | 'label' => 'Child', | |
889 | 'contribution_id' => $contribution['id'], | |
890 | 'qty' => 1, | |
891 | 'unit_price' => 50, | |
892 | 'line_total' => 50, | |
893 | 'membership_type_id' => $membershipTypeID2, | |
894 | 'financial_type_id' => $financialTypeId, | |
895 | 'entity_table' => 'civicrm_membership', | |
896 | ], | |
897 | ]; | |
898 | $params[] = [ | |
899 | 'contact_id' => $this->individualCreate(), | |
900 | 'membership_type_id' => $membershipTypeID2, | |
901 | 'contribution_recur_id' => $contributionRecur['id'], | |
902 | 'join_date' => date('Ymd', time()), | |
903 | 'start_date' => date('Ymd', time()), | |
904 | 'skipLineItem' => TRUE, | |
905 | 'end_date' => date('Ymd', strtotime('+1 year')), | |
906 | 'source' => 'Payment', | |
907 | 'line_items' => [ | |
908 | 'price_field_id' => $priceField['id'], | |
909 | 'price_field_value_id' => $priceFieldValueId[2], | |
910 | 'label' => 'Child', | |
911 | 'contribution_id' => $contribution['id'], | |
912 | 'qty' => 1, | |
913 | 'membership_type_id' => $membershipTypeID2, | |
914 | 'unit_price' => 50, | |
915 | 'line_total' => 50, | |
916 | 'financial_type_id' => $financialTypeId, | |
917 | 'entity_table' => 'civicrm_membership', | |
918 | ], | |
919 | ]; | |
920 | ||
921 | foreach ($params as $key => $param) { | |
922 | $membership = $this->callAPISuccess('membership', 'create', $param); | |
923 | $param['line_items']['entity_id'] = $membership['id']; | |
924 | $memPayments = new CRM_Member_BAO_MembershipPayment(); | |
925 | $paymentParams = [ | |
926 | 'membership_id' => $membership['id'], | |
927 | 'contribution_id' => $contribution['id'], | |
928 | ]; | |
929 | $memPayments->copyValues($paymentParams); | |
930 | $memPayments->save(); | |
931 | $lineItemBAO = new CRM_Price_BAO_LineItem(); | |
932 | $lineItemBAO->copyValues($param['line_items']); | |
933 | $lineItemBAO->save(); | |
934 | } | |
935 | $this->callAPISuccess('contribution', 'repeattransaction', [ | |
936 | 'original_contribution_id' => $contribution['id'], | |
937 | 'contribution_status_id' => 'Completed', | |
938 | 'trxn_id' => uniqid(), | |
939 | ]); | |
940 | $this->callAPISuccessGetCount('Contribution', [], 2); | |
941 | $this->callAPISuccessGetCount('LineItem', [], 6); | |
942 | $this->membershipTypeDelete(['id' => $membershipTypeID1]); | |
943 | $this->membershipTypeDelete(['id' => $membershipTypeID2]); | |
944 | } | |
945 | ||
6a488035 | 946 | } |