From ff04c5c35b163f89d5d0b66c4bef29cf3c5a2279 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 7 Sep 2023 08:40:31 +1200 Subject: [PATCH] Move scenario set up to trait --- .../Event/Form/Registration/ConfirmTest.php | 31 +------ .../phpunit/CRMTraits/Event/ScenarioTrait.php | 80 +++++++++++++++++++ 2 files changed, 82 insertions(+), 29 deletions(-) create mode 100644 tests/phpunit/CRMTraits/Event/ScenarioTrait.php diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index b529b561af..fa3bd7e005 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -10,6 +10,7 @@ use Civi\Test\FormTrait; */ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { + use CRMTraits_Event_ScenarioTrait; use CRMTraits_Financial_PriceSetTrait; use CRMTraits_Profile_ProfileTrait; use FormTrait; @@ -293,35 +294,7 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { public function testTaxMultipleParticipant(): void { $this->swapMessageTemplateForTestTemplate('event_online_receipt', 'text'); $this->createLoggedInUser(); - $this->eventCreatePaid(); - $this->addTaxAccountToFinancialType(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Event Fee')); - $form = $this->getTestForm('CRM_Event_Form_Registration_Register', [ - 'first_name' => 'Participant1', - 'last_name' => 'LastName', - 'email-Primary' => 'participant1@example.com', - 'additional_participants' => 2, - 'payment_processor_id' => 0, - 'priceSetId' => $this->getPriceSetID('PaidEvent'), - 'price_' . $this->ids['PriceField']['PaidEvent'] => $this->ids['PriceFieldValue']['PaidEvent_standard'], - 'defaultRole' => 1, - 'participant_role_id' => '1', - 'button' => '_qf_Register_upload', - ], ['id' => $this->getEventID()]) - ->addSubsequentForm('CRM_Event_Form_Registration_AdditionalParticipant', [ - 'first_name' => 'Participant2', - 'last_name' => 'LastName', - 'email-Primary' => 'participant2@example.com', - 'priceSetId' => $this->getPriceSetID('PaidEvent'), - 'price_' . $this->ids['PriceField']['PaidEvent'] => $this->ids['PriceFieldValue']['PaidEvent_standard'], - ])->addSubsequentForm('CRM_Event_Form_Registration_AdditionalParticipant', [ - 'first_name' => 'Participant3', - 'last_name' => 'LastName', - 'email-Primary' => 'participant3@example.com', - 'priceSetId' => $this->getPriceSetID('PaidEvent'), - 'price_' . $this->ids['PriceField']['PaidEvent'] => $this->ids['PriceFieldValue']['PaidEvent_standard'], - ]) - ->addSubsequentForm('CRM_Event_Form_Registration_Confirm') - ->processForm(); + $this->createScenarioMultipleParticipantPendingWithTax(); $participants = $this->callAPISuccess('Participant', 'get', [])['values']; $this->assertCount(3, $participants); diff --git a/tests/phpunit/CRMTraits/Event/ScenarioTrait.php b/tests/phpunit/CRMTraits/Event/ScenarioTrait.php new file mode 100644 index 0000000000..1922e35adb --- /dev/null +++ b/tests/phpunit/CRMTraits/Event/ScenarioTrait.php @@ -0,0 +1,80 @@ +eventCreatePaid(); + $this->addTaxAccountToFinancialType(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Event Fee')); + $this->getTestForm('CRM_Event_Form_Registration_Register', [ + 'first_name' => 'Participant1', + 'last_name' => 'LastName', + 'email-Primary' => 'participant1@example.com', + 'additional_participants' => 2, + 'payment_processor_id' => 0, + 'priceSetId' => $this->getPriceSetID('PaidEvent'), + 'price_' . $this->ids['PriceField']['PaidEvent'] => $this->ids['PriceFieldValue']['PaidEvent_standard'], + 'defaultRole' => 1, + 'participant_role_id' => '1', + 'button' => '_qf_Register_upload', + ], ['id' => $this->getEventID()]) + ->addSubsequentForm('CRM_Event_Form_Registration_AdditionalParticipant', [ + 'first_name' => 'Participant2', + 'last_name' => 'LastName', + 'email-Primary' => 'participant2@example.com', + 'priceSetId' => $this->getPriceSetID('PaidEvent'), + 'price_' . $this->ids['PriceField']['PaidEvent'] => $this->ids['PriceFieldValue']['PaidEvent_standard'], + ]) + ->addSubsequentForm('CRM_Event_Form_Registration_AdditionalParticipant', [ + 'first_name' => 'Participant3', + 'last_name' => 'LastName', + 'email-Primary' => 'participant3@example.com', + 'priceSetId' => $this->getPriceSetID('PaidEvent'), + 'price_' . $this->ids['PriceField']['PaidEvent'] => $this->ids['PriceFieldValue']['PaidEvent_standard'], + ]) + ->addSubsequentForm('CRM_Event_Form_Registration_Confirm') + ->processForm(); + $participants = Participant::get(FALSE) + ->addWhere('event_id', '=', $this->getEventID('PaidEvent')) + ->addOrderBy('registered_by_id') + ->execute(); + foreach ($participants as $index => $participant) { + $identifier = $participant['registered_by_id'] ? 'participant_' . $index : 'primary'; + $this->setTestEntity('Participant', $participant, $identifier); + $this->setTestEntityID('Contact', $participant['contact_id'], $identifier); + } + + } + +} -- 2.25.1