Skip to content

Commit

Permalink
Merge pull request #18798 from eileenmcnaughton/memtest
Browse files Browse the repository at this point in the history
Replace BAO calls with api calls in test class
  • Loading branch information
eileenmcnaughton authored Oct 19, 2020
2 parents 3662ba7 + 296ca25 commit 6be65bb
Showing 1 changed file with 32 additions and 45 deletions.
77 changes: 32 additions & 45 deletions tests/phpunit/CRM/Member/BAO/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function testCreate() {
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
];
CRM_Member_BAO_Membership::create($params);
$this->callAPISuccess('Membership', 'create', $params);

$membershipTypeId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId,
'membership_type_id', 'contact_id',
Expand Down Expand Up @@ -181,7 +181,7 @@ public function testGetValues() {
'status_id' => $this->_membershipStatusID,
];

CRM_Member_BAO_Membership::create($params);
$this->callAPISuccess('Membership', 'create', $params);

$membershipId1 = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
'contact_id', 'Database check for created membership.'
Expand All @@ -198,7 +198,7 @@ public function testGetValues() {
'status_id' => $this->_membershipStatusID,
];

CRM_Member_BAO_Membership::create($params);
$this->callAPISuccess('Membership', 'create', $params);

$membershipId2 = $this->assertDBNotNull('CRM_Member_BAO_Membership', 'source123', 'id',
'source', 'Database check for created membership.'
Expand Down Expand Up @@ -242,7 +242,7 @@ public function testActiveMembers() {
'status_id' => $this->_membershipStatusID,
];

CRM_Member_BAO_Membership::create($params);
$this->callAPISuccess('Membership', 'create', $params);

$membershipId1 = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
'contact_id', 'Database check for created membership.'
Expand All @@ -264,7 +264,7 @@ public function testActiveMembers() {
'status_id' => $this->_membershipStatusID,
];

CRM_Member_BAO_Membership::create($params);
$this->callAPISuccess('Membership', 'create', $params);

$membershipId2 = $this->assertDBNotNull('CRM_Member_BAO_Membership', 'PaySource', 'id',
'source', 'Database check for created membership.'
Expand Down Expand Up @@ -415,13 +415,12 @@ public function testRenewMembership() {
'status_id' => $this->_membershipStatusID,
];

$membership = CRM_Member_BAO_Membership::create($params);
$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
'contact_id', 'Database check for created membership.'
);
$this->callAPISuccess('Membership', 'create', $params);

$membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $contactId]);

$this->assertDBNotNull('CRM_Member_BAO_MembershipLog',
$membership->id,
$membership['id'],
'id',
'membership_id',
'Database checked on membershiplog record.'
Expand All @@ -448,7 +447,7 @@ public function testRenewMembership() {
NULL,
NULL
);
$endDate = date("Y-m-d", strtotime($membership->end_date . " +1 year"));
$endDate = date("Y-m-d", strtotime($membership['end_date'] . " +1 year"));

$this->assertDBNotNull('CRM_Member_BAO_MembershipLog',
$MembershipRenew->id,
Expand All @@ -459,7 +458,7 @@ public function testRenewMembership() {
$this->assertEquals($this->_membershipTypeID, $MembershipRenew->membership_type_id, 'Verify membership type is changed during renewal.');
$this->assertEquals($endDate, $MembershipRenew->end_date, 'Verify correct end date is calculated after membership renewal');

$this->membershipDelete($membershipId);
$this->membershipDelete($membership['id']);
$this->contactDelete($contactId);
}

Expand All @@ -484,32 +483,20 @@ public function testStaleMembership() {
'status_id' => $statusId,
];

$membership = CRM_Member_BAO_Membership::create($params);
$this->callAPISuccess('Membership', 'create', $params);

$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
'contact_id', 'Database check for created membership.'
);

$this->assertEquals($membership->status_id, $statusId, 'Verify correct status id is calculated.');
$this->assertEquals($membership->membership_type_id, $this->_membershipTypeID,
'Verify correct membership type id.'
);

//verify all dates.
$dates = [
'startDate' => 'start_date',
'joinDate' => 'join_date',
'endDate' => 'end_date',
];
$membership = $this->callAPISuccessGetSingle('Membership', [
'contact_id' => $contactId,
'start_date' => $startDate,
'join_date' => $joinDate,
'end_date' => $endDate,
]);

foreach ($dates as $date => $dbDate) {
$this->assertEquals($membership->$dbDate, $$date,
"Verify correct {$date} is present."
);
}
$this->assertEquals($membership['status_id'], $statusId, 'Verify correct status id is calculated.');
$this->assertEquals($membership['membership_type_id'], $this->_membershipTypeID);

$this->assertDBNotNull('CRM_Member_BAO_MembershipLog',
$membership->id,
$membership['id'],
'id',
'membership_id',
'Database checked on membership log record.'
Expand Down Expand Up @@ -538,7 +525,7 @@ public function testStaleMembership() {
'Database checked on membership log record.'
);

$this->membershipDelete($membershipId);
$this->membershipDelete($membership['id']);
$this->contactDelete($contactId);
}

Expand All @@ -555,17 +542,17 @@ public function testUpdateAllMembershipStatusConvertExpiredOverriddenStatusToNor
'status_id' => $this->_membershipStatusID,
];

$createdMembership = CRM_Member_BAO_Membership::create($params);
$createdMembershipID = $this->callAPISuccess('Membership', 'create', $params)['id'];

civicrm_api3('Job', 'process_membership');

$membershipAfterProcess = civicrm_api3('Membership', 'get', [
'sequential' => 1,
'id' => $createdMembership->id,
'id' => $createdMembershipID,
'return' => ['id', 'is_override', 'status_override_end_date'],
])['values'][0];

$this->assertEquals($createdMembership->id, $membershipAfterProcess['id']);
$this->assertEquals($createdMembershipID, $membershipAfterProcess['id']);
$this->assertArrayNotHasKey('is_override', $membershipAfterProcess);
$this->assertArrayNotHasKey('status_override_end_date', $membershipAfterProcess);
}
Expand All @@ -583,17 +570,17 @@ public function testUpdateAllMembershipStatusHandleOverriddenWithEndOverrideDate
'status_id' => $this->_membershipStatusID,
];

$createdMembership = CRM_Member_BAO_Membership::create($params);
$createdMembershipID = $this->callAPISuccess('Membership', 'create', $params)['id'];

civicrm_api3('Job', 'process_membership');

$membershipAfterProcess = civicrm_api3('Membership', 'get', [
'sequential' => 1,
'id' => $createdMembership->id,
'id' => $createdMembershipID,
'return' => ['id', 'is_override', 'status_override_end_date'],
])['values'][0];

$this->assertEquals($createdMembership->id, $membershipAfterProcess['id']);
$this->assertEquals($createdMembershipID, $membershipAfterProcess['id']);
$this->assertArrayNotHasKey('is_override', $membershipAfterProcess);
$this->assertArrayNotHasKey('status_override_end_date', $membershipAfterProcess);
}
Expand All @@ -610,17 +597,17 @@ public function testUpdateAllMembershipStatusDoesNotConvertOverridenMembershipWi
'status_id' => $this->_membershipStatusID,
];

$createdMembership = CRM_Member_BAO_Membership::create($params);
$createdMembershipID = $this->callAPISuccess('Membership', 'create', $params)['id'];

civicrm_api3('Job', 'process_membership');

$membershipAfterProcess = civicrm_api3('Membership', 'get', [
'sequential' => 1,
'id' => $createdMembership->id,
'id' => $createdMembershipID,
'return' => ['id', 'is_override', 'status_override_end_date'],
])['values'][0];

$this->assertEquals($createdMembership->id, $membershipAfterProcess['id']);
$this->assertEquals($createdMembershipID, $membershipAfterProcess['id']);
$this->assertEquals(1, $membershipAfterProcess['is_override']);
}

Expand Down Expand Up @@ -827,7 +814,7 @@ protected function setupMembership(): array {
'status_id' => $this->_membershipStatusID,
];

CRM_Member_BAO_Membership::create($params);
$this->callAPISuccess('Membership', 'create', $params);

$membershipId = $this->assertDBNotNull('CRM_Member_BAO_Membership', $contactId, 'id',
'contact_id', 'Database check for created membership.'
Expand Down

0 comments on commit 6be65bb

Please sign in to comment.