From 1093ee40f93830904d1cb418c15232808efd170c Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Sat, 23 Oct 2021 10:28:31 +1300 Subject: [PATCH] Fix more tests to use the full form flow --- .../tests/phpunit/CancelTest.php | 15 ++++++------- tests/phpunit/api/v3/ContributionTest.php | 21 +++++++------------ tests/phpunit/api/v3/MembershipTest.php | 15 +++++++------ 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/ext/contributioncancelactions/tests/phpunit/CancelTest.php b/ext/contributioncancelactions/tests/phpunit/CancelTest.php index 431e728ee0..30ed165d18 100644 --- a/ext/contributioncancelactions/tests/phpunit/CancelTest.php +++ b/ext/contributioncancelactions/tests/phpunit/CancelTest.php @@ -105,7 +105,6 @@ class CancelTest extends TestCase implements HeadlessInterface, HookInterface, T /** * Create an order with more than one membership. * - * @throws \CRM_Core_Exception */ protected function createMembershipOrder(): void { $priceFieldID = $this->callAPISuccessGetValue('price_field', [ @@ -182,9 +181,8 @@ class CancelTest extends TestCase implements HeadlessInterface, HookInterface, T * @param array $params * * @return int - * @throws \CRM_Core_Exception */ - public function createPaymentProcessor($params = []): int { + public function createPaymentProcessor(array $params = []): int { $params = array_merge([ 'name' => 'demo', 'domain_id' => CRM_Core_Config::domainID(), @@ -245,7 +243,6 @@ class CancelTest extends TestCase implements HeadlessInterface, HookInterface, T /** * Test cancel order api * @throws API_Exception - * @throws CRM_Core_Exception */ public function testCancelOrderWithParticipant(): void { $this->createContact(); @@ -261,8 +258,6 @@ class CancelTest extends TestCase implements HeadlessInterface, HookInterface, T * form. * * @throws \API_Exception - * @throws \CRM_Core_Exception - * @throws \CiviCRM_API3_Exception */ public function testCancelFromContributionForm(): void { $this->createContact(); @@ -270,7 +265,6 @@ class CancelTest extends TestCase implements HeadlessInterface, HookInterface, T $this->createMembershipOrder(); $this->createLoggedInUser(); $formValues = [ - 'id' => $this->ids['Contribution'][0], 'contact_id' => $this->ids['contact'][0], 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Cancelled'), ]; @@ -278,7 +272,11 @@ class CancelTest extends TestCase implements HeadlessInterface, HookInterface, T $_SERVER['REQUEST_METHOD'] = 'GET'; $form->controller = new CRM_Core_Controller(); $form->controller->setStateMachine(new CRM_Core_StateMachine($form->controller)); - $form->testSubmit($formValues, CRM_Core_Action::UPDATE); + $_SESSION['_' . $form->controller->_name . '_container']['values']['Contribution'] = $formValues; + $_REQUEST['action'] = 'update'; + $_REQUEST['id'] = $this->ids['Contribution'][0]; + $form->buildForm(); + $form->postProcess(); $contribution = Contribution::get() ->addWhere('id', '=', $this->ids['Contribution'][0]) @@ -300,7 +298,6 @@ class CancelTest extends TestCase implements HeadlessInterface, HookInterface, T * * @return int * @throws API_Exception - * @throws CRM_Core_Exception */ protected function createEventOrder(): int { $this->ids['event'][0] = (int) Event::create()->setValues(['title' => 'Event', 'start_date' => 'tomorrow', 'event_type_id:name' => 'Workshop'])->execute()->first()['id']; diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 4d9dc491cf..ece83491bd 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -3449,9 +3449,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * Test if renewal activity is create after changing Pending contribution to * Completed via offline * - * @throws \CRM_Core_Exception - * @throws \CRM_Core_Exception - * @throws \CiviCRM_API3_Exception + * @throws \CRM_Core_Exception|\CiviCRM_API3_Exception */ public function testPendingToCompleteContribution(): void { $this->createPriceSetWithPage('membership'); @@ -3464,12 +3462,11 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'status_id' => 'Scheduled', ]); $this->assertEquals(1, $activity['count']); - + $_REQUEST['id'] = $this->getContributionID(); + $_REQUEST['action'] = 'update'; // change pending contribution to completed - $form = new CRM_Contribute_Form_Contribution(); - - $form->_params = [ - 'id' => $this->getContributionID(), + /* @var CRM_Contribute_Form_Contribution $form */ + $form = $this->getFormObject('CRM_Contribute_Form_Contribution', [ 'total_amount' => 20, 'net_amount' => 20, 'fee_amount' => 0, @@ -3489,15 +3486,13 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'hidden_AdditionalDetail' => 1, 'hidden_Premium' => 1, 'from_email_address' => '"civi45" ', - 'receipt_date' => '', - 'receipt_date_time' => '', 'payment_processor_id' => $this->paymentProcessorID, 'currency' => 'USD', 'contribution_page_id' => $this->_ids['contribution_page'], 'source' => 'Membership Signup and Renewal', - ]; - - $form->testSubmit($form->_params, CRM_Core_Action::UPDATE); + ]); + $form->buildForm(); + $form->postProcess(); // Case 2: After successful payment for Pending backoffice there are three activities created // 2.a Update status of existing Scheduled Membership Signup (created in step 1) to Completed diff --git a/tests/phpunit/api/v3/MembershipTest.php b/tests/phpunit/api/v3/MembershipTest.php index 2cb2d31be3..a723c55880 100644 --- a/tests/phpunit/api/v3/MembershipTest.php +++ b/tests/phpunit/api/v3/MembershipTest.php @@ -151,7 +151,6 @@ class api_v3_MembershipTest extends CiviUnitTestCase { * Test Activity creation on cancellation of membership contribution. * * @throws \CRM_Core_Exception - * @throws \CiviCRM_API3_Exception */ public function testActivityForCancelledContribution(): void { // @todo figure out why financial validation fails with this test. @@ -160,16 +159,20 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $this->createContributionAndMembershipOrder(); $membershipID = $this->callAPISuccessGetValue('MembershipPayment', ['return' => 'id']); - $form = new CRM_Contribute_Form_Contribution(); - $form->_id = $this->ids['Contribution'][0]; - $form->testSubmit([ + + $_REQUEST['id'] = $this->ids['Contribution'][0]; + $_REQUEST['action'] = 'update'; + // change pending contribution to completed + /* @var CRM_Contribute_Form_Contribution $form */ + $form = $this->getFormObject('CRM_Contribute_Form_Contribution', [ 'total_amount' => 100, 'financial_type_id' => 1, 'contact_id' => $contactId, 'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'), 'contribution_status_id' => 3, - ], - CRM_Core_Action::UPDATE); + ]); + $form->buildForm(); + $form->postProcess(); $this->callAPISuccessGetSingle('Activity', [ 'activity_type_id' => 'Membership Signup', -- 2.25.1