From bff6a70cda66210f14f73910a5ae78cd89570579 Mon Sep 17 00:00:00 2001 From: Deepak Srivastava Date: Fri, 20 May 2022 16:42:33 +0100 Subject: [PATCH] test case for missing contactID when registering for paid event from waitlist - https://github.com/civicrm/civicrm-core/pull/23358 --- CRM/Event/Form/Registration/Confirm.php | 1 + .../Event/Form/Registration/ConfirmTest.php | 155 ++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/CRM/Event/Form/Registration/Confirm.php b/CRM/Event/Form/Registration/Confirm.php index f5849d307675..4049c358995b 100644 --- a/CRM/Event/Form/Registration/Confirm.php +++ b/CRM/Event/Form/Registration/Confirm.php @@ -1255,6 +1255,7 @@ public static function testSubmit($params) { $form->_paymentProcessor = $params['paymentProcessorObj']; } $form->postProcess(); + return $form; } /** diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index 1accc8e26259..5477de3bce4f 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -217,6 +217,161 @@ public function testPaidSubmit($thousandSeparator) { $mut->clearMessages(); } + /** + * Tests missing contactID when registering for paid event from waitlist + * https://github.com/civicrm/civicrm-core/pull/23358, https://lab.civicrm.org/extensions/stripe/-/issues/347 + * + * @throws \CiviCRM_API3_Exception + */ + public function testWaitlistRegistrationContactIdParam() { + // @todo - figure out why this doesn't pass validate financials + $this->isValidateFinancialsOnPostAssert = FALSE; + $paymentProcessorID = $this->processorCreate(); + /* @var \CRM_Core_Payment_Dummy $processor */ + $processor = Civi\Payment\System::singleton()->getById($paymentProcessorID); + $processor->setDoDirectPaymentResult(['fee_amount' => 1.67]); + $params = ['is_monetary' => 1, 'financial_type_id' => 1]; + $event = $this->eventCreate($params); + $individualID = $this->individualCreate(); + $form = CRM_Event_Form_Registration_Confirm::testSubmit([ + 'id' => $event['id'], + 'contributeMode' => 'direct', + 'registerByID' => $individualID, + 'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID), + 'totalAmount' => $this->formatMoneyInput(8000.67), + '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' => date('Y') + 1, + ], + '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' => $paymentProcessorID, + 'bypass_payment' => '', + 'is_primary' => 1, + 'is_pay_later' => 0, + 'contact_id' => $individualID, + 'campaign_id' => NULL, + 'defaultRole' => 1, + 'participant_role_id' => '1', + 'currencyID' => 'USD', + 'amount_level' => 'Tiny-tots (ages 5-8) - 1', + 'amount' => $this->formatMoneyInput(8000.67), + '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->callAPISuccessGetCount('Participant', [], 1); + $contribution = $this->callAPISuccessGetSingle('Contribution', []); + $this->assertEquals(8000.67, $contribution['total_amount']); + $this->assertEquals(1.67, $contribution['fee_amount']); + $this->assertEquals(7999, $contribution['net_amount']); + + $value = $form->get('value'); + $this->assertArrayHasKey('contact_id', $value, 'contact_id missing in $value array'); + $this->assertEquals($value['contact_id'], $individualID, 'Invalid contact_id in $value array.'); + + // Add someone to the waitlist. + $waitlistContactId = $this->individualCreate(); + $waitlistContact = $this->callAPISuccess('Contact', 'getsingle', ['id' => $waitlistContactId]); + $waitlistParticipantId = $this->participantCreate(['event_id' => $event['id'], 'contact_id' => $waitlistContactId, 'status_id' => 'On waitlist']); + + $waitlistParticipant = $this->callAPISuccess('Participant', 'getsingle', ['id' => $waitlistParticipantId, 'return' => ["participant_status"]]); + $this->assertEquals($waitlistParticipant['participant_status'], 'On waitlist', 'Invalid participant status. Expecting: On waitlist'); + + $form = CRM_Event_Form_Registration_Confirm::testSubmit([ + 'id' => $event['id'], + 'contributeMode' => 'direct', + 'registerByID' => $waitlistContactId, + 'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID), + 'totalAmount' => $this->formatMoneyInput(8000.67), + 'params' => [ + [ + 'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801', + 'entryURL' => 'http://dmaster.local/civicrm/event/register?reset=1&id=3', + 'first_name' => $waitlistContact['first_name'], + 'last_name' => $waitlistContact['last_name'], + 'email-Primary' => $waitlistContact['email'], + 'hidden_processor' => '1', + 'credit_card_number' => '4111111111111111', + 'cvv2' => '123', + 'credit_card_exp_date' => [ + 'M' => '1', + 'Y' => date('Y') + 1, + ], + 'credit_card_type' => 'Visa', + 'billing_first_name' => $waitlistContact['first_name'], + 'billing_middle_name' => '', + 'billing_last_name' => $waitlistContact['last_name'], + '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' => $paymentProcessorID, + 'bypass_payment' => '', + 'is_primary' => 1, + 'is_pay_later' => 0, + 'participant_id' => $waitlistParticipantId, + 'campaign_id' => NULL, + 'defaultRole' => 1, + 'participant_role_id' => '1', + 'currencyID' => 'USD', + 'amount_level' => 'Tiny-tots (ages 5-8) - 1', + 'amount' => $this->formatMoneyInput(8000.67), + 'tax_amount' => NULL, + 'year' => '2019', + 'month' => '1', + 'ip_address' => '127.0.0.1', + 'invoiceID' => '68adc34957a29171948e8643ce906332', + 'button' => '_qf_Register_upload', + 'billing_state_province-5' => 'AP', + 'billing_country-5' => 'US', + ], + ], + ]); + $this->callAPISuccessGetCount('Participant', [], 2); + $this->callAPISuccessGetCount('Contribution', [], 2); + + $waitlistParticipant = $this->callAPISuccess('Participant', 'getsingle', ['id' => $waitlistParticipantId, 'return' => ["participant_status"]]); + $this->assertEquals($waitlistParticipant['participant_status'], 'Registered', 'Invalid participant status. Expecting: Registered'); + + $value = $form->get('value'); + $this->assertArrayHasKey('contact_id', $value, 'contact_id missing in waitlist registration $value array'); + $this->assertEquals($value['contact_id'], $waitlistParticipant['contact_id'], 'Invalid contact_id in waitlist $value array.'); + } + /** * Test for Tax amount for multiple participant. *