From d026b890e5d74fd9ce395a38c23852931b50cfb3 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 11 Apr 2022 14:16:32 +1200 Subject: [PATCH] Fix test to use full flow --- CRM/Event/Form/Registration/Confirm.php | 6 + .../Event/Form/Registration/ConfirmTest.php | 269 +++++++++--------- tests/phpunit/CiviTest/CiviUnitTestCase.php | 4 + 3 files changed, 139 insertions(+), 140 deletions(-) diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index f1fcdc57ce..85ff949b6e 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -1225,6 +1225,12 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration { /** * Submit in test mode. * + * Do not use this - we have figured out how to emulate form in tests now. + * + * See ConfirmTest. + * + * @deprecated + * * @param $params */ public static function testSubmit($params) { diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index 2f57e086fd..9503d80789 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -28,64 +28,52 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { /** * Initial test of submit function. - * - * @throws \Exception */ public function testSubmit(): void { $event = $this->eventCreate(); $mut = new CiviMailUtils($this, TRUE); - CRM_Event_Form_Registration_Confirm::testSubmit([ - 'id' => $event['id'], - 'contributeMode' => 'direct', - 'registerByID' => $this->createLoggedInUser(), - 'params' => [ - [ - 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', - 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3', - 'first_name' => 'k', - 'last_name' => 'p', - 'email-Primary' => 'demo@example.com', - 'hidden_processor' => '1', - 'credit_card_number' => '4111111111111111', - 'cvv2' => '123', - 'credit_card_exp_date' => [ - 'M' => '1', - 'Y' => '2019', - ], - 'credit_card_type' => 'Visa', - 'billing_first_name' => 'p', - 'billing_middle_name' => '', - 'billing_last_name' => 'p', - 'billing_street_address-5' => 'p', - 'billing_city-5' => 'p', - 'billing_state_province_id-5' => '1061', - 'billing_postal_code-5' => '7', - 'billing_country_id-5' => '1228', - 'priceSetId' => '6', - 'price_7' => [ - 13 => 1, - ], - 'payment_processor_id' => '1', - 'bypass_payment' => '', - 'MAX_FILE_SIZE' => '33554432', - 'is_primary' => 1, - 'is_pay_later' => 0, - 'campaign_id' => NULL, - 'defaultRole' => 1, - 'participant_role_id' => '1', - 'currencyID' => 'USD', - 'amount_level' => 'Tiny-tots (ages 5-8) - 1', - 'amount' => '800.00', - 'tax_amount' => NULL, - 'year' => '2019', - 'month' => '1', - 'ip_address' => '127.0.0.1', - 'invoiceID' => '57adc34957a29171948e8643ce906332', - 'button' => '_qf_Register_upload', - 'billing_state_province-5' => 'AP', - 'billing_country-5' => 'US', - ], + $this->submitForm($event['id'], [ + 'first_name' => 'k', + 'last_name' => 'p', + 'email-Primary' => 'demo@example.com', + 'hidden_processor' => '1', + 'credit_card_number' => '4111111111111111', + 'cvv2' => '123', + 'credit_card_exp_date' => [ + 'M' => '1', + 'Y' => '2019', + ], + 'credit_card_type' => 'Visa', + 'billing_first_name' => 'p', + 'billing_middle_name' => '', + 'billing_last_name' => 'p', + 'billing_street_address-5' => 'p', + 'billing_city-5' => 'p', + 'billing_state_province_id-5' => '1061', + 'billing_postal_code-5' => '7', + 'billing_country_id-5' => '1228', + 'priceSetId' => '6', + 'price_7' => [ + 13 => 1, ], + 'payment_processor_id' => '1', + 'bypass_payment' => '', + 'is_primary' => 1, + 'is_pay_later' => 0, + 'campaign_id' => NULL, + 'defaultRole' => 1, + 'participant_role_id' => '1', + 'currencyID' => 'USD', + 'amount_level' => 'Tiny-tots (ages 5-8) - 1', + 'amount' => '800.00', + 'tax_amount' => NULL, + 'year' => '2019', + 'month' => '1', + 'ip_address' => '127.0.0.1', + 'invoiceID' => '57adc34957a29171948e8643ce906332', + 'button' => '_qf_Register_upload', + 'billing_state_province-5' => 'AP', + 'billing_country-5' => 'US', ]); $mut->checkMailLog([ @@ -219,7 +207,8 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { 'amount' => '1.67', ], $entityFinancialTrxns[2], ['id', 'entity_id']); $mut->checkMailLog([ - 'Event Information and Location', 'Registration Confirmation - Annual CiviCRM meet', + 'Event Information and Location', + 'Registration Confirmation - Annual CiviCRM meet', 'Expires: January ' . (date('Y') + 1), 'Visa', '************1111', @@ -333,7 +322,7 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { /** * Test online registration for event with no price options selected as per CRM-19964. */ - public function testOnlineRegNoPrice() { + public function testOnlineRegNoPrice(): void { $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => FALSE]); $paymentProcessorID = $this->processorCreate(['is_default' => TRUE, 'user_name' => 'Test', 'is_test' => TRUE]); $params = [ @@ -360,36 +349,29 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { ] ); // Create online event registration. - CRM_Event_Form_Registration_Confirm::testSubmit([ - 'id' => $event['id'], - 'contributeMode' => 'direct', - 'registerByID' => $this->createLoggedInUser(), - 'totalAmount' => 0, - 'params' => [ - [ - 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', - 'entryURL' => "http://dmaster.local/civicrm/event/register?reset=1&id={$event['id']}", - 'first_name' => 'Bruce', - 'last_name' => 'Wayne', - 'email-Primary' => 'bruce@gotham.com', - 'price_' . $priceField['id'] => '', - 'priceSetId' => $priceField['values'][$priceField['id']]['price_set_id'], - 'payment_processor_id' => $paymentProcessorID, - 'amount' => 0, - 'bypass_payment' => '', - 'MAX_FILE_SIZE' => '33554432', - 'is_primary' => 1, - 'is_pay_later' => 0, - 'campaign_id' => NULL, - 'defaultRole' => 1, - 'participant_role_id' => '1', - 'tax_amount' => NULL, - 'ip_address' => '127.0.0.1', - 'invoiceID' => '57adc34957a29171948e8643ce906332', - 'button' => '_qf_Register_upload', - ], - ], - ]); + $this->submitForm( + $event['id'], + [ + 'first_name' => 'Bruce', + 'last_name' => 'Wayne', + 'email-Primary' => 'bruce@gotham.com', + 'price_' . $priceField['id'] => '', + 'priceSetId' => $priceField['values'][$priceField['id']]['price_set_id'], + 'payment_processor_id' => $paymentProcessorID, + 'amount' => 0, + 'amount_level' => '', + 'bypass_payment' => '', + 'is_primary' => 1, + 'is_pay_later' => 0, + 'campaign_id' => NULL, + 'defaultRole' => 1, + 'participant_role_id' => '1', + 'tax_amount' => NULL, + 'ip_address' => '127.0.0.1', + 'invoiceID' => '57adc34957a29171948e8643ce906332', + 'button' => '_qf_Register_upload', + ] + ); $contribution = $this->callAPISuccess('Contribution', 'get', ['invoice_id' => '57adc34957a29171948e8643ce906332']); $this->assertEquals($contribution['count'], '0', "Contribution should not be created for zero fee event registration when no price field selected."); } @@ -404,10 +386,10 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { $event = $this->eventCreate(); $this->createJoinedProfile(['entity_table' => 'civicrm_event', 'entity_id' => $event['id']]); + $_REQUEST['id'] = $event['id']; /* @var \CRM_Event_Form_Registration_Confirm $form */ $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm'); $form->set('params', [[]]); - $form->set('id', $event['id']); $form->set('values', [ 'event' => $event['values'][$event['id']], 'location' => [], @@ -439,60 +421,49 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { $contact_id = $this->createLoggedInUser(); } $mut = new CiviMailUtils($this, TRUE); - CRM_Event_Form_Registration_Confirm::testSubmit([ - 'id' => $event['id'], - 'contributeMode' => 'direct', - 'registerByID' => $contact_id, - 'custom_pre_id' => $event['custom_pre_id'], - 'params' => [ - [ - 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', - 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3', - 'first_name' => 'k', - 'last_name' => 'p', - 'email-Primary' => 'demo@example.com', - 'hidden_processor' => '1', - 'credit_card_number' => '4111111111111111', - 'cvv2' => '123', - 'credit_card_exp_date' => [ - 'M' => '1', - 'Y' => '2019', - ], - 'credit_card_type' => 'Visa', - 'billing_first_name' => 'p', - 'billing_middle_name' => '', - 'billing_last_name' => 'p', - 'billing_street_address-5' => 'p', - 'billing_city-5' => 'p', - 'billing_state_province_id-5' => '1061', - 'billing_postal_code-5' => '7', - 'billing_country_id-5' => '1228', - 'priceSetId' => '6', - 'price_7' => [ - 13 => 1, - ], - 'payment_processor_id' => '1', - 'bypass_payment' => '', - 'MAX_FILE_SIZE' => '33554432', - 'is_primary' => 1, - 'is_pay_later' => 0, - 'campaign_id' => NULL, - 'defaultRole' => 1, - 'participant_role_id' => '1', - 'currencyID' => 'USD', - 'amount_level' => 'Tiny-tots (ages 5-8) - 1', - 'amount' => '800.00', - 'tax_amount' => NULL, - 'year' => '2019', - 'month' => '1', - 'ip_address' => '127.0.0.1', - 'invoiceID' => '57adc34957a29171948e8643ce906332', - 'button' => '_qf_Register_upload', - 'billing_state_province-5' => 'AP', - 'billing_country-5' => 'US', - 'note' => $event['note'], - ], + $this->submitForm($event['id'], [ + 'first_name' => 'k', + 'last_name' => 'p', + 'email-Primary' => 'demo@example.com', + 'hidden_processor' => '1', + 'credit_card_number' => '4111111111111111', + 'cvv2' => '123', + 'credit_card_exp_date' => [ + 'M' => '1', + 'Y' => '2019', ], + 'credit_card_type' => 'Visa', + 'billing_first_name' => 'p', + 'billing_middle_name' => '', + 'billing_last_name' => 'p', + 'billing_street_address-5' => 'p', + 'billing_city-5' => 'p', + 'billing_state_province_id-5' => '1061', + 'billing_postal_code-5' => '7', + 'billing_country_id-5' => '1228', + 'priceSetId' => '6', + 'price_7' => [ + 13 => 1, + ], + 'payment_processor_id' => '1', + 'bypass_payment' => '', + 'is_primary' => 1, + 'is_pay_later' => 0, + 'campaign_id' => NULL, + 'defaultRole' => 1, + 'participant_role_id' => '1', + 'currencyID' => 'USD', + 'amount_level' => 'Tiny-tots (ages 5-8) - 1', + 'amount' => '800.00', + 'tax_amount' => NULL, + 'year' => '2019', + 'month' => '1', + 'ip_address' => '127.0.0.1', + 'invoiceID' => '57adc34957a29171948e8643ce906332', + 'button' => '_qf_Register_upload', + 'billing_state_province-5' => 'AP', + 'billing_country-5' => 'US', + 'note' => $event['note'], ]); $participant = $this->callAPISuccessGetSingle('Participant', []); $mut->checkMailLog(['Comment: ' . $event['note'] . chr(0x0A)]); @@ -515,10 +486,10 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { $this->uf_field_add($this->ids["UFGroup"]["our profile"], 'note', 'Contact', 'Comment'); } + $_REQUEST['id'] = $event['id']; /* @var \CRM_Event_Form_Registration_Confirm $form */ $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm'); $form->set('params', [[]]); - $form->set('id', $event['id']); $form->set('values', [ 'event' => $event['values'][$event['id']], 'location' => [], @@ -663,4 +634,22 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase { $mut->clearMessages(); } + /** + * Submit the confirm form. + * + * @param int $eventID + * @param array $params + * Array that would be stored in the form as params at this point. + * (ideally we will move to submitted rather than processed values + * in time). + */ + protected function submitForm(int $eventID, array $params): void { + $_REQUEST['id'] = $eventID; + $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm', []); + $form->set('params', [$params]); + $form->set('registerByID', $this->createLoggedInUser()); + $form->buildForm(); + $form->postProcess(); + } + } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index bcb7849dc7..eff00f48b3 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3215,6 +3215,10 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { $form->controller = new CRM_Event_Cart_Controller_Checkout(); break; + case 'CRM_Event_Form_Registration_Confirm': + $form->controller = new CRM_Event_Controller_Registration(); + break; + case strpos($class, '_Form_') !== FALSE: $form->controller = new CRM_Core_Controller_Simple($class, $pageName); break; -- 2.25.1