CRM-19799, added test
authorPradeep Nayak <pradpnayak@gmail.com>
Mon, 26 Dec 2016 23:37:48 +0000 (05:07 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Wed, 28 Dec 2016 21:02:01 +0000 (02:32 +0530)
----------------------------------------
* CRM-19799: LineItems incorrect at both Contribution Level and Financial Accounts Level
  https://issues.civicrm.org/jira/browse/CRM-19799

tests/phpunit/api/v3/ContributionPageTest.php

index 4cde02fdcf0af323d8dff0859b050425d1bf5e6f..2d2c8c054578ad456586d9de65eb668ca15b0e4a 100644 (file)
@@ -1354,4 +1354,66 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     $this->assertEquals($pledgePayment['values'][2]['contribution_id'], $contribution['id']);
   }
 
+  /**
+   * Test form submission with multiple option price set.
+   */
+  public function testSubmitContributionPageWithPriceSet() {
+    $this->_priceSetParams['is_quick_config'] = 0;
+    $this->setUpContributionPage();
+    $submitParams = array(
+      'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
+      'id' => (int) $this->_ids['contribution_page'],
+      'amount' => 80,
+      'first_name' => 'Billy',
+      'last_name' => 'Gruff',
+      'email' => 'billy@goat.gruff',
+      'is_pay_later' => TRUE,
+    );
+    $this->addPriceFields($submitParams);
+
+    $this->callAPISuccess('contribution_page', 'submit', $submitParams);
+    $contribution = $this->callAPISuccessGetSingle('contribution', array(
+      'contribution_page_id' => $this->_ids['contribution_page'],
+      'contribution_status_id' => 2,
+    ));
+    $this->callAPISuccessGetCount(
+      'LineItem',
+      array(
+        'contribution_id' => $contribution['id'],
+      ),
+      3
+    );
+  }
+
+  /**
+   * Function to add additional price fields to priceset.
+   * @param array $params
+   */
+  public function addPriceFields(&$params) {
+    $priceSetID = reset($this->_ids['price_set']);
+    $priceField = $this->callAPISuccess('price_field', 'create', array(
+      'price_set_id' => $priceSetID,
+      'label' => 'Chicken Breed',
+      'html_type' => 'CheckBox',
+    ));
+    $priceFieldValue1 = $this->callAPISuccess('price_field_value', 'create', array(
+      'price_set_id' => $priceSetID,
+      'price_field_id' => $priceField['id'],
+      'label' => 'Shoe-eating chicken -1',
+      'financial_type_id' => 'Donation',
+      'amount' => 30,
+    ));
+    $priceFieldValue2 = $this->callAPISuccess('price_field_value', 'create', array(
+      'price_set_id' => $priceSetID,
+      'price_field_id' => $priceField['id'],
+      'label' => 'Shoe-eating chicken -2',
+      'financial_type_id' => 'Donation',
+      'amount' => 40,
+    ));
+    $params['price_' . $priceField['id']] = array(
+      $priceFieldValue1['id'] => 1,
+      $priceFieldValue2['id'] => 1,
+    );
+  }
+
 }