From 62759d667891e97feff9f74c7c7eb8eeae98bb5c Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 30 Nov 2021 12:06:05 +1300 Subject: [PATCH] Fix membership test to use full flow --- .../CRM/Member/Form/MembershipTest.php | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index f4e24abc7d..97b8847d78 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -1012,7 +1012,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception */ - public function testSubmitUpdateMembershipFromPartiallyPaid() { + public function testSubmitUpdateMembershipFromPartiallyPaid(): void { $memStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'validate'); //Perform a pay later membership contribution. @@ -1029,18 +1029,19 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'total_amount' => 5, ]); - // Complete the contribution from offline form. - $form = new CRM_Contribute_Form_Contribution(); $submitParams = [ 'id' => $contribution['contribution_id'], 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'), - 'price_set_id' => 0, ]; $fields = ['total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'contact_id', 'payment_instrument_id']; foreach ($fields as $val) { $submitParams[$val] = $prevContribution[$val]; } - $form->testSubmit($submitParams, CRM_Core_Action::UPDATE); + $_REQUEST['action'] = 'update'; + $_REQUEST['id'] = $contribution['contribution_id']; + // Complete the contribution from offline form. + $form = $this->getContributionForm($submitParams); + $form->postProcess(); //Check if Membership is updated to New. $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]); @@ -1378,7 +1379,6 @@ Expires: ', * Test membership status overrides when contribution is cancelled. * * @throws \CRM_Core_Exception - * @throws \CiviCRM_API3_Exception */ public function testContributionFormStatusUpdate(): void { // @todo figure out why financial validation fails with this test. @@ -1393,13 +1393,10 @@ Expires: ', 'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'), 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Cancelled'), ]; - - //Update Contribution to Cancelled. - $form = new CRM_Contribute_Form_Contribution(); - $form->_id = $params['id'] = $this->ids['Contribution'][0]; - $form->_mode = NULL; - $form->_contactID = $this->_individualId; - $form->testSubmit($params, CRM_Core_Action::UPDATE); + $_REQUEST['action'] = 'update'; + $_REQUEST['id'] = $this->ids['Contribution'][0]; + $form = $this->getContributionForm($params); + $form->postProcess(); $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_contactID]); //Assert membership status overrides when the contribution cancelled. @@ -1410,6 +1407,20 @@ Expires: ', ])); } + /** + * Get the contribution form object. + * + * @param array $formValues + * + * @return \CRM_Contribute_Form_Contribution + */ + protected function getContributionForm(array $formValues): CRM_Contribute_Form_Contribution { + /* @var CRM_Contribute_Form_Contribution $form */ + $form = $this->getFormObject('CRM_Contribute_Form_Contribution', $formValues); + $form->buildForm(); + return $form; + } + /** * CRM-21656: Test the submit function of the membership form if Sales Tax is enabled. * This test simulates what happens when one hits Edit on a Contribution that has both LineItems and Sales Tax components -- 2.25.1