Fix test to use full flow
authorEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 11 Apr 2022 02:16:32 +0000 (14:16 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 11 Apr 2022 02:51:59 +0000 (14:51 +1200)
CRM/Event/Form/Registration/Confirm.php
tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index f1fcdc57ceefcf98e7470cf9c03367b9b2b1c3f6..85ff949b6edd0134a4141ccce14c2fafe37ad48b 100644 (file)
@@ -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) {
index 2f57e086fdb9e6d1862e75d183ff2439080a7c81..9503d80789c19629a724a73b3a2954c0eec624b9 100644 (file)
@@ -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&amp;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' => '\ 1Tiny-tots (ages 5-8) - 1\ 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' => '\ 1Tiny-tots (ages 5-8) - 1\ 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&amp;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&amp;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' => '\ 1Tiny-tots (ages 5-8) - 1\ 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' => '\ 1Tiny-tots (ages 5-8) - 1\ 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();
+  }
+
 }
index bcb7849dc78cf3f3a08fb04bf4d6d2949ff6806b..eff00f48b3a9ca3bfb8f0a12f251bad7b454eb94 100644 (file)
@@ -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;