Fix forms to call full form flow
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 1 Sep 2023 08:12:40 +0000 (20:12 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 1 Sep 2023 08:40:15 +0000 (20:40 +1200)
tests/phpunit/CRM/Event/Form/ParticipantTest.php

index 61a76d437227883ca09f5f6a9f9258f5e6382006..ccc9da5661a68490a2e5ac79c83135ee8c2f95e0 100644 (file)
@@ -378,8 +378,11 @@ London,',
    * @throws \CRM_Core_Exception
    */
   protected function createParticipantRecordsFromTwoFieldPriceSet(): void {
-    // Create financial type - Event Fee 2
-    $form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1]);
+    $submittedValues['contact_id'] = $this->ids['Contact']['event'] = $this->individualCreate();
+    $event = $this->eventCreatePaid([
+      'confirm_email_text' => "Just do it\n Now",
+      'is_show_location' => TRUE,
+    ]);
 
     $textFieldsToCreate = [['amount' => 10, 'label' => 'First Text field'], ['amount' => 55, 'label' => 'Second Text field']];
     foreach ($textFieldsToCreate as $fieldToCreate) {
@@ -401,52 +404,13 @@ London,',
       $this->ids['PriceField'][strtolower($fieldParams['name'])] = $textPriceFieldID = $this->callAPISuccess('PriceField', 'create', $fieldParams)['id'];
       $this->ids['PriceFieldValue'][strtolower($fieldParams['name'])] = (int) $this->callAPISuccess('PriceFieldValue', 'getsingle', ['price_field_id' => $textPriceFieldID])['id'];
     }
-
-    $form->_lineItem = [
-      0 => [
-        13 => [
-          'price_field_id' => $this->ids['PriceField']['second_text_field'],
-          'price_field_value_id' => $this->ids['PriceFieldValue']['second_text_field'],
-          'label' => 'Event Fee 1',
-          'field_title' => 'Event Fee 1',
-          'description' => NULL,
-          'qty' => 1,
-          'unit_price' => 55.00,
-          'line_total' => 55.,
-          'participant_count' => 0,
-          'max_value' => NULL,
-          'membership_type_id' => NULL,
-          'membership_num_terms' => NULL,
-          'auto_renew' => NULL,
-          'html_type' => 'Text',
-          'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'),
-          'tax_amount' => NULL,
-          'non_deductible_amount' => '0.00',
-        ],
-        14 => [
-          'price_field_id' => $this->ids['PriceField']['first_text_field'],
-          'price_field_value_id' => $this->ids['PriceFieldValue']['first_text_field'],
-          'label' => 'Event Fee 2',
-          'field_title' => 'Event Fee 2',
-          'description' => NULL,
-          'qty' => 1,
-          'unit_price' => 10.00,
-          'line_total' => 10,
-          'participant_count' => 0,
-          'max_value' => NULL,
-          'membership_type_id' => NULL,
-          'membership_num_terms' => NULL,
-          'auto_renew' => NULL,
-          'html_type' => 'Text',
-          'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'),
-          'tax_amount' => NULL,
-          'non_deductible_amount' => '0.00',
-        ],
-      ],
-    ];
-    $form->setAction(CRM_Core_Action::ADD);
-    $form->_priceSetId = $this->getPriceSetID('PaidEvent');
-
+    $submittedValues = array_merge($this->getRecordContributionParams('Partially paid'), $submittedValues);
+    $submittedValues['event_id'] = $event['id'];
+    $_REQUEST['cid'] = $submittedValues['contact_id'];
+    /** @var CRM_Event_Form_Participant $form */
+    $form = $this->getFormObject('CRM_Event_Form_Participant', $submittedValues);
+    $form->preProcess();
+    $form->buildForm();
     $form->submit([
       'register_date' => date('Ymd'),
       'receive_date' => '2018-09-01',