Move & improve test for Membership only, not separate payment
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 19 Nov 2023 21:26:29 +0000 (10:26 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 19 Nov 2023 21:32:50 +0000 (10:32 +1300)
CRM/Contribute/Form/Contribution/Main.php
Civi/Test/FormTrait.php
tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php
tests/phpunit/api/v3/ContributionPageTest.php

index 0b2ee65d92c0d11690569e880e9f57a46972fa3c..90d939c4b15ae2ed8dd6536921be081c0f7fd6f7 100644 (file)
@@ -551,7 +551,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
   }
 
   /**
-   * Get the idea of the other amount field if the form is configured to offer it.
+   * Get the ID of the other amount field if the form is configured to offer it.
    *
    * The other amount field is an alternative to the configured radio options,
    * specific to this form.
@@ -571,7 +571,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
   }
 
   /**
-   * Get the idea of the other amount field if the form is configured to offer an other amount.
+   * Get the ID of the main amount field if the form is configured to offer an other amount.
    *
    * The other amount field is an alternative to the configured radio options,
    * specific to this form.
index 77beefcc90d98e52d9b84409618d685f1e70a126..56944e05c704cb30116bb84ade5e14b814064c16 100644 (file)
@@ -65,7 +65,7 @@ trait FormTrait {
    */
   protected function assertMailSentContainingString(string $string, int $mailIndex = 0): void {
     $mail = $this->form->getMail()[$mailIndex];
-    $this->assertStringContainsString($string, $mail['body']);
+    $this->assertStringContainsString(preg_replace('/\s+/', '', $string), preg_replace('/\s+/', '', $mail['body']));
   }
 
   /**
index 47e0a3abbbf6f165ae83d9b80353c44f13f87695..facd0f11cc55c1068bf5ff39aaa8f429e6db9c12 100644 (file)
@@ -500,4 +500,33 @@ class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase {
     ], 1);
   }
 
+  /**
+   * Test submit opting for the membership and not the contribution.
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function testSubmitMembershipBlockNotSeparatePaymentMembershipOnly(): void {
+    $this->contributionPageQuickConfigCreate([], [], FALSE, TRUE, TRUE, TRUE);
+    $this->submitOnlineContributionForm([
+      'payment_processor_id' => $this->ids['PaymentProcessor']['dummy'],
+      'price_' . $this->ids['PriceField']['contribution_amount'] => -1,
+      'price_' . $this->ids['PriceField']['membership_amount'] => $this->ids['PriceFieldValue']['membership_general'],
+      'id' => $this->getContributionPageID(),
+    ] + $this->getBillingSubmitValues(),
+    $this->getContributionPageID());
+
+    $contribution = $this->callAPISuccess('Contribution', 'getsingle', ['contribution_page_id' => $this->getContributionPageID()]);
+    $membershipPayment = $this->callAPISuccess('MembershipPayment', 'getsingle', ['contribution_id' => $contribution['id']]);
+    $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id'], 'entity_id' => $membershipPayment['id']]);
+    $this->assertMailSentContainingStrings([
+      'Dear Dave,',
+      'Membership Information',
+      'Membership Type General',
+      'Membership Start Date',
+      'Membership Expiration',
+      'Membership Fee',
+      'Amount $100.00',
+    ]);
+  }
+
 }
index 557152140cb0d354b1fbe5652ee85381207a5b60..bdf9d9a9e435a2cafa874ad0a4dd58c2db4fd81d 100644 (file)
@@ -271,25 +271,6 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     ], 'online');
   }
 
-  /**
-   * Test submit with a membership block in place.
-   */
-  public function testSubmitMembershipBlockNotSeparatePayment(): void {
-    $this->setUpMembershipContributionPage(FALSE, FALSE, ['minimum_fee' => 0]);
-    $submitParams = [
-      $this->getPriceFieldLabel('membership') => $this->getPriceFieldValue('general'),
-      'id' => $this->getContributionPageID(),
-      'billing_first_name' => 'Billy',
-      'billing_middle_name' => 'Goat',
-      'billing_last_name' => 'Gruff',
-    ];
-
-    $this->callAPISuccess('ContributionPage', 'submit', $submitParams);
-    $contribution = $this->callAPISuccess('Contribution', 'getsingle', ['contribution_page_id' => $this->getContributionPageID()]);
-    $membershipPayment = $this->callAPISuccess('MembershipPayment', 'getsingle', ['contribution_id' => $contribution['id']]);
-    $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id'], 'entity_id' => $membershipPayment['id']]);
-  }
-
   /**
    * Test submit with a membership block in place works with renewal.
    *