CRM-20823 : Price Set field with an Expiry Date still being required after being...
authorJitendra Purohit <jitendra@fuzion.co.nz>
Thu, 6 Jul 2017 10:15:54 +0000 (15:45 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Thu, 6 Jul 2017 12:25:51 +0000 (17:55 +0530)
CRM/Price/BAO/PriceSet.php
tests/phpunit/CRM/Contribute/Form/Contribution/MainTest.php

index 50189d2155024dfeb00db69f70d8f395d8450e4d..a83d7b665828c33857f933b61d14af2f622a02da 100644 (file)
@@ -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'])) {
index 47f76775686d9a8b8b095959c3e44f1835a0b0f9..1fe63b5589207af5a3b58ad6a5a91c88e2960a16 100644 (file)
@@ -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');
+  }
+
 }