Skip to content

Commit

Permalink
Fix Membership.create in BAO to respect passed in status_id
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Aug 2, 2021
1 parent 1ec58fe commit 97e1443
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 146 deletions.
28 changes: 16 additions & 12 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4690,19 +4690,23 @@ public static function updateMembershipBasedOnCompletionOfContribution($contribu
);
$dates['join_date'] = $currentMembership['join_date'];
}
if ('Pending' === CRM_Core_PseudoConstant::getName('CRM_Member_BAO_Membership', 'status_id', $membership['status_id'])) {
$membershipParams['skipStatusCal'] = '';
}
else {
//get the status for membership.
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'],
$dates['end_date'],
$dates['join_date'],
'now',
TRUE,
$membershipParams['membership_type_id'],
$membershipParams
);

//get the status for membership.
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'],
$dates['end_date'],
$dates['join_date'],
'now',
TRUE,
$membershipParams['membership_type_id'],
$membershipParams
);

unset($dates['end_date']);
$membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 'New');
unset($dates['end_date']);
$membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 'New');
}
//we might be renewing membership,
//so make status override false.
$membershipParams['is_override'] = FALSE;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Member/BAO/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public static function create(&$params, $ids = []) {
$excludeIsAdmin = TRUE;
}

if (empty($params['is_override'])) {
if (empty($params['status_id']) && empty($params['is_override'])) {
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($params['start_date'], $params['end_date'], $params['join_date'],
'now', $excludeIsAdmin, $params['membership_type_id'] ?? NULL, $params
);
Expand Down
3 changes: 2 additions & 1 deletion Civi/Test/ContactTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public function organizationCreate($params = [], $seq = 0): int {
*/
public function individualCreate(array $params = [], $seq = 0, $random = FALSE): int {
$params = array_merge($this->sampleContact('Individual', $seq, $random), $params);
return $this->_contactCreate($params);
$this->ids['Contact']['individual_' . $seq] = $this->_contactCreate($params);
return $this->ids['Contact']['individual_' . $seq];
}

/**
Expand Down
4 changes: 3 additions & 1 deletion api/v3/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ function civicrm_api3_order_create(array $params): array {
}

if ($entityParams['entity'] === 'membership') {
$entityParams['status_id'] = 'Pending';
if (empty($entityParams['id'])) {
$entityParams['status_id'] = 'Pending';
}
if (!empty($params['contribution_recur_id'])) {
$entityParams['contribution_recur_id'] = $params['contribution_recur_id'];
}
Expand Down
8 changes: 3 additions & 5 deletions tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public function testExportComponentsContributionSoftCredits(): void {
*
* @throws \CRM_Core_Exception
* @throws \League\Csv\Exception
* @throws \API_Exception
*/
public function testExportComponentsMembership(): void {
$this->setUpMembershipExportData();
Expand Down Expand Up @@ -305,7 +306,7 @@ public function testExportComponentsMembership(): void {
'Membership Start Date' => $membership['start_date'],
'Membership Expiration Date' => $membership['end_date'],
'Source' => 'Payment',
'Membership Status' => 'New',
'Membership Status' => 'Pending',
'Membership ID' => '2',
'Primary Member ID' => '',
'Max Related' => '',
Expand Down Expand Up @@ -420,7 +421,7 @@ public function setUpContributionExportData(): void {
* Set up some data for us to do testing on.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \API_Exception
*/
public function setUpMembershipExportData(): void {
$this->setUpContactExportData();
Expand Down Expand Up @@ -472,9 +473,6 @@ public function setUpActivityExportData(): void {

/**
* Set up some data for us to do testing on.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function setUpContactExportData(): void {
$this->contactIDs[] = $contactA = $this->individualCreate(['gender_id' => 'Female']);
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/CRM/Member/Selector/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class CRM_Member_Selector_SearchTest extends CiviUnitTestCase {
/**
* Test results from getRows.
*
* @throws \CRM_Core_Exception
* @throws \API_Exception
*/
public function testSelectorGetRows() {
public function testSelectorGetRows(): void {
$this->_contactID = $this->individualCreate();
$this->_invoiceID = 1234;
$this->_contributionPageID = NULL;
Expand All @@ -44,7 +44,7 @@ public function testSelectorGetRows() {
'membership_source' => 'Payment',
'member_is_test' => '0',
'owner_membership_id' => NULL,
'membership_status' => 'New',
'membership_status' => 'Pending',
'member_campaign_id' => NULL,
'campaign' => NULL,
'campaign_id' => NULL,
Expand Down
6 changes: 1 addition & 5 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ public function createDomainContacts(): void {
/**
* Common teardown functions for all unit tests.
*
* @throws \CiviCRM_API3_Exception
* @throws \CRM_Core_Exception
* @throws \API_Exception
*/
Expand Down Expand Up @@ -712,8 +711,6 @@ public function membershipDelete($membershipID) {
* @param string $name
*
* @return mixed
*
* @throws \CRM_Core_Exception
*/
public function membershipStatusCreate($name = 'test member status') {
$params['name'] = $name;
Expand Down Expand Up @@ -825,7 +822,6 @@ public function paymentProcessorTypeCreate($params = []) {
* @param array $params
*
* @return mixed
* @throws \CRM_Core_Exception
*/
public function paymentProcessorAuthorizeNetCreate($params = []) {
$params = array_merge([
Expand Down Expand Up @@ -3169,7 +3165,7 @@ protected function addTaxAccountToFinancialType(int $financialTypeId, $accountPa
public function createPriceSetWithPage($entity = NULL, $params = []) {
$membershipTypeID = $this->membershipTypeCreate(['name' => 'Special']);
$contributionPageResult = $this->callAPISuccess('contribution_page', 'create', [
'title' => "Test Contribution Page",
'title' => 'Test Contribution Page',
'financial_type_id' => 1,
'currency' => 'NZD',
'goal_amount' => 50,
Expand Down
Loading

0 comments on commit 97e1443

Please sign in to comment.