[Test] Extend new membership form to cover multi-line renew
authoreileen <emcnaughton@wikimedia.org>
Sun, 17 Jan 2021 21:15:00 +0000 (10:15 +1300)
committereileen <emcnaughton@wikimedia.org>
Sun, 17 Jan 2021 21:15:00 +0000 (10:15 +1300)
CRM/Member/Form.php
tests/phpunit/CRM/Member/Form/MembershipTest.php

index 292cef47b8d9bab282f584fbf9d5cb4d440ffa3c..497047739d1f952fd54c5aabcd1ba77d6434e168 100644 (file)
@@ -466,7 +466,7 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
    *
    * @param array $formValues
    */
-  public function testSubmit($formValues) {
+  public function testSubmit(array $formValues): void {
     $this->setContextVariables($formValues);
     $this->_memType = $formValues['membership_type_id'][1];
     $this->_params = $formValues;
index 4ed9865863fb6d2a61ab5d4c54772be802f496b5..3a00ecbe26190d398178b4514b37c215844c5d06 100644 (file)
@@ -769,17 +769,15 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
       'label' => 'PendingEdited',
     ]);
 
-    $form = $this->getForm();
-
     $this->callAPISuccess('MembershipType', 'create', [
       'id' => $this->ids['membership_type']['AnnualFixed'],
       'duration_unit' => 'month',
       'duration_interval' => 1,
       'auto_renew' => TRUE,
     ]);
-    $form->preProcess();
-    $this->createLoggedInUser();
     $params = $this->getBaseSubmitParams();
+    $form = $this->getForm();
+    $this->createLoggedInUser();
     $form->_mode = 'test';
     $form->_contactID = $this->_individualId;
     $form->testSubmit($params);
@@ -813,9 +811,33 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
     ], CRM_Core_Session::singleton()->getStatus());
   }
 
-  public function testSubmitRecurTwoRows() {
-    $this->createMembershipPriceSet();
+  /**
+   * Test submit recurring with two line items.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
+   */
+  public function testSubmitRecurTwoRows(): void {
+    $pfvIDs = $this->createMembershipPriceSet();
     $form = $this->getForm();
+    $form->_mode = 'live';
+    $priceParams = [
+      'price_' . $this->getPriceFieldID() => $pfvIDs,
+      'price_set_id' => $this->getPriceSetID(),
+      'frequency_interval' => 1,
+      'frequency_unit' => 'month',
+      'membership_type_id' => NULL,
+    ];
+    $form->testSubmit(array_merge($this->getBaseSubmitParams(), $priceParams));
+    $memberships = $this->callAPISuccess('Membership', 'get')['values'];
+    $this->assertCount(2, $memberships);
+    $this->callAPISuccessGetSingle('Contribution', []);
+    $this->callAPISuccessGetCount('MembershipPayment', [], 2);
+    $lines = $this->callAPISuccess('LineItem', 'get', ['sequential' => 1])['values'];
+    $this->assertCount(2, $lines);
+    $this->assertEquals('civicrm_membership', $lines[0]['entity_table']);
+    $this->assertEquals('civicrm_membership', $lines[1]['entity_table']);
+
   }
 
   /**
@@ -1177,10 +1199,12 @@ Expires: ',
   /**
    * Get a membership form object.
    *
-   * We need to instantiate the form to run preprocess, which means we have to trick it about the request method.
+   * We need to instantiate the form to run preprocess, which means we have to
+   * trick it about the request method.
    *
    * @return \CRM_Member_Form_Membership
    * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   protected function getForm() {
     if (isset($_REQUEST['cid'])) {
@@ -1189,6 +1213,7 @@ Expires: ',
     $form = new CRM_Member_Form_Membership();
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $form->controller = new CRM_Core_Controller();
+    $form->preProcess();
     return $form;
   }