Fix tests to more standard setup method
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 17 Dec 2023 22:20:33 +0000 (11:20 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 18 Dec 2023 00:19:19 +0000 (13:19 +1300)
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Financial/BAO/Order.php
tests/phpunit/api/v3/ContributionPageTest.php

index 6375776a4afb844dbb952eb5039c986b356bbc81..02db81ad495a73620c0c3f88bbdc8093b9a9a128 100644 (file)
@@ -1860,10 +1860,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
       // @todo deprecate receiving amount, calculate on the form.
       $form->order->setOverrideTotalAmount((float) $params['amount']);
     }
-    $amount = $form->order->getTotalAmount();
-    if ($form->isSeparateMembershipPayment()) {
-      $amount -= $form->order->getMembershipTotalAmount();
-    }
     // hack these in for test support.
     $form->_fields['billing_first_name'] = 1;
     $form->_fields['billing_last_name'] = 1;
index caa68816b37ea68691aa353332345f0533f593ed..8272744f13c1a22978e99ab562c549c799a5d22e 100644 (file)
@@ -923,8 +923,9 @@ class CRM_Financial_BAO_Order {
         if ($valueID !== '') {
           $this->setPriceSetIDFromSelectedField($fieldID);
           $throwAwayArray = [];
+          $temporaryParams = $params;
           // @todo - still using getLine for now but better to bring it to this class & do a better job.
-          $newLines = CRM_Price_BAO_PriceSet::getLine($params, $throwAwayArray, $this->getPriceSetID(), $this->getPriceFieldSpec($fieldID), $fieldID)[1];
+          $newLines = CRM_Price_BAO_PriceSet::getLine($temporaryParams, $throwAwayArray, $this->getPriceSetID(), $this->getPriceFieldSpec($fieldID), $fieldID)[1];
           foreach ($newLines as $newLine) {
             $lineItems[$newLine['price_field_value_id']] = $newLine;
           }
index fd2679a16dad0612e3c3f7af3717d1aa1d31abca..149ea4e500744c80f5aac878b55062b774cf2db8 100644 (file)
@@ -300,8 +300,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     $mut = new CiviMailUtils($this, TRUE);
     $this->setUpMembershipContributionPage(TRUE);
     $submitParams = [
-      $this->getPriceFieldLabel('contribution') => 1,
-      $this->getPriceFieldLabel('membership') => $this->getPriceFieldValue('general'),
+      'price_' . $this->ids['PriceField']['other_amount'] => 1,
+      $this->getPriceFieldLabel('membership_amount') => $this->getPriceFieldValue('general'),
       'id' => $this->getContributionPageID(),
       'billing_first_name' => 'Billy',
       'billing_middle_name' => 'Goat',
@@ -340,8 +340,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     $this->ids['MembershipType'] = [$this->membershipTypeCreate(['minimum_fee' => 2])];
     //Pay later
     $submitParams = [
-      $this->getPriceFieldLabel('contribution') => 1,
-      $this->getPriceFieldLabel('membership') => $this->getPriceFieldValue('general'),
+      $this->getPriceFieldLabel('other_amount') => 1,
+      $this->getPriceFieldLabel('membership_amount') => $this->getPriceFieldValue('general'),
       'id' => $this->getContributionPageID(),
       'billing_first_name' => 'Billy',
       'billing_middle_name' => 'Goat',
@@ -998,22 +998,11 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
       ], $membershipTypeParams);
       $this->ids['MembershipType'] = [$this->membershipTypeCreate($membershipTypeParams)];
     }
-    $this->setUpMembershipBlockPriceSet();
-    $this->setupPaymentProcessor();
     $contributionPageParameters = !$isRecur ? [] : [
       'is_recur' => TRUE,
       'recur_frequency_unit' => 'month',
     ];
-    $this->setUpContributionPage($contributionPageParameters, ['id' => $this->getPriceSetID('membership_block')]);
-
-    $this->callAPISuccess('MembershipBlock', 'create', [
-      'entity_id' => $this->getContributionPageID(),
-      'entity_table' => 'civicrm_contribution_page',
-      'is_required' => TRUE,
-      'is_active' => TRUE,
-      'is_separate_payment' => $isSeparatePayment,
-      'membership_type_default' => $this->ids['MembershipType'],
-    ]);
+    $this->contributionPageQuickConfigCreate($contributionPageParameters, [], $isSeparatePayment, TRUE, TRUE, TRUE);
   }
 
   /**
@@ -1520,7 +1509,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    */
   private function getSubmitParamsContributionPlusMembership(bool $isCardPayment = FALSE, string $membershipType = 'general'): array {
     $params = $this->getSubmitParamsMembership($isCardPayment, $membershipType);
-    $params[$this->getPriceFieldLabel('contribution')] = 1;
+    $params['price_' . $this->ids['PriceField']['other_amount']] = 88;
     return $params;
   }
 
@@ -1534,7 +1523,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    */
   protected function getSubmitParamsMembership(bool $isCardPayment = FALSE, string $membershipType = 'general'): array {
     $params = [
-      $this->getPriceFieldLabel('membership') => $this->getPriceFieldValue($membershipType),
+      'price_' . $this->ids['PriceField']['membership_amount'] => $this->ids['PriceFieldValue']['membership_' . $membershipType],
       'id' => $this->getContributionPageID(),
       'billing_first_name' => 'Billy',
       'billing_middle_name' => 'Goat',