Skip to content

Commit

Permalink
Improve cleanup on membershipStatus to cope with undeleted memberships
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Mar 22, 2020
1 parent 879ff7b commit 31c3ac9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,8 @@ public function membershipDelete($membershipID) {
* @param string $name
*
* @return mixed
*
* @throws \CRM_Core_Exception
*/
public function membershipStatusCreate($name = 'test member status') {
$params['name'] = $name;
Expand All @@ -636,17 +638,19 @@ public function membershipStatusCreate($name = 'test member status') {

$result = $this->callAPISuccess('MembershipStatus', 'Create', $params);
CRM_Member_PseudoConstant::flush('membershipStatus');
return $result['id'];
return (int) $result['id'];
}

/**
* Delete the given membership status, deleting any memberships of the status first.
*
* @param int $membershipStatusID
*
* @throws \CRM_Core_Exception
*/
public function membershipStatusDelete($membershipStatusID) {
if (!$membershipStatusID) {
return;
}
$result = $this->callAPISuccess('MembershipStatus', 'Delete', ['id' => $membershipStatusID]);
public function membershipStatusDelete(int $membershipStatusID) {
$this->callAPISuccess('Membership', 'get', ['status_id' => $membershipStatusID, 'api.Membership.delete' => 1]);
$this->callAPISuccess('MembershipStatus', 'Delete', ['id' => $membershipStatusID]);
}

public function membershipRenewalDate($durationUnit, $membershipEndDate) {
Expand Down
5 changes: 5 additions & 0 deletions tests/phpunit/api/v3/MembershipStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public function setUp() {
CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE);
}

/**
* Cleanup after test.
*
* @throws \CRM_Core_Exception
*/
public function tearDown() {
$this->membershipStatusDelete($this->_membershipStatusID);
$this->membershipTypeDelete(['id' => $this->_membershipTypeID]);
Expand Down

0 comments on commit 31c3ac9

Please sign in to comment.