From: Jitendra Purohit Date: Thu, 6 Jul 2017 10:15:54 +0000 (+0530) Subject: CRM-20823 : Price Set field with an Expiry Date still being required after being... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a012055bc78c1f043559b8114b4d1db67a23f922;p=civicrm-core.git CRM-20823 : Price Set field with an Expiry Date still being required after being expired --- diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 50189d2155..a83d7b6658 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -982,7 +982,7 @@ WHERE id = %1"; $autoRenewMembershipTypes[] = $membershiptTypeValue['id']; } } - foreach ($form->_priceSet['fields'] as &$field) { + foreach ($form->_priceSet['fields'] as $field) { if (array_key_exists('options', $field) && is_array($field['options'])) { foreach ($field['options'] as $option) { if (!empty($option['membership_type_id'])) { diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php index 47f7677568..1fe63b5589 100644 --- a/tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php @@ -125,4 +125,78 @@ class CRM_Contribute_Form_Contribution_MainTest extends CiviUnitTestCase { return $form; } + /** + * Test expired priceset are not returned from buildPriceSet() Function + */ + public function testExpiredPriceSet() { + $form = $this->getContributionForm(); + $priceSetParams1 = array( + 'name' => 'priceset', + 'title' => 'Priceset with Multiple Terms', + 'is_active' => 1, + 'extends' => 3, + 'financial_type_id' => 2, + 'is_quick_config' => 1, + 'is_reserved' => 1, + ); + $priceSet = $this->callAPISuccess('price_set', 'create', $priceSetParams1); + $form->_priceSetId = $priceSet['id']; + + $form->controller = new CRM_Core_Controller(); + $form->set('priceSetId', $form->_priceSetId); + $params = array( + 'price_set_id' => $form->_priceSetId, + 'name' => 'testvalidpf', + 'label' => 'test valid pf', + 'html_type' => 'Radio', + 'is_enter_qty' => 1, + 'is_active' => 1, + ); + $priceField1 = $this->callAPISuccess('PriceField', 'create', $params); + + //Create expired price field. + $params = array( + 'price_set_id' => $form->_priceSetId, + 'name' => 'testexpiredpf', + 'label' => 'test expired pf', + 'html_type' => 'Radio', + 'is_enter_qty' => 1, + 'is_active' => 1, + 'expire_on' => date('Y-m-d', strtotime("-1 days")), + ); + $priceField2 = $this->callAPISuccess('PriceField', 'create', $params); + + //Create price options. + $membershipOrgId = $this->organizationCreate(NULL); + $memtype = $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId)); + foreach (array($priceField1, $priceField2) as $priceField) { + $priceFieldValueParams = array( + 'price_field_id' => $priceField['id'], + 'name' => 'rye grass', + 'membership_type_id' => $memtype, + 'label' => 'juicy and healthy', + 'amount' => 1, + 'membership_num_terms' => 2, + 'financial_type_id' => 1, + ); + $this->callAPISuccess('PriceFieldValue', 'create', $priceFieldValueParams); + } + + $priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSet['id'])); + $form->_values['fee'] = $form->_feeBlock = $priceSet['fields']; + foreach ($priceSet['fields'] as $pField) { + foreach ($pField['options'] as $opId => $opValues) { + $membershipTypeIds[$opValues['membership_type_id']] = $opValues['membership_type_id']; + } + } + $form->_membershipTypeValues = CRM_Member_BAO_Membership::buildMembershipTypeValues($form, $membershipTypeIds); + + //This function should not update form priceSet with the expired one. + CRM_Price_BAO_PriceSet::buildPriceSet($form); + + $this->assertEquals(count($form->_priceSet['fields']), 1); + $field = current($form->_priceSet['fields']); + $this->assertEquals($field['name'], 'testvalidpf'); + } + }