Update Unit test styling to cover the future coder version
[civicrm-core.git] / tests / phpunit / api / v3 / MembershipTest.php
CommitLineData
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
TO
27
28/**
29 * Test APIv3 civicrm_membership functions
30 *
6c6e6187
TO
31 * @package CiviCRM_APIv3
32 * @subpackage API_Member
6a488035
TO
33 */
34
4cbe18b8
EM
35/**
36 * Class api_v3_MembershipTest
acb109b7 37 * @group headless
4cbe18b8 38 */
6a488035
TO
39class api_v3_MembershipTest extends CiviUnitTestCase {
40 protected $_apiversion;
41 protected $_contactID;
d54576ed
EM
42 protected $_membershipID;
43 protected $_membershipID2;
44 protected $_membershipID3;
6a488035 45 protected $_membershipTypeID;
8c33a68c 46 protected $_membershipTypeID2;
6a488035 47 protected $_membershipStatusID;
6a488035
TO
48 protected $_entity;
49 protected $_params;
b7c9bc4c 50
80d714d2 51 /**
52 * Set up for tests.
53 */
6a488035 54 public function setUp() {
6a488035
TO
55 parent::setUp();
56 $this->_apiversion = 3;
57 $this->_contactID = $this->individualCreate();
75638074 58 $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID));
5896d037
TO
59 $this->_membershipTypeID2 = $this->membershipTypeCreate(array(
60 'period_type' => 'fixed',
2ea0abec 61 // Ie. 1 March.
5896d037 62 'fixed_period_start_day' => '301',
2ea0abec 63 // Ie. 11 Nov.
21dfd5f5 64 'fixed_period_rollover_day' => '1111',
5d8b37be 65 'name' => 'Another one',
5896d037 66 ));
6a488035
TO
67 $this->_membershipStatusID = $this->membershipStatusCreate('test status');
68
6a488035
TO
69 CRM_Member_PseudoConstant::membershipType(NULL, TRUE);
70 CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE);
71 CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name');
72
73 $this->_entity = 'Membership';
74 $this->_params = array(
75 'contact_id' => $this->_contactID,
76 'membership_type_id' => $this->_membershipTypeID,
77 'join_date' => '2009-01-21',
78 'start_date' => '2009-01-21',
79 'end_date' => '2009-12-21',
80 'source' => 'Payment',
81 'is_override' => 1,
82 'status_id' => $this->_membershipStatusID,
6a488035
TO
83 );
84 }
85
80d714d2 86 /**
87 * Clean up after tests.
88 *
89 * @throws \Exception
90 */
00be9182 91 public function tearDown() {
6a488035 92 $this->quickCleanup(array(
39b959db
SL
93 'civicrm_membership',
94 'civicrm_membership_payment',
95 'civicrm_membership_log',
96 'civicrm_uf_match',
97 ),
771f3245 98 TRUE
6a488035
TO
99 );
100 $this->membershipStatusDelete($this->_membershipStatusID);
8c33a68c 101 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID2));
6a488035
TO
102 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
103 $this->contactDelete($this->_contactID);
104
105 }
106
107 /**
2ea0abec 108 * Test membership deletion.
6a488035 109 */
00be9182 110 public function testMembershipDelete() {
6a488035 111 $membershipID = $this->contactMembershipCreate($this->_params);
3506b6cd 112 $this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID);
6a488035 113 $params = array(
21dfd5f5 114 'id' => $membershipID,
6a488035 115 );
d54576ed 116 $this->callAPIAndDocument('membership', 'delete', $params, __FUNCTION__, __FILE__);
3506b6cd 117 $this->assertDBRowNotExist('CRM_Member_DAO_Membership', $membershipID);
6a488035
TO
118 }
119
00be9182 120 public function testMembershipDeleteEmpty() {
d54576ed 121 $this->callAPIFailure('membership', 'delete', array());
6a488035
TO
122 }
123
00be9182 124 public function testMembershipDeleteInvalidID() {
d54576ed 125 $this->callAPIFailure('membership', 'delete', array('id' => 'blah'));
6a488035
TO
126 }
127
128 /**
2ea0abec 129 * Test civicrm_membership_delete() with invalid Membership Id.
6a488035 130 */
00be9182 131 public function testMembershipDeleteWithInvalidMembershipId() {
6a488035 132 $membershipId = 'membership';
d54576ed 133 $this->callAPIFailure('membership', 'delete', $membershipId);
6a488035
TO
134 }
135
ed4cc29d
JT
136 /**
137 * Test membership deletion and with the preserve contribution param.
138 */
139 public function testMembershipDeletePreserveContribution() {
39b959db
SL
140 //DELETE
141 $membershipID = $this->contactMembershipCreate($this->_params);
142 //DELETE
143 $this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID);
ed4cc29d
JT
144 $ContributionCreate = $this->callAPISuccess('Contribution', 'create', array(
145 'sequential' => 1,
146 'financial_type_id' => "Member Dues",
147 'total_amount' => 100,
148 'contact_id' => $this->_params['contact_id'],
149 ));
150 $membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', array(
151 'sequential' => 1,
152 'contribution_id' => $ContributionCreate['values'][0]['id'],
153 'membership_id' => $membershipID,
154 ));
155 $memParams = array(
156 'id' => $membershipID,
157 'preserve_contribution' => 1,
158 );
159 $contribParams = array(
160 'id' => $ContributionCreate['values'][0]['id'],
161 );
162 $this->callAPIAndDocument('membership', 'delete', $memParams, __FUNCTION__, __FILE__);
163 $this->assertDBRowNotExist('CRM_Member_DAO_Membership', $membershipID);
164 $this->assertDBRowExist('CRM_Contribute_DAO_Contribution', $ContributionCreate['values'][0]['id']);
165 $this->callAPISuccess('Contribution', 'delete', $contribParams);
166 $this->assertDBRowNotExist('CRM_Contribute_DAO_Contribution', $ContributionCreate['values'][0]['id']);
167 }
168
c277e79e
JP
169 /**
170 * Test Activity creation on cancellation of membership contribution.
171 */
172 public function testActivityForCancelledContribution() {
173 $contactId = $this->createLoggedInUser();
174 $membershipID = $this->contactMembershipCreate($this->_params);
175 $this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID);
176
177 $ContributionCreate = $this->callAPISuccess('Contribution', 'create', array(
178 'financial_type_id' => "Member Dues",
179 'total_amount' => 100,
180 'contact_id' => $this->_params['contact_id'],
181 ));
182 $membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', array(
183 'sequential' => 1,
184 'contribution_id' => $ContributionCreate['id'],
185 'membership_id' => $membershipID,
186 ));
187 $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
188 $this->paymentInstruments = $instruments['values'];
189
190 $form = new CRM_Contribute_Form_Contribution();
191 $form->_id = $ContributionCreate['id'];
192 $form->testSubmit(array(
193 'total_amount' => 100,
194 'financial_type_id' => 1,
c277e79e
JP
195 'contact_id' => $contactId,
196 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
197 'contribution_status_id' => 3,
198 ),
199 CRM_Core_Action::UPDATE);
200
201 $activity = $this->callAPISuccess('Activity', 'get', array(
202 'activity_type_id' => "Change Membership Status",
203 'source_record_id' => $membershipID,
204 ));
205 $this->assertNotEmpty($activity['values']);
206 }
207
6a488035 208 /**
2ea0abec 209 * Test membership get.
6a488035 210 */
00be9182 211 public function testContactMembershipsGet() {
6a488035 212 $this->_membershipID = $this->contactMembershipCreate($this->_params);
2ea0abec 213 $this->callAPISuccess('membership', 'get', array());
6c6e6187 214 $this->callAPISuccess('Membership', 'Delete', array('id' => $this->_membershipID));
6a488035
TO
215 }
216
217 /**
218 * Test civicrm_membership_get with params not array.
2ea0abec 219 *
6a488035
TO
220 * Gets treated as contact_id, memberships expected.
221 */
00be9182 222 public function testGetWithParamsContactId() {
6a488035
TO
223 $this->_membershipID = $this->contactMembershipCreate($this->_params);
224 $params = array(
225 'contact_id' => $this->_contactID,
6a488035 226 );
771f3245 227 $membership = $this->callAPISuccess('membership', 'get', $params);
6a488035
TO
228
229 $result = $membership['values'][$this->_membershipID];
771f3245 230 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 231 'id' => $this->_membershipID,
5896d037 232 ));
6a488035
TO
233 $this->assertEquals($result['contact_id'], $this->_contactID, "In line " . __LINE__);
234 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID, "In line " . __LINE__);
235 $this->assertEquals($result['status_id'], $this->_membershipStatusID, "In line " . __LINE__);
236 $this->assertEquals($result['join_date'], '2009-01-21', "In line " . __LINE__);
237 $this->assertEquals($result['start_date'], '2009-01-21', "In line " . __LINE__);
238 $this->assertEquals($result['end_date'], '2009-12-21', "In line " . __LINE__);
239 $this->assertEquals($result['source'], 'Payment', "In line " . __LINE__);
240 $this->assertEquals($result['is_override'], 1, "In line " . __LINE__);
241 }
242
b4529041 243 /**
244 * Test civicrm_membership_get with params not array.
2ea0abec 245 *
b4529041 246 * Gets treated as contact_id, memberships expected.
247 */
00be9182 248 public function testGetInSyntax() {
b4529041 249 $this->_membershipID = $this->contactMembershipCreate($this->_params);
250 $this->_membershipID2 = $this->contactMembershipCreate($this->_params);
251 $this->_membershipID3 = $this->contactMembershipCreate($this->_params);
252 $params = array(
253 'id' => array('IN' => array($this->_membershipID, $this->_membershipID3)),
254 );
255 $membership = $this->callAPISuccess('membership', 'get', $params);
256 $this->assertEquals(2, $membership['count']);
257 $this->assertEquals(array($this->_membershipID, $this->_membershipID3), array_keys($membership['values']));
258 $params = array(
259 'id' => array('NOT IN' => array($this->_membershipID, $this->_membershipID3)),
260 );
261 $membership = $this->callAPISuccess('membership', 'get', $params);
262 $this->assertEquals(1, $membership['count']);
263 $this->assertEquals(array($this->_membershipID2), array_keys($membership['values']));
b4529041 264 }
265
caca32ba 266 /**
267 * Test civicrm_membership_get with params not array.
268 * Gets treated as contact_id, memberships expected.
269 */
00be9182 270 public function testGetInSyntaxOnContactID() {
caca32ba 271 $this->_membershipID = $this->contactMembershipCreate($this->_params);
272 $contact2 = $this->individualCreate();
273 $contact3 = $this->individualCreate(array('first_name' => 'Scout', 'last_name' => 'Canine'));
274 $this->_membershipID2 = $this->contactMembershipCreate(array_merge($this->_params, array('contact_id' => $contact2)));
275 $this->_membershipID3 = $this->contactMembershipCreate(array_merge($this->_params, array('contact_id' => $contact3)));
276 $params = array(
277 'contact_id' => array('IN' => array($this->_contactID, $contact3)),
278 );
279 $membership = $this->callAPISuccess('membership', 'get', $params);
280 $this->assertEquals(2, $membership['count']);
281 $this->assertEquals(array($this->_membershipID, $this->_membershipID3), array_keys($membership['values']));
282 $params = array(
283 'contact_id' => array('NOT IN' => array($this->_contactID, $contact3)),
284 );
285 $membership = $this->callAPISuccess('membership', 'get', $params);
286 $this->assertEquals(1, $membership['count']);
287 $this->assertEquals(array($this->_membershipID2), array_keys($membership['values']));
288 }
5896d037 289
caca32ba 290 /**
291 * Test civicrm_membership_get with params not array.
80d714d2 292 *
caca32ba 293 * Gets treated as contact_id, memberships expected.
294 */
00be9182 295 public function testGetWithParamsMemberShipTypeId() {
d54576ed 296 $this->callAPISuccess($this->_entity, 'create', $this->_params);
6a488035
TO
297 $params = array(
298 'membership_type_id' => $this->_membershipTypeID,
6a488035 299 );
771f3245 300 $membership = $this->callAPISuccess('membership', 'get', $params);
d54576ed 301 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 302 'id' => $membership['id'],
771f3245 303 ));
6a488035 304 $result = $membership['values'][$membership['id']];
80d714d2 305 $this->assertEquals($result['contact_id'], $this->_contactID);
306 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID);
307 $this->assertEquals($result['status_id'], $this->_membershipStatusID);
308 $this->assertEquals($result['join_date'], '2009-01-21');
309 $this->assertEquals($result['start_date'], '2009-01-21');
310 $this->assertEquals($result['end_date'], '2009-12-21');
311 $this->assertEquals($result['source'], 'Payment');
312 $this->assertEquals($result['is_override'], 1);
6a488035
TO
313 $this->assertEquals($result['id'], $membership['id']);
314 }
5896d037 315
a73daeff
E
316 /**
317 * Test civicrm_membership_get with params not array.
318 * Gets treated as contact_id, memberships expected.
319 */
00be9182 320 public function testGetWithParamsMemberShipTypeIdContactID() {
a73daeff
E
321 $params = $this->_params;
322 $this->callAPISuccess($this->_entity, 'create', $params);
323 $params['membership_type_id'] = $this->_membershipTypeID2;
324 $this->callAPISuccess($this->_entity, 'create', $params);
325 $this->callAPISuccessGetCount('membership', array('contact_id' => $this->_contactID), 2);
326 $params = array(
327 'membership_type_id' => $this->_membershipTypeID,
328 'contact_id' => $this->_contactID,
329 );
330 $result = $this->callAPISuccess('membership', 'getsingle', $params);
331 $this->assertEquals($result['contact_id'], $this->_contactID);
332 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID);
6a488035 333
a73daeff
E
334 $params = array(
335 'membership_type_id' => $this->_membershipTypeID2,
336 'contact_id' => $this->_contactID,
337 );
338 $result = $this->callAPISuccess('membership', 'getsingle', $params);
339 $this->assertEquals($result['contact_id'], $this->_contactID);
340 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID2);
341 }
5896d037 342
6a488035 343 /**
80d714d2 344 * Check with complete array + custom field.
345 *
6a488035
TO
346 * Note that the test is written on purpose without any
347 * variables specific to participant so it can be replicated into other entities
348 * and / or moved to the automated test suite
349 */
00be9182 350 public function testGetWithParamsMemberShipIdAndCustom() {
6a488035
TO
351 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
352
353 $params = $this->_params;
354 $params['custom_' . $ids['custom_field_id']] = "custom string";
355
771f3245 356 $result = $this->callAPISuccess($this->_entity, 'create', $params);
6a488035 357
771f3245 358 $getParams = array('membership_type_id' => $params['membership_type_id']);
359 $check = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
6a488035
TO
360 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
361
d54576ed 362 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 363 'id' => $result['id'],
771f3245 364 ));
6a488035
TO
365 }
366
367 /**
368 * Test civicrm_membership_get with proper params.
369 * Memberships expected.
370 */
00be9182 371 public function testGet() {
6a488035
TO
372 $membershipID = $this->contactMembershipCreate($this->_params);
373 $params = array(
374 'contact_id' => $this->_contactID,
6a488035
TO
375 );
376
771f3245 377 $membership = $this->callAPISuccess('membership', 'get', $params);
6a488035 378 $result = $membership['values'][$membershipID];
771f3245 379 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 380 'id' => $membership['id'],
771f3245 381 ));
80d714d2 382 $this->assertEquals($result['join_date'], '2009-01-21');
383 $this->assertEquals($result['contact_id'], $this->_contactID);
384 $this->assertEquals($result['membership_type_id'], $this->_membershipTypeID);
385 $this->assertEquals($result['status_id'], $this->_membershipStatusID);
6a488035 386
80d714d2 387 $this->assertEquals($result['start_date'], '2009-01-21');
388 $this->assertEquals($result['end_date'], '2009-12-21');
389 $this->assertEquals($result['source'], 'Payment');
390 $this->assertEquals($result['is_override'], 1);
6a488035
TO
391 }
392
6a488035
TO
393 /**
394 * Test civicrm_membership_get with proper params.
395 * Memberships expected.
396 */
00be9182 397 public function testGetWithId() {
6a488035
TO
398 $membershipID = $this->contactMembershipCreate($this->_params);
399 $params = array(
400 'contact_id' => $this->_contactID,
d54576ed 401 'id' => $this->_membershipID,
6a488035
TO
402 'return' => 'id',
403 );
771f3245 404 $result = $this->callAPISuccess('membership', 'get', $params);
6a488035
TO
405 $this->assertEquals($membershipID, $result['id']);
406 $params = array(
407 'contact_id' => $this->_contactID,
d54576ed 408 'membership_id' => $this->_membershipID,
6a488035
TO
409 'return' => 'membership_id',
410 );
771f3245 411 $result = $this->callAPISuccess('membership', 'get', $params);
6a488035 412 $this->assertEquals($membershipID, $result['id']);
6a488035
TO
413 }
414
415 /**
416 * Test civicrm_membership_get for only active.
417 * Memberships expected.
418 */
00be9182 419 public function testGetOnlyActive() {
5c49fee0 420 $description = "Demonstrates use of 'filter' active_only' param.";
6a488035 421 $this->_membershipID = $this->contactMembershipCreate($this->_params);
5896d037 422 $params = array(
6a488035
TO
423 'contact_id' => $this->_contactID,
424 'active_only' => 1,
6a488035
TO
425 );
426
771f3245 427 $membership = $this->callAPISuccess('membership', 'get', $params);
a73daeff
E
428 $this->assertEquals($membership['values'][$this->_membershipID]['status_id'], $this->_membershipStatusID);
429 $this->assertEquals($membership['values'][$this->_membershipID]['contact_id'], $this->_contactID);
6a488035
TO
430 $params = array(
431 'contact_id' => $this->_contactID,
432 'filters' => array(
433 'is_current' => 1,
434 ),
6a488035
TO
435 );
436
a828d7b8 437 $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__, __FILE__, $description, 'FilterIsCurrent');
a73daeff
E
438 $this->assertEquals($membership['values'][$this->_membershipID]['status_id'], $this->_membershipStatusID);
439 $this->assertEquals($membership['values'][$this->_membershipID]['contact_id'], $this->_contactID);
6a488035 440
6c6e6187 441 $this->callAPISuccess('Membership', 'Delete', array('id' => $this->_membershipID));
6a488035
TO
442 }
443
444 /**
445 * Test civicrm_membership_get for non exist contact.
446 * empty Memberships.
447 */
00be9182 448 public function testGetNoContactExists() {
6a488035
TO
449 $params = array(
450 'contact_id' => 55555,
6a488035
TO
451 );
452
771f3245 453 $membership = $this->callAPISuccess('membership', 'get', $params);
80d714d2 454 $this->assertEquals($membership['count'], 0);
6a488035
TO
455 }
456
457 /**
458 * Test civicrm_membership_get with relationship.
459 * get Memberships.
460 */
00be9182 461 public function testGetWithRelationship() {
6a488035 462 $membershipOrgId = $this->organizationCreate(NULL);
e4d5f1e2 463 $memberContactId = $this->individualCreate();
6a488035
TO
464
465 $relTypeParams = array(
466 'name_a_b' => 'Relation 1',
467 'name_b_a' => 'Relation 2',
468 'description' => 'Testing relationship type',
469 'contact_type_a' => 'Organization',
470 'contact_type_b' => 'Individual',
471 'is_reserved' => 1,
472 'is_active' => 1,
6a488035
TO
473 );
474 $relTypeID = $this->relationshipTypeCreate($relTypeParams);
475
476 $params = array(
477 'name' => 'test General',
478 'duration_unit' => 'year',
479 'duration_interval' => 1,
480 'period_type' => 'rolling',
481 'member_of_contact_id' => $membershipOrgId,
482 'domain_id' => 1,
5896d037 483 'financial_type_id' => 1,
6a488035
TO
484 'relationship_type_id' => $relTypeID,
485 'relationship_direction' => 'b_a',
486 'is_active' => 1,
6a488035 487 );
771f3245 488 $memType = $this->callAPISuccess('membership_type', 'create', $params);
6a488035
TO
489
490 $params = array(
491 'contact_id' => $memberContactId,
492 'membership_type_id' => $memType['id'],
493 'join_date' => '2009-01-21',
494 'start_date' => '2009-01-21',
495 'end_date' => '2009-12-21',
496 'source' => 'Payment',
497 'is_override' => 1,
498 'status_id' => $this->_membershipStatusID,
6a488035
TO
499 );
500 $membershipID = $this->contactMembershipCreate($params);
501
502 $params = array(
503 'contact_id' => $memberContactId,
504 'membership_type_id' => $memType['id'],
6a488035
TO
505 );
506
771f3245 507 $result = $this->callAPISuccess('membership', 'get', $params);
6a488035
TO
508
509 $membership = $result['values'][$membershipID];
771f3245 510 $this->assertEquals($this->_membershipStatusID, $membership['status_id']);
d54576ed 511 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 512 'id' => $membership['id'],
5896d037 513 ));
6a488035
TO
514 $this->membershipTypeDelete(array('id' => $memType['id']));
515 $this->relationshipTypeDelete($relTypeID);
516 $this->contactDelete($membershipOrgId);
517 $this->contactDelete($memberContactId);
518 }
519
4cc99d00 520 /**
521 * Test civicrm_membership_create with relationships.
522 * create/get Memberships.
523 *
524 * Test suite for CRM-14758: API ( contact, create ) does not always create related membership
525 * and max_related property for Membership_Type and Membership entities
526 */
00be9182 527 public function testCreateWithRelationship() {
4cc99d00 528 // Create membership type: inherited through employment, max_related = 2
529 $params = array(
530 'name_a_b' => 'Employee of',
531 );
532 $result = $this->callAPISuccess('relationship_type', 'get', $params);
533 $relationshipTypeId = $result['id'];
534 $membershipOrgId = $this->organizationCreate();
535 $params = array(
536 'name' => 'Corporate Membership',
537 'duration_unit' => 'year',
538 'duration_interval' => 1,
539 'period_type' => 'rolling',
540 'member_of_contact_id' => $membershipOrgId,
541 'domain_id' => 1,
542 'financial_type_id' => 1,
543 'relationship_type_id' => $relationshipTypeId,
544 'relationship_direction' => 'b_a',
545 'max_related' => 2,
546 'is_active' => 1,
547 );
548 $result = $this->callAPISuccess('membership_type', 'create', $params);
549 $membershipTypeId = $result['id'];
550
551 // Create employer and first employee
552 $employerId[0] = $this->organizationCreate(array(), 1);
553 $memberContactId[0] = $this->individualCreate(array('employer_id' => $employerId[0]), 0);
554
555 // Create organization's membership
556 $params = array(
557 'contact_id' => $employerId[0],
558 'membership_type_id' => $membershipTypeId,
559 'source' => 'Test suite',
560 'start_date' => date('Y-m-d'),
561 'end_date' => "+1 year",
562 );
563 $OrganizationMembershipID = $this->contactMembershipCreate($params);
564
565 // Check that the employee inherited the membership
566 $params = array(
567 'contact_id' => $memberContactId[0],
568 'membership_type_id' => $membershipTypeId,
569 );
570
571 $result = $this->callAPISuccess('membership', 'get', $params);
572
573 $this->assertEquals(1, $result['count']);
574 $result = $result['values'][$result['id']];
575 $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
576
577 // Create second employee
578 $memberContactId[1] = $this->individualCreate(array('employer_id' => $employerId[0]), 1);
579
580 // Check that the employee inherited the membership
581 $params = array(
582 'contact_id' => $memberContactId[1],
583 'membership_type_id' => $membershipTypeId,
584 );
585 $result = $this->callAPISuccess('membership', 'get', $params);
4cc99d00 586 // If it fails here CRM-14758 is not fixed
587 $this->assertEquals(1, $result['count']);
588 $result = $result['values'][$result['id']];
589 $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
590
591 // Create third employee
932a6904 592 $memberContactId[2] = $this->individualCreate(array('employer_id' => $employerId[0]), 2);
4cc99d00 593
594 // Check that employee does NOT inherit the membership (max_related = 2)
595 $params = array(
596 'contact_id' => $memberContactId[2],
597 'membership_type_id' => $membershipTypeId,
598 );
599 $result = $this->callAPISuccess('membership', 'get', $params);
600 $this->assertEquals(0, $result['count']);
601
602 // Increase max_related for the employer's membership
603 $params = array(
604 'id' => $OrganizationMembershipID,
605 'max_related' => 3,
606 );
5d8b37be 607 $this->callAPISuccess('Membership', 'create', $params);
4cc99d00 608
609 // Check that the employee inherited the membership
610 $params = array(
611 'contact_id' => $memberContactId[2],
612 'membership_type_id' => $membershipTypeId,
613 );
614 $result = $this->callAPISuccess('membership', 'get', $params);
615 $this->assertEquals(1, $result['count']);
616 $result = $result['values'][$result['id']];
617 $this->assertEquals($OrganizationMembershipID, $result['owner_membership_id']);
618
619 // First employee moves to a new job
620 $employerId[1] = $this->organizationCreate(array(), 2);
621 $params = array(
622 'id' => $memberContactId[0],
623 'employer_id' => $employerId[1],
624 );
625 $this->callAPISuccess('contact', 'create', $params);
626
627 // Check that employee does NO LONGER inherit the membership
628 $params = array(
629 'contact_id' => $memberContactId[0],
630 'membership_type_id' => $membershipTypeId,
631 );
632 $result = $this->callAPISuccess('membership', 'get', $params);
633 $this->assertEquals(0, $result['count']);
634
00538ec6
JP
635 //Create pay_later membership for organization.
636 $employerId[2] = $this->organizationCreate(array(), 1);
637 $params = array(
638 'contact_id' => $employerId[2],
639 'membership_type_id' => $membershipTypeId,
640 'source' => 'Test pay later suite',
641 'is_pay_later' => 1,
642 'status_id' => 5,
643 );
644 $organizationMembership = CRM_Member_BAO_Membership::add($params);
645 $organizationMembershipID = $organizationMembership->id;
646 $memberContactId[3] = $this->individualCreate(array('employer_id' => $employerId[2]), 0);
647 // Check that the employee inherited the membership
648 $params = array(
649 'contact_id' => $memberContactId[3],
650 'membership_type_id' => $membershipTypeId,
651 );
652 $result = $this->callAPISuccess('membership', 'get', $params);
653 $this->assertEquals(1, $result['count']);
654 $result = $result['values'][$result['id']];
655 $this->assertEquals($organizationMembershipID, $result['owner_membership_id']);
656
4a009ccf
CW
657 // Set up params for enable/disable checks
658 $relationship1 = $this->callAPISuccess('relationship', 'get', array('contact_id_a' => $memberContactId[1]));
659 $params = array(
660 'contact_id' => $memberContactId[1],
661 'membership_type_id' => $membershipTypeId,
662 );
663
664 // Deactivate relationship using create and assert membership is not inherited
665 $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 0));
666 $result = $this->callAPISuccess('membership', 'get', $params);
667 $this->assertEquals(0, $result['count']);
668
669 // Re-enable relationship using create and assert membership is inherited
670 $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 1));
671 $result = $this->callAPISuccess('membership', 'get', $params);
672 $this->assertEquals(1, $result['count']);
673
674 // Deactivate relationship using setvalue and assert membership is not inherited
675 $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 0));
676 $result = $this->callAPISuccess('membership', 'get', $params);
677 $this->assertEquals(0, $result['count']);
678
679 // Re-enable relationship using setvalue and assert membership is inherited
680 $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 1));
681 $result = $this->callAPISuccess('membership', 'get', $params);
682 $this->assertEquals(1, $result['count']);
683
1b5fad8a
CW
684 // Delete relationship and assert membership is not inherited
685 $this->callAPISuccess('relationship', 'delete', array('id' => $relationship1['id']));
686 $result = $this->callAPISuccess('membership', 'get', $params);
687 $this->assertEquals(0, $result['count']);
688
4cc99d00 689 // Tear down - reverse of creation to be safe
690 $this->contactDelete($memberContactId[2]);
691 $this->contactDelete($memberContactId[1]);
692 $this->contactDelete($memberContactId[0]);
693 $this->contactDelete($employerId[1]);
694 $this->contactDelete($employerId[0]);
695 $this->membershipTypeDelete(array('id' => $membershipTypeId));
696 $this->contactDelete($membershipOrgId);
697 }
698
37eda84b 699 /**
0298287b 700 * We are checking for no e-notices + only id & end_date returned
37eda84b 701 */
00be9182 702 public function testMembershipGetWithReturn() {
d54576ed 703 $this->contactMembershipCreate($this->_params);
37eda84b 704 $result = $this->callAPISuccess('membership', 'get', array('return' => 'end_date'));
6c6e6187 705 foreach ($result['values'] as $membership) {
0248c335 706 $this->assertEquals(array('id', 'end_date'), array_keys($membership));
37eda84b 707 }
708 }
39b959db 709
6a488035
TO
710 ///////////////// civicrm_membership_create methods
711
712 /**
713 * Test civicrm_contact_memberships_create with empty params.
714 * Error expected.
715 */
00be9182 716 public function testCreateWithEmptyParams() {
6a488035 717 $params = array();
d54576ed 718 $this->callAPIFailure('membership', 'create', $params);
6a488035
TO
719 }
720
721 /**
fe482240 722 * If is_overide is passed in status must also be passed in.
6a488035 723 */
00be9182 724 public function testCreateOverrideNoStatus() {
6a488035
TO
725 $params = $this->_params;
726 unset($params['status_id']);
d54576ed 727 $this->callAPIFailure('membership', 'create', $params);
6a488035
TO
728 }
729
00be9182 730 public function testMembershipCreateMissingRequired() {
6a488035
TO
731 $params = array(
732 'membership_type_id' => '1',
733 'join_date' => '2006-01-21',
734 'start_date' => '2006-01-21',
735 'end_date' => '2006-12-21',
736 'source' => 'Payment',
737 'status_id' => '2',
6a488035
TO
738 );
739
d54576ed 740 $this->callAPIFailure('membership', 'create', $params);
6a488035
TO
741 }
742
00be9182 743 public function testMembershipCreate() {
6a488035
TO
744 $params = array(
745 'contact_id' => $this->_contactID,
746 'membership_type_id' => $this->_membershipTypeID,
747 'join_date' => '2006-01-21',
748 'start_date' => '2006-01-21',
749 'end_date' => '2006-12-21',
750 'source' => 'Payment',
751 'is_override' => 1,
752 'status_id' => $this->_membershipStatusID,
6a488035
TO
753 );
754
771f3245 755 $result = $this->callAPIAndDocument('membership', 'create', $params, __FUNCTION__, __FILE__);
6a488035 756 $this->getAndCheck($params, $result['id'], $this->_entity);
6a488035
TO
757 $this->assertNotNull($result['id']);
758 $this->assertEquals($this->_contactID, $result['values'][$result['id']]['contact_id'], " in line " . __LINE__);
759 $this->assertEquals($result['id'], $result['values'][$result['id']]['id'], " in line " . __LINE__);
760 }
5896d037 761
28a04ea9 762 /**
763 * Check for useful message if contact doesn't exist
764 */
00be9182 765 public function testMembershipCreateWithInvalidContact() {
6a488035
TO
766 $params = array(
767 'contact_id' => 999,
768 'membership_type_id' => $this->_membershipTypeID,
769 'join_date' => '2006-01-21',
770 'start_date' => '2006-01-21',
771 'end_date' => '2006-12-21',
772 'source' => 'Payment',
773 'is_override' => 1,
774 'status_id' => $this->_membershipStatusID,
6a488035
TO
775 );
776
d54576ed 777 $this->callAPIFailure('membership', 'create', $params,
771f3245 778 'contact_id is not valid : 999'
779 );
6a488035 780 }
5896d037 781
00be9182 782 public function testMembershipCreateWithInvalidStatus() {
6a488035
TO
783 $params = $this->_params;
784 $params['status_id'] = 999;
d54576ed 785 $this->callAPIFailure('membership', 'create', $params,
771f3245 786 "'999' is not a valid option for field status_id"
787 );
6a488035
TO
788 }
789
00be9182 790 public function testMembershipCreateWithInvalidType() {
6a488035
TO
791 $params = $this->_params;
792 $params['membership_type_id'] = 999;
793
d54576ed 794 $this->callAPIFailure('membership', 'create', $params,
771f3245 795 "'999' is not a valid option for field membership_type_id"
796 );
6a488035
TO
797 }
798
799 /**
100fef9d 800 * Check with complete array + custom field
6a488035
TO
801 * Note that the test is written on purpose without any
802 * variables specific to participant so it can be replicated into other entities
803 * and / or moved to the automated test suite
804 */
00be9182 805 public function testCreateWithCustom() {
6a488035
TO
806 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
807
808 $params = $this->_params;
809 $params['custom_' . $ids['custom_field_id']] = "custom string";
810
a828d7b8 811 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, NULL, 'CreateWithCustomData');
5896d037
TO
812 $check = $this->callAPISuccess($this->_entity, 'get', array(
813 'id' => $result['id'],
21dfd5f5 814 'contact_id' => $this->_contactID,
5896d037 815 ));
6a488035 816 $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
6a488035
TO
817 }
818
22e97101
JV
819 /**
820 * Search on custom field value.
821 */
822 public function testSearchWithCustomDataCRM16036() {
823 // Create a custom field on membership
824 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
825
826 // Create a new membership, but don't assign anything to the custom field.
827 $params = $this->_params;
828 $result = $this->callAPIAndDocument(
829 $this->_entity,
830 'create',
831 $params,
832 __FUNCTION__,
833 __FILE__,
834 NULL,
835 'SearchWithCustomData');
836
837 // search memberships with CRM-16036 as custom field value.
838 // Since we did not touch the custom field of any membership,
839 // this should not return any results.
840 $check = $this->callAPISuccess($this->_entity, 'get', array(
841 'custom_' . $ids['custom_field_id'] => "CRM-16036",
842 ));
843
844 // Cleanup.
845 $this->callAPISuccess($this->_entity, 'delete', array(
846 'id' => $result['id'],
847 ));
848
849 // Assert.
850 $this->assertEquals(0, $check['count']);
851 }
852
6a488035
TO
853 /**
854 * Test civicrm_contact_memberships_create with membership id (edit
855 * membership).
856 * success expected.
857 */
00be9182 858 public function testMembershipCreateWithId() {
6a488035
TO
859 $membershipID = $this->contactMembershipCreate($this->_params);
860 $params = array(
861 'id' => $membershipID,
862 'contact_id' => $this->_contactID,
863 'membership_type_id' => $this->_membershipTypeID,
864 'join_date' => '2006-01-21',
865 'start_date' => '2006-01-21',
866 'end_date' => '2006-12-21',
867 'source' => 'Payment',
868 'is_override' => 1,
869 'status_id' => $this->_membershipStatusID,
6a488035
TO
870 );
871
771f3245 872 $result = $this->callAPISuccess('membership', 'create', $params);
c329a76a
JP
873
874 //Update Status and check activities created.
875 $updateStatus = array(
876 'id' => $result['id'],
1eae7f10 877 'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Cancelled'),
c329a76a
JP
878 );
879 $this->callAPISuccess('Membership', 'create', $updateStatus);
880 $activities = CRM_Activity_BAO_Activity::getContactActivity($this->_contactID);
881 $this->assertEquals(2, count($activities));
882 $activityNames = array_flip(CRM_Utils_Array::collect('activity_name', $activities));
883 $this->assertArrayHasKey('Membership Signup', $activityNames);
884 $this->assertArrayHasKey('Change Membership Status', $activityNames);
885
771f3245 886 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 887 'id' => $result['id'],
771f3245 888 ));
6a488035
TO
889 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
890 }
891
892 /**
893 * Test civicrm_contact_memberships_create with membership id (edit
894 * membership).
895 * success expected.
896 */
00be9182 897 public function testMembershipCreateUpdateWithIdNoContact() {
6a488035
TO
898 $membershipID = $this->contactMembershipCreate($this->_params);
899 $params = array(
900 'id' => $membershipID,
901 'membership_type_id' => $this->_membershipTypeID,
902 'contact_id' => $this->_contactID,
903 'join_date' => '2006-01-21',
904 'start_date' => '2006-01-21',
905 'end_date' => '2006-12-21',
906 'source' => 'Payment',
907 'is_override' => 1,
908 'status_id' => $this->_membershipStatusID,
6a488035
TO
909 );
910
771f3245 911 $result = $this->callAPISuccess('membership', 'create', $params);
912 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 913 'id' => $result['id'],
5896d037 914 ));
771f3245 915
6a488035
TO
916 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
917 }
918
919 /**
920 * Test civicrm_contact_memberships_create with membership id (edit
921 * membership).
922 * success expected.
923 */
00be9182 924 public function testMembershipCreateUpdateWithIdNoDates() {
6a488035
TO
925 $membershipID = $this->contactMembershipCreate($this->_params);
926 $params = array(
927 'id' => $membershipID,
928 'contact_id' => $this->_contactID,
929 'membership_type_id' => $this->_membershipTypeID,
930 'source' => 'Payment',
931 'is_override' => 1,
932 'status_id' => $this->_membershipStatusID,
6a488035
TO
933 );
934
771f3245 935 $result = $this->callAPISuccess('membership', 'create', $params);
936 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 937 'id' => $result['id'],
5896d037 938 ));
6a488035
TO
939 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
940 }
941
942 /**
943 * Test civicrm_contact_memberships_create with membership id (edit
944 * membership).
945 * success expected.
946 */
00be9182 947 public function testMembershipCreateUpdateWithIdNoDatesNoType() {
6a488035
TO
948 $membershipID = $this->contactMembershipCreate($this->_params);
949 $params = array(
950 'id' => $membershipID,
951 'source' => 'not much here',
952 'contact_id' => $this->_contactID,
953 'is_override' => 1,
954 'status_id' => $this->_membershipStatusID,
6a488035
TO
955 );
956
771f3245 957 $result = $this->callAPISuccess('membership', 'create', $params);
958 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 959 'id' => $result['id'],
771f3245 960 ));
6a488035
TO
961 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
962 }
963
964 /**
965 * Test civicrm_contact_memberships_create with membership id (edit
966 * membership).
967 * success expected.
968 */
00be9182 969 public function testMembershipCreateUpdateWithIDAndSource() {
6a488035
TO
970 $membershipID = $this->contactMembershipCreate($this->_params);
971 $params = array(
972 'id' => $membershipID,
973 'source' => 'changed',
974 'contact_id' => $this->_contactID,
6c6e6187 975 'status_id' => $this->_membershipStatusID,
5896d037 976 'membership_type_id' => $this->_membershipTypeID,
6a488035
TO
977 'skipStatusCal' => 1,
978 );
771f3245 979 $result = $this->callAPISuccess('membership', 'create', $params);
6a488035 980 $this->assertEquals($result['id'], $membershipID, "in line " . __LINE__);
771f3245 981 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 982 'id' => $result['id'],
5896d037 983 ));
6a488035
TO
984 }
985
986 /**
eceb18cc 987 * Change custom field using update.
6a488035 988 */
00be9182 989 public function testUpdateWithCustom() {
6a488035
TO
990 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
991
992 $params = $this->_params;
993 $params['custom_' . $ids['custom_field_id']] = "custom string";
a828d7b8 994 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, NULL, 'UpdateCustomData');
5896d037
TO
995 $result = $this->callAPISuccess($this->_entity, 'create', array(
996 'id' => $result['id'],
21dfd5f5 997 'custom_' . $ids['custom_field_id'] => "new custom",
5896d037
TO
998 ));
999 $check = $this->callAPISuccess($this->_entity, 'get', array(
1000 'id' => $result['id'],
21dfd5f5 1001 'contact_id' => $this->_contactID,
5896d037 1002 ));
6a488035
TO
1003
1004 $this->assertEquals("new custom", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
d54576ed 1005 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 1006 'id' => $check['id'],
5896d037 1007 ));
6a488035
TO
1008
1009 $this->customFieldDelete($ids['custom_field_id']);
1010 $this->customGroupDelete($ids['custom_group_id']);
1011 }
1012
93c482a4
EM
1013 /**
1014 * per CRM-15746 check that the id can be altered in an update hook
1015 */
28a04ea9 1016 public function testMembershipUpdateCreateHookCRM15746() {
93c482a4
EM
1017 $this->hookClass->setHook('civicrm_pre', array($this, 'hook_civicrm_pre_update_create_membership'));
1018 $result = $this->callAPISuccess('membership', 'create', $this->_params);
1019 $this->callAPISuccess('membership', 'create', array('id' => $result['id'], 'end_date' => '1 year ago'));
1020 $this->callAPISuccessGetCount('membership', array(), 2);
1021 $this->hookClass->reset();
1022 $this->callAPISuccess('membership', 'create', array('id' => $result['id'], 'end_date' => '1 year ago'));
1023 $this->callAPISuccessGetCount('membership', array(), 2);
1024 }
1025
2ea0abec
EM
1026 /**
1027 * Custom hook for update membership.
1028 *
1029 * @param string $op
1030 * @param object $objectName
1031 * @param int $id
1032 * @param array $params
1033 *
1034 * @throws \Exception
1035 */
28a04ea9 1036 public function hook_civicrm_pre_update_create_membership($op, $objectName, $id, &$params) {
93c482a4
EM
1037 if ($objectName == 'Membership' && $op == 'edit') {
1038 $existingMembership = $this->callAPISuccessGetSingle('membership', array('id' => $params['id']));
1039 unset($params['id'], $params['membership_id']);
6c6e6187 1040 $params['join_date'] = $params['membership_start_date'] = $params['start_date'] = date('Ymd000000', strtotime($existingMembership['start_date']));
93c482a4
EM
1041 $params = array_merge($existingMembership, $params);
1042 $params['id'] = NULL;
1043 }
1044 }
1045
6a488035 1046 /**
fe482240 1047 * Test civicrm_contact_memberships_create Invalid membership data.
6a488035
TO
1048 * Error expected.
1049 */
00be9182 1050 public function testMembershipCreateInvalidMemData() {
6a488035
TO
1051 //membership_contact_id as string
1052 $params = array(
1053 'membership_contact_id' => 'Invalid',
1054 'membership_type_id' => $this->_membershipTypeID,
1055 'join_date' => '2011-01-21',
1056 'start_date' => '2010-01-21',
1057 'end_date' => '2008-12-21',
1058 'source' => 'Payment',
1059 'is_override' => 1,
5896d037
TO
1060 'status_id' => $this->_membershipStatusID,
1061 );
6a488035 1062
d54576ed 1063 $this->callAPIFailure('membership', 'create', $params);
6a488035
TO
1064
1065 //membership_contact_id which is no in contact table
1066 $params['membership_contact_id'] = 999;
d54576ed 1067 $this->callAPIFailure('membership', 'create', $params);
6a488035
TO
1068
1069 //invalid join date
1070 unset($params['membership_contact_id']);
1071 $params['join_date'] = "invalid";
d54576ed 1072 $this->callAPIFailure('Membership', 'Create', $params);
6a488035
TO
1073 }
1074
1075 /**
1076 * Test civicrm_contact_memberships_create with membership_contact_id
1077 * membership).
1078 * Success expected.
1079 */
00be9182 1080 public function testMembershipCreateWithMemContact() {
6a488035
TO
1081 $params = array(
1082 'membership_contact_id' => $this->_contactID,
1083 'membership_type_id' => $this->_membershipTypeID,
1084 'join_date' => '2011-01-21',
1085 'start_date' => '2010-01-21',
1086 'end_date' => '2008-12-21',
1087 'source' => 'Payment',
1088 'is_override' => 1,
1089 'status_id' => $this->_membershipStatusID,
6a488035
TO
1090 );
1091
771f3245 1092 $result = $this->callAPISuccess('membership', 'create', $params);
6a488035 1093
d54576ed 1094 $this->callAPISuccess('Membership', 'Delete', array(
6a488035 1095 'id' => $result['id'],
771f3245 1096 ));
6a488035 1097 }
5896d037 1098
cc73900e 1099 /**
1100 * Test civicrm_contact_memberships_create with membership_contact_id
1101 * membership).
1102 * Success expected.
1103 */
00be9182 1104 public function testMembershipCreateValidMembershipTypeString() {
cc73900e 1105 $params = array(
1106 'membership_contact_id' => $this->_contactID,
1107 'membership_type_id' => 'General',
1108 'join_date' => '2011-01-21',
1109 'start_date' => '2010-01-21',
1110 'end_date' => '2008-12-21',
1111 'source' => 'Payment',
1112 'is_override' => 1,
1113 'status_id' => $this->_membershipStatusID,
1114 );
1115
1116 $result = $this->callAPISuccess('membership', 'create', $params);
1117 $this->assertEquals($this->_membershipTypeID, $result['values'][$result['id']]['membership_type_id']);
d54576ed 1118 $this->callAPISuccess('Membership', 'Delete', array(
cc73900e 1119 'id' => $result['id'],
1120 ));
1121 }
1122
1123 /**
1124 * Test civicrm_contact_memberships_create with membership_contact_id
1125 * membership).
1126 * Success expected.
1127 */
00be9182 1128 public function testMembershipCreateInValidMembershipTypeString() {
cc73900e 1129 $params = array(
1130 'membership_contact_id' => $this->_contactID,
1131 'membership_type_id' => 'invalid',
1132 'join_date' => '2011-01-21',
1133 'start_date' => '2010-01-21',
1134 'end_date' => '2008-12-21',
1135 'source' => 'Payment',
1136 'is_override' => 1,
1137 'status_id' => $this->_membershipStatusID,
1138 );
1139
d54576ed 1140 $this->callAPIFailure('membership', 'create', $params);
cc73900e 1141 }
6a488035 1142
cc73900e 1143 /**
eceb18cc 1144 * Test that if membership join date is not set it defaults to today.
cc73900e 1145 */
00be9182 1146 public function testEmptyJoinDate() {
8c33a68c 1147 unset($this->_params['join_date'], $this->_params['is_override']);
1148 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
1149 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1150 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['join_date']);
1151 $this->assertEquals('2009-01-21', $result['start_date']);
1152 $this->assertEquals('2009-12-21', $result['end_date']);
cc73900e 1153 }
5896d037 1154
cc73900e 1155 /**
fe482240 1156 * Test that if membership start date is not set it defaults to correct end date.
8c33a68c 1157 * - fixed
cc73900e 1158 */
00be9182 1159 public function testEmptyStartDateFixed() {
8c33a68c 1160 unset($this->_params['start_date'], $this->_params['is_override']);
1161 $this->_params['membership_type_id'] = $this->_membershipTypeID2;
1162 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
1163 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1164 $this->assertEquals('2009-01-21', $result['join_date']);
1165 $this->assertEquals('2008-03-01', $result['start_date']);
1166 $this->assertEquals('2009-12-21', $result['end_date']);
1167 }
cc73900e 1168
8c33a68c 1169 /**
1170 * Test that if membership start date is not set it defaults to correct end date
1171 * - fixed
1172 */
2ea0abec
EM
1173 public function testEmptyStartEndDateFixedOneYear() {
1174 unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
1175 $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2, 'duration_interval' => 1));
1176 $this->_params['membership_type_id'] = $this->_membershipTypeID2;
1177 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
1178 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1179 $this->assertEquals('2009-01-21', $result['join_date']);
1180 $this->assertEquals('2008-03-01', $result['start_date']);
1181 $this->assertEquals('2010-02-28', $result['end_date']);
1182 }
1183
1184 /**
9398f167
EM
1185 * Test that if membership start date is not set it defaults to correct end date for fixed multi year memberships.
1186 */
1187 public function testEmptyStartEndDateFixedMultiYear() {
1188 unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
1189 $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2, 'duration_interval' => 5));
1190 $this->_params['membership_type_id'] = $this->_membershipTypeID2;
1191 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
1192 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1193 $this->assertEquals('2009-01-21', $result['join_date']);
1194 $this->assertEquals('2008-03-01', $result['start_date']);
1195 $this->assertEquals('2014-02-28', $result['end_date']);
1196 }
1197
41dcb974 1198 /**
1199 * CRM-18503 - Test membership join date is correctly set for fixed memberships.
1200 */
1201 public function testMembershipJoinDateFixed() {
1202 $memStatus = CRM_Member_PseudoConstant::membershipStatus();
1203 // Update the fixed membership type to 1 year duration.
1204 $this->callAPISuccess('membership_type', 'create', array('id' => $this->_membershipTypeID2, 'duration_interval' => 1));
1205 $contactId = $this->createLoggedInUser();
1206 // Create membership with 'Pending' status.
1207 $params = array(
1208 'contact_id' => $contactId,
1209 'membership_type_id' => $this->_membershipTypeID2,
1210 'source' => 'test membership',
1211 'is_pay_later' => 0,
1212 'status_id' => array_search('Pending', $memStatus),
1213 'skipStatusCal' => 1,
1214 'is_for_organization' => 1,
1215 );
1216 $ids = array();
1217 $membership = CRM_Member_BAO_Membership::create($params, $ids);
1218
1219 // Update membership to 'Completed' and check the dates.
1220 $memParams = array(
1221 'id' => $membership->id,
1222 'contact_id' => $contactId,
1223 'is_test' => 0,
1224 'membership_type_id' => $this->_membershipTypeID2,
1225 'num_terms' => 1,
1226 'status_id' => array_search('New', $memStatus),
1227 );
1228 $result = $this->callAPISuccess('Membership', 'create', $memParams);
1229
70a87708 1230 // Extend duration interval if join_date exceeds the rollover period.
1231 $joinDate = date('Y-m-d');
1232 $year = date('Y');
1233 $startDate = date('Y-m-d', strtotime(date('Y-03-01')));
581eb285 1234 $rollOver = TRUE;
1235 if (strtotime($startDate) > time()) {
1236 $rollOver = FALSE;
1237 $startDate = date('Y-m-d', strtotime(date('Y-03-01') . '- 1 year'));
1238 }
70a87708 1239 $membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($this->_membershipTypeID2);
1240 $fixedPeriodRollover = CRM_Member_BAO_MembershipType::isDuringFixedAnnualRolloverPeriod($joinDate, $membershipTypeDetails, $year, $startDate);
1241 $y = 1;
581eb285 1242 if ($fixedPeriodRollover && $rollOver) {
70a87708 1243 $y += 1;
1244 }
1245
41dcb974 1246 $expectedDates = array(
1247 'join_date' => date('Ymd'),
70a87708 1248 'start_date' => str_replace('-', '', $startDate),
1249 'end_date' => date('Ymd', strtotime(date('Y-03-01') . "+ {$y} year - 1 day")),
41dcb974 1250 );
1251 foreach ($result['values'] as $values) {
1252 foreach ($expectedDates as $date => $val) {
70a87708 1253 $this->assertEquals($val, $values[$date], "Failed asserting {$date} values");
41dcb974 1254 }
1255 }
1256 }
1257
b1fc74f0 1258 /**
964a9e96
EM
1259 * Test correct end and start dates are calculated for fixed multi year memberships.
1260 *
1261 * The empty start date is calculated to be the start_date (1 Jan prior to the join_date - so 1 Jan 15)
1262 *
1263 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1264 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1265 * and we add on 4 years rather than 5 because we are not after the rollover day - so we calculate 31 Dec 2019
1266 */
1267 public function testFixedMultiYearDateSetTwoEmptyStartEndDate() {
1268 unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
1269
1270 $this->callAPISuccess('membership_type', 'create', array(
1271 'id' => $this->_membershipTypeID2,
1272 'duration_interval' => 5,
1273 // Ie 1 Jan.
1274 'fixed_period_start_day' => '101',
1275 // Ie. 1 Nov.
1276 'fixed_period_rollover_day' => '1101',
1277 ));
1278 $this->_params['membership_type_id'] = $this->_membershipTypeID2;
1279 $dates = array(
1280 'join_date' => '28-Jan 2015',
1281 );
1282 $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
1283 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1284 $this->assertEquals('2015-01-28', $result['join_date']);
1285 $this->assertEquals('2015-01-01', $result['start_date']);
1286 $this->assertEquals('2019-12-31', $result['end_date']);
1287 }
1288
1289 /**
1290 * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
b1fc74f0
EM
1291 *
1292 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1293 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1294 * and we add on 4 years rather than 5 because we are not after the rollover day - so we calculate 31 Dec 2019
1295 */
964a9e96 1296 public function testFixedMultiYearDateSetTwoEmptyEndDate() {
b1fc74f0
EM
1297 unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
1298
1299 $this->callAPISuccess('membership_type', 'create', array(
1300 'id' => $this->_membershipTypeID2,
1301 'duration_interval' => 5,
1302 // Ie 1 Jan.
1303 'fixed_period_start_day' => '101',
1304 // Ie. 1 Nov.
1305 'fixed_period_rollover_day' => '1101',
1306 ));
1307 $this->_params['membership_type_id'] = $this->_membershipTypeID2;
1308 $dates = array(
1309 'start_date' => '28-Jan 2015',
1310 'join_date' => '28-Jan 2015',
1311 );
1312 $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
1313 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1314 $this->assertEquals('2015-01-28', $result['join_date']);
1315 $this->assertEquals('2015-01-28', $result['start_date']);
1316 $this->assertEquals('2019-12-31', $result['end_date']);
1317 }
1318
1319 /**
964a9e96
EM
1320 * Test correct end and start dates are calculated for fixed multi year memberships.
1321 *
1322 * The empty start date is calculated to be the start_date (1 Jan prior to the join_date - so 1 Jan 15)
1323 *
1324 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1325 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1326 * and we add on <1 years rather than > 1 because we are not after the rollover day - so we calculate 31 Dec 2015
1327 */
1328 public function testFixedSingleYearDateSetTwoEmptyStartEndDate() {
1329 unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
1330
1331 $this->callAPISuccess('membership_type', 'create', array(
1332 'id' => $this->_membershipTypeID2,
1333 'duration_interval' => 1,
1334 // Ie 1 Jan.
1335 'fixed_period_start_day' => '101',
1336 // Ie. 1 Nov.
1337 'fixed_period_rollover_day' => '1101',
1338 ));
1339 $this->_params['membership_type_id'] = $this->_membershipTypeID2;
1340 $dates = array(
1341 'join_date' => '28-Jan 2015',
1342 );
1343 $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
1344 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1345 $this->assertEquals('2015-01-28', $result['join_date']);
1346 $this->assertEquals('2015-01-01', $result['start_date']);
1347 $this->assertEquals('2015-12-31', $result['end_date']);
1348 }
1349
1350 /**
1351 * Test correct end date for fixed single year memberships is calculated and start_date is not changed.
b1fc74f0
EM
1352 *
1353 * In this set our start date is after the start day and before the rollover day so we don't get an extra year
1354 * and we end one day before the rollover day. Start day is 1 Jan so we end on 31 Dec
1355 * and we add on <1 years rather than > 1 because we are not after the rollover day - so we calculate 31 Dec 2015
1356 */
964a9e96 1357 public function testFixedSingleYearDateSetTwoEmptyEndDate() {
b1fc74f0
EM
1358 unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
1359
1360 $this->callAPISuccess('membership_type', 'create', array(
1361 'id' => $this->_membershipTypeID2,
1362 'duration_interval' => 1,
1363 // Ie 1 Jan.
1364 'fixed_period_start_day' => '101',
1365 // Ie. 1 Nov.
1366 'fixed_period_rollover_day' => '1101',
1367 ));
1368 $this->_params['membership_type_id'] = $this->_membershipTypeID2;
1369 $dates = array(
1370 'start_date' => '28-Jan 2015',
1371 'join_date' => '28-Jan 2015',
1372 );
1373 $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
1374 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1375 $this->assertEquals('2015-01-28', $result['join_date']);
1376 $this->assertEquals('2015-01-28', $result['start_date']);
1377 $this->assertEquals('2015-12-31', $result['end_date']);
1378 }
1379
1380 /**
964a9e96 1381 * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
b1fc74f0
EM
1382 *
1383 * In this set our start date is after the start day and after the rollover day so we do get an extra year
1384 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
964a9e96 1385 * and we add on 1 year we are after the rollover day - so we calculate 31 Oct 2016
b1fc74f0 1386 */
964a9e96 1387 public function testFixedSingleYearDateSetThreeEmptyEndDate() {
b1fc74f0
EM
1388 unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
1389
1390 $this->callAPISuccess('membership_type', 'create', array(
1391 'id' => $this->_membershipTypeID2,
1392 'duration_interval' => 1,
1393 // Ie. 1 Nov.
1394 'fixed_period_start_day' => '1101',
1395 // Ie 1 Jan.
1396 'fixed_period_rollover_day' => '101',
1397 ));
1398 $this->_params['membership_type_id'] = $this->_membershipTypeID2;
1399 $dates = array(
1400 'start_date' => '28-Jan 2015',
1401 'join_date' => '28-Jan 2015',
1402 );
1403 $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
1404 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1405 $this->assertEquals('2015-01-28', $result['join_date']);
1406 $this->assertEquals('2015-01-28', $result['start_date']);
1407 $this->assertEquals('2016-10-31', $result['end_date']);
1408 }
1409
964a9e96
EM
1410 /**
1411 * Test correct end and start dates are calculated for fixed multi year memberships.
1412 *
d177a2a6 1413 * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
964a9e96
EM
1414 *
1415 * In this set our start date is after the start day and after the rollover day so we do get an extra year
1416 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1417 * and we add on 1 year we are after the rollover day - so we calculate 31 Oct 2016
1418 */
1419 public function testFixedSingleYearDateSetThreeEmptyStartEndDate() {
1420 unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
1421
1422 $this->callAPISuccess('membership_type', 'create', array(
1423 'id' => $this->_membershipTypeID2,
1424 'duration_interval' => 1,
1425 // Ie. 1 Nov.
1426 'fixed_period_start_day' => '1101',
1427 // Ie 1 Jan.
1428 'fixed_period_rollover_day' => '101',
1429 ));
1430 $this->_params['membership_type_id'] = $this->_membershipTypeID2;
1431 $dates = array(
1432 'join_date' => '28-Jan 2015',
1433 );
1434 $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
1435 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1436 $this->assertEquals('2015-01-28', $result['join_date']);
1437 $this->assertEquals('2014-11-01', $result['start_date']);
1438 $this->assertEquals('2016-10-31', $result['end_date']);
1439 }
b1fc74f0
EM
1440
1441 /**
964a9e96 1442 * Test that correct end date is calculated for fixed multi year memberships and start date is not changed.
b1fc74f0
EM
1443 *
1444 * In this set our start date is after the start day and after the rollover day so we do get an extra year
1445 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1446 * and we add on 5 years we are after the rollover day - so we calculate 31 Oct 2020
1447 */
964a9e96 1448 public function testFixedMultiYearDateSetThreeEmptyEndDate() {
b1fc74f0
EM
1449 unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
1450
1451 $this->callAPISuccess('membership_type', 'create', array(
1452 'id' => $this->_membershipTypeID2,
1453 'duration_interval' => 5,
1454 // Ie. 1 Nov.
1455 'fixed_period_start_day' => '1101',
1456 // Ie 1 Jan.
1457 'fixed_period_rollover_day' => '101',
1458 ));
1459 $this->_params['membership_type_id'] = $this->_membershipTypeID2;
1460 $dates = array(
1461 'start_date' => '28-Jan 2015',
1462 'join_date' => '28-Jan 2015',
1463 );
1464 $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
1465 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1466 $this->assertEquals('2015-01-28', $result['join_date']);
1467 $this->assertEquals('2015-01-28', $result['start_date']);
1468 $this->assertEquals('2020-10-31', $result['end_date']);
1469 }
9398f167 1470
964a9e96
EM
1471 /**
1472 * Test correct end and start dates are calculated for fixed multi year memberships.
1473 *
d177a2a6 1474 * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
964a9e96
EM
1475 *
1476 * The empty start date is calculated to be the start_date (1 Nov prior to the join_date - so 1 Nov 14)
1477 * In this set our join date is after the start day and after the rollover day so we do get an extra year
1478 * and we end one day before the rollover day. Start day is 1 Nov so we end on 31 Oct
1479 * and we add on 5 years we are after the rollover day - so we calculate 31 Oct 2020
1480 */
1481 public function testFixedMultiYearDateSetThreeEmptyStartEndDate() {
1482 unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
1483
1484 $this->callAPISuccess('membership_type', 'create', array(
1485 'id' => $this->_membershipTypeID2,
1486 'duration_interval' => 5,
1487 // Ie. 1 Nov.
1488 'fixed_period_start_day' => '1101',
1489 // Ie 1 Jan.
1490 'fixed_period_rollover_day' => '101',
1491 ));
1492 $this->_params['membership_type_id'] = $this->_membershipTypeID2;
1493 $dates = array(
1494 'join_date' => '28-Jan 2015',
1495 );
1496 $result = $this->callAPISuccess($this->_entity, 'create', array_merge($this->_params, $dates));
1497 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1498 $this->assertEquals('2015-01-28', $result['join_date']);
1499 $this->assertEquals('2014-11-01', $result['start_date']);
1500 $this->assertEquals('2020-10-31', $result['end_date']);
1501 }
1502
9398f167
EM
1503 /**
1504 * Test that if membership start date is not set it defaults to correct end date for fixed single year memberships.
2ea0abec 1505 */
00be9182 1506 public function testEmptyStartDateRolling() {
8c33a68c 1507 unset($this->_params['start_date'], $this->_params['is_override']);
1508 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
1509 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1510 $this->assertEquals('2009-01-21', $result['join_date']);
1511 $this->assertEquals('2009-01-21', $result['start_date']);
1512 $this->assertEquals('2009-12-21', $result['end_date']);
cc73900e 1513 }
5896d037 1514
8c33a68c 1515 /**
eceb18cc 1516 * Test that if membership end date is not set it defaults to correct end date.
8c33a68c 1517 * - rolling
1518 */
00be9182 1519 public function testEmptyEndDateFixed() {
8c33a68c 1520 unset($this->_params['start_date'], $this->_params['is_override'], $this->_params['end_date']);
1521 $this->_params['membership_type_id'] = $this->_membershipTypeID2;
1522 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
1523 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1524 $this->assertEquals('2009-01-21', $result['join_date']);
1525 $this->assertEquals('2008-03-01', $result['start_date']);
1526 $this->assertEquals('2010-02-28', $result['end_date']);
1527 }
5896d037 1528
8c33a68c 1529 /**
eceb18cc 1530 * Test that if membership end date is not set it defaults to correct end date.
8c33a68c 1531 * - rolling
1532 */
00be9182 1533 public function testEmptyEndDateRolling() {
8c33a68c 1534 unset($this->_params['is_override'], $this->_params['end_date']);
1535 $this->_params['membership_type_id'] = $this->_membershipTypeID;
1536 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
1537 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1538 $this->assertEquals('2009-01-21', $result['join_date']);
1539 $this->assertEquals('2009-01-21', $result['start_date']);
1540 $this->assertEquals('2010-01-20', $result['end_date']);
1541 }
1542
8c33a68c 1543 /**
452b9e04 1544 * Test that if dates are set they not over-ridden if id is passed in
8c33a68c 1545 */
6c6e6187 1546 public function testMembershipDatesNotOverridden() {
8c33a68c 1547 $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
1548 unset($this->_params['end_date'], $this->_params['start_date']);
1549 $this->_params['id'] = $result['id'];
1550 $this->callAPISuccess($this->_entity, 'create', $this->_params);
1551 $result = $this->callAPISuccess($this->_entity, 'getsingle', array('id' => $result['id']));
1552 $this->assertEquals('2009-01-21', $result['join_date']);
1553 $this->assertEquals('2009-01-21', $result['start_date']);
1554 $this->assertEquals('2009-12-21', $result['end_date']);
1555
6c6e6187 1556 }
96025800 1557
8b3df6dc 1558 /**
1559 * Test that all membership types are returned when getoptions is called.
1560 *
1561 * This test locks in current behaviour where types for all domains are returned. It should possibly be domain
1562 * specific but that should only be done in conjunction with adding a hook to allow that to be altered as the
1563 * multisite use case expects the master domain to be able to see all sites.
1564 *
1565 * See CRM-17075.
1566 */
1567 public function testGetOptionsMembershipTypeID() {
1568 $options = $this->callAPISuccess('Membership', 'getoptions', array('field' => 'membership_type_id'));
5d8b37be 1569 $this->assertEquals('Another one', array_pop($options['values']));
8b3df6dc 1570 $this->assertEquals('General', array_pop($options['values']));
1571 $this->assertEquals(NULL, array_pop($options['values']));
1572 }
1573
6a488035 1574}