From e8a645ac2dee505df8fa4f738f01e7a1f0e49cdc Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 18 Jan 2021 10:15:00 +1300 Subject: [PATCH] [Test] Extend new membership form to cover multi-line renew --- CRM/Member/Form.php | 2 +- .../CRM/Member/Form/MembershipTest.php | 39 +++++++++++++++---- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index 292cef47b8..497047739d 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -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; diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index 4ed9865863..3a00ecbe26 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -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; } -- 2.25.1