Minor test cleanup
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 28 Jul 2022 09:18:28 +0000 (10:18 +0100)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 30 Jul 2022 09:51:06 +0000 (10:51 +0100)
CRM/Event/Form/Registration/Register.php
tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php
tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php
tests/phpunit/CRM/Core/CopyTest.php
tests/phpunit/CRM/Event/Form/ParticipantTest.php
tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php
tests/phpunit/CRM/Event/Form/Registration/RegisterTest.php
tests/phpunit/CRM/Utils/TokenConsistencyTest.php
tests/phpunit/CRMTraits/Custom/CustomDataTrait.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index 640e5b339500ad34fd3e4fcfbbfc79fd29682584..96a55b4fc3a8710b3c38f80a6419512d4e27e98f 100644 (file)
@@ -310,7 +310,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
         $unsetSubmittedOptions[$val['id']] = $optionFullIds;
       }
       //reset values for all options those are full.
-      CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
+      CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions ?? [], $this);
     }
 
     //set default participant fields, CRM-4320.
index f85200729e6fa22cc688e3f8511f1236327c8e0d..91e467eac767f89befe7e5b84fc1608dc784f08d 100644 (file)
@@ -162,16 +162,16 @@ class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase {
    * @throws \CRM_Core_Exception
    * @throws \CiviCRM_API3_Exception
    */
-  public function testDashboardPartialPayments() {
+  public function testDashboardPartialPayments(): void {
     $contributionId = $this->contributionCreate([
       'contact_id' => $this->contactID,
       'contribution_status_id' => 'Pending',
       'total_amount' => 25,
     ]);
-    $result = civicrm_api3('Payment', 'create', [
+    $this->callAPISuccess('Payment', 'create', [
       'contribution_id' => $contributionId,
       'total_amount' => 11,
-      'trxn_date' => "2021-05-11",
+      'trxn_date' => '2021-05-11',
     ]);
     $this->contributions[] = civicrm_api3('Contribution', 'get', [
       'contact_id' => $this->contactID,
@@ -205,7 +205,7 @@ class CRM_Contact_Page_View_UserDashBoardTest extends CiviUnitTestCase {
   /**
    * Tests the event dashboard as a minimally permissioned user.
    */
-  public function testEventDashboard() {
+  public function testEventDashboard(): void {
     CRM_Core_Config::singleton()->userPermissionClass->permissions = [
       'register for events',
       'access Contact Dashboard',
index bfd0ea40f081993dca431ac7c3ad62658606f323..5c45f8f17680bf41c9b3f44720f31b5e9b0ddb4c 100644 (file)
@@ -2204,7 +2204,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase {
     $actionSchedule['start_action_offset'] = 7;
     $actionSchedule['start_action_unit'] = 'day';
     $actionSchedule['start_action_date'] = 'registration_end_date';
-    $actionSchedule['entity_value'] = $event['values'][$event['id']]['event_type_id'];
+    $actionSchedule['entity_value'] = $event['event_type_id'];
     $actionSchedule['entity_status'] = $this->callAPISuccessGetValue('ParticipantStatusType', [
       'return' => 'id',
       'name' => 'Attended',
index 8829447410738ff558042f8848648f847e99cbeb..e34d5d3f9298d10a9b6acfd7f0bd823739e802e9 100644 (file)
@@ -22,9 +22,9 @@ class CRM_Core_CopyTest extends CiviUnitTestCase {
   public function testEventCopy(): void {
 
     $this->createCustomGroupWithFieldOfType(['extends' => 'Event']);
-    $event = $this->eventCreate([$this->getCustomFieldName('text') => 'blah']);
+    $event = $this->eventCreate([$this->getCustomFieldName('text', 4) => 'blah']);
     $eventId = $event['id'];
-    $eventRes = $event['values'][$eventId];
+    $eventRes = $event;
     $params[$this->getCustomFieldName('text') . '_1'] = 'blah';
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params,
       $eventId,
index 33e303b76256a54a94bd7f5d32ecdea39ff62c57..59fdb82032cce9bcfe82f1f6b56a44fd91856213 100644 (file)
@@ -130,7 +130,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
    * @throws \CRM_Core_Exception
    * @throws \CiviCRM_API3_Exception
    */
-  public function testPaymentAllocationOnMultiLineItemEvent() {
+  public function testPaymentAllocationOnMultiLineItemEvent(): void {
     // USE-CASE :
     // 1. Create a Price set with two price fields
     // 2. Register for a Event using both the price field A($55 - qty 1) and B($10 - qty 1)
index 37c649339d7f2ef2f8371a22672955dbda90ef18..ab19da3b92cbc15a6d1902102604697e67dc25e3 100644 (file)
@@ -10,17 +10,6 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
 
   use CRMTraits_Profile_ProfileTrait;
 
-
-  /**
-   * Should financials be checked after the test but before tear down.
-   *
-   * Ideally all tests (or at least all that call any financial api calls ) should do this but there
-   * are some test data issues and some real bugs currently blocking.
-   *
-   * @var bool
-   */
-  protected $isValidateFinancialsOnPostAssert = TRUE;
-
   public function setUp(): void {
     $this->useTransaction(TRUE);
     parent::setUp();
@@ -376,7 +365,7 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
    * @throws \CRM_Core_Exception
    * @throws \Exception
    */
-  public function testTaxMultipleParticipant() {
+  public function testTaxMultipleParticipant(): void {
     // @todo - figure out why this doesn't pass validate financials
     $this->isValidateFinancialsOnPostAssert = FALSE;
     $mut = new CiviMailUtils($this);
@@ -388,7 +377,7 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
       'contributeMode' => 'direct',
       'registerByID' => $this->createLoggedInUser(),
       'totalAmount' => 440,
-      'event' => reset($event['values']),
+      'event' => $event,
       'params' => [
         [
           'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
@@ -452,8 +441,8 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
       ]
     );
     $this->assertContains(' (multiple participants)', $contribution['amount_level']);
-    $this->assertEquals($contribution['tax_amount'], 40, 'Invalid Tax amount.');
-    $this->assertEquals($contribution['total_amount'], 440, 'Invalid Tax amount.');
+    $this->assertEquals(40, $contribution['tax_amount'], 'Invalid Tax amount.');
+    $this->assertEquals(440, $contribution['total_amount'], 'Invalid Tax amount.');
     $mailSent = $mut->getAllMessages();
     $this->assertCount(3, $mailSent, 'Three mails should have been sent to the 3 participants.');
     $this->assertStringContainsString('contactID:::' . $contribution['contact_id'], $mailSent[0]);
@@ -503,30 +492,31 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
     );
     // Create online event registration.
     $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',
+      $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.");
+    $this->assertEquals('0', $contribution['count'], 'Contribution should not be created for zero fee event registration when no price field selected.');
   }
 
   /**
@@ -535,7 +525,7 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
    * @throws \CRM_Core_Exception
    * @throws \Exception
    */
-  public function testAssignProfiles() {
+  public function testAssignProfiles(): void {
     $event = $this->eventCreate();
     $this->createJoinedProfile(['entity_table' => 'civicrm_event', 'entity_id' => $event['id']]);
 
@@ -544,7 +534,7 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
     $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm');
     $form->set('params', [[]]);
     $form->set('values', [
-      'event' => $event['values'][$event['id']],
+      'event' => $event,
       'location' => [],
       'custom_pre_id' => $this->ids['UFGroup']['our profile'],
     ]);
@@ -564,59 +554,61 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
    * Submit event registration with a note field
    *
    * @param array $event
-   * @param int $contact_id
+   * @param int|null $contact_id
    *
    * @return array
    * @throws \Exception
    */
-  private function submitWithNote($event, $contact_id) {
-    if (empty($contact_id)) {
+  private function submitWithNote(array $event, ?int $contact_id): array {
+    if ($contact_id === NULL) {
       $contact_id = $this->createLoggedInUser();
     }
     $mut = new CiviMailUtils($this, TRUE);
     $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,
+      [
+        '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'],
       ],
-      '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)]);
@@ -630,13 +622,12 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
    * Create an event with a "pre" profile
    *
    * @throws \CRM_Core_Exception
-   * @throws \Exception
    */
-  private function creatEventWithProfile($event) {
+  private function creatEventWithProfile($event): array {
     if (empty($event)) {
       $event = $this->eventCreate();
       $this->createJoinedProfile(['entity_table' => 'civicrm_event', 'entity_id' => $event['id']]);
-      $this->uf_field_add($this->ids["UFGroup"]["our profile"], 'note', 'Contact', 'Comment');
+      $this->uf_field_add($this->ids['UFGroup']['our profile'], 'note', 'Contact', 'Comment');
     }
 
     $_REQUEST['id'] = $event['id'];
@@ -644,7 +635,7 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
     $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm');
     $form->set('params', [[]]);
     $form->set('values', [
-      'event' => $event['values'][$event['id']],
+      'event' => $event,
       'location' => [],
       'custom_pre_id' => $this->ids['UFGroup']['our profile'],
     ]);
@@ -707,14 +698,14 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
     //now that the contact has one note, register this contact again with a different note
     //and confirm that the note shown in the email is the current one
     $event = $this->creatEventWithProfile($event);
-    $event['custom_pre_id'] = $this->ids["UFGroup"]["our profile"];
+    $event['custom_pre_id'] = $this->ids['UFGroup']['our profile'];
     $event['note'] = 'This is note 2';
     [$contact_id, $participant_id] = $this->submitWithNote($event, $contact_id);
     civicrm_api3('Participant', 'delete', ['id' => $participant_id]);
 
     //finally, submit a blank note and confirm that the note shown in the email is blank
     $event = $this->creatEventWithProfile($event);
-    $event['custom_pre_id'] = $this->ids["UFGroup"]["our profile"];
+    $event['custom_pre_id'] = $this->ids['UFGroup']['our profile'];
     $event['note'] = '';
     $this->submitWithNote($event, $contact_id);
   }
@@ -728,48 +719,48 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
     $event = $this->eventCreate();
     $mut = new CiviMailUtils($this, TRUE);
     $this->submitForm($event['id'], [
-      'first_name' => 'k',
-      'last_name' => 'p',
-      'email-Other' => 'nonprimaryemail@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,
+      [
+        'first_name' => 'k',
+        'last_name' => 'p',
+        'email-Other' => 'nonprimaryemail@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',
+        'invoiceID' => '57adc34957a29171948e8643ce906332',
+        'button' => '_qf_Register_upload',
+        'billing_state_province-5' => 'AP',
+        'billing_country-5' => 'US',
       ],
-      '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',
     ]);
     $mut->checkMailLog(['nonprimaryemail@example.com']);
     $mut->stop();
@@ -787,8 +778,14 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
    */
   protected function submitForm(int $eventID, array $params): void {
     $_REQUEST['id'] = $eventID;
+    $form = $this->getFormObject('CRM_Event_Form_Registration_Register', $params);
+    $form->buildForm();
+    $form->postProcess();
     $form = $this->getFormObject('CRM_Event_Form_Registration_Confirm', []);
-    $form->set('params', [$params]);
+    if (!isset($params[0])) {
+      $params = [$params];
+    }
+    $form->set('params', $params);
     $form->set('registerByID', $this->createLoggedInUser());
     $form->buildForm();
     $form->postProcess();
index c631141fef6b9278f54b25134bad34186543820c..5afe62c87e7ba89fe33297f52db380d685469307 100644 (file)
@@ -28,7 +28,7 @@ class CRM_Event_Form_Registration_RegisterTest extends CiviUnitTestCase {
     $priceSetId = $this->eventPriceSetCreate($feeAmt, $minAmt);
     $priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
     $form->_values['fee'] = $form->_feeBlock = $priceSet['fields'];
-    $form->_values['event'] = $event['values'][$event['id']];
+    $form->_values['event'] = $event;
     $form->_skipDupeRegistrationCheck = 1;
 
     $priceField = $this->callAPISuccess('PriceField', 'get', ['price_set_id' => $priceSetId]);
index 52a5b3dc32f89c48cbec4cf6ba39edefeb662929..ef491e0656c50ab8dfe6a3c0efc379d2edf5b73c 100644 (file)
@@ -973,7 +973,7 @@ United States', $tokenProcessor->getRow(0)->render('message'));
       'description' => 'event description',
       'end_date' => 20081023,
       'registration_end_date' => 20081015,
-      $this->getCustomFieldName('text') => 'my field',
+      $this->getCustomFieldName('text', 4) => 'my field',
       'loc_block_id' => $locationBlockID,
     ])['id'];
     // Create an unrelated participant record so that the ids don't match.
index 533086074d0d01e67a9be6b7391b58ef9876911d..72ffc40df455665b55bbe801041be87878786339 100644 (file)
@@ -169,10 +169,19 @@ trait CRMTraits_Custom_CustomDataTrait {
    * Generally keys map to data types.
    *
    * @param string $key
+   * @param int $version
    *
    * @return string
+   *
+   * @noinspection PhpDocMissingThrowsInspection
+   * @noinspection PhpUnhandledExceptionInspection
    */
-  protected function getCustomFieldName(string $key): string {
+  protected function getCustomFieldName(string $key, $version = 3): string {
+    if ($version === 4) {
+      $field = CustomField::get(FALSE)->addWhere('id', '=', $this->getCustomFieldID($key))
+        ->addSelect('name', 'custom_group_id.name')->execute()->first();
+      return $field['custom_group_id.name'] . '.' . $field['name'];
+    }
     return 'custom_' . $this->getCustomFieldID($key);
   }
 
index b46a7d985d00c5776a9d46d84f29a524166f8a6c..567d4fe047bb875f8988b51b7be9ccbef4586e9c 100644 (file)
@@ -30,6 +30,7 @@ use Civi\Api4\Address;
 use Civi\Api4\Contribution;
 use Civi\Api4\CustomField;
 use Civi\Api4\CustomGroup;
+use Civi\Api4\Event;
 use Civi\Api4\FinancialAccount;
 use Civi\Api4\FinancialType;
 use Civi\Api4\LineItem;
@@ -921,10 +922,11 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    */
   public function dummyProcessorCreate($processorParams = []) {
     $paymentProcessorID = $this->processorCreate($processorParams);
+    $this->ids['PaymentProcessor']['dummy_test'] = $paymentProcessorID;
     // For the tests we don't need a live processor, but as core ALWAYS creates a processor in live mode and one in test mode we do need to create both
     //   Otherwise we are testing a scenario that only exists in tests (and some tests fail because the live processor has not been defined).
     $processorParams['is_test'] = FALSE;
-    $this->processorCreate($processorParams);
+    $this->ids['PaymentProcessor']['dummy_live'] = $this->processorCreate($processorParams);
     return System::singleton()->getById($paymentProcessorID);
   }
 
@@ -1101,6 +1103,9 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    *   Name-value pair for an event.
    *
    * @return array
+   *
+   * @noinspection PhpUnhandledExceptionInspection
+   * @noinspection PhpDocMissingThrowsInspection
    */
   public function eventCreate(array $params = []): array {
     // if no contact was passed, make up a dummy event creator
@@ -1128,11 +1133,12 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
       'event_full_text' => 'Sorry! We are already full',
       'is_monetary' => 0,
       'is_active' => 1,
+      'default_role_id' => 1,
       'is_show_location' => 0,
       'is_email_confirm' => 1,
     ], $params);
 
-    $event = $this->callAPISuccess('Event', 'create', $params);
+    $event = Event::create(FALSE)->setValues($params)->execute()->first();
     $this->ids['event'][] = $event['id'];
     return $event;
   }
@@ -1151,9 +1157,17 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    *
    * @throws \CRM_Core_Exception
    */
-  protected function eventCreatePaid($params, $options = [['name' => 'hundy', 'amount' => 100]], $key = 'event') {
-    $params['is_monetary'] = TRUE;
+  protected function eventCreatePaid(array $params, array $options = [['name' => 'hundy', 'amount' => 100]], $key = 'event'): array {
+    // @todo - uncomment these - but need to fix an e-notice first.
+    // $this->dummyProcessorCreate();
+    // $params['payment_processor'] = [$this->ids['PaymentProcessor']['dummy_live']];
+    $params = array_merge([
+      'is_monetary' => TRUE,
+      'financial_type_id:name' => 'Event Fee',
+    ], $params);
+
     $event = $this->eventCreate($params);
+
     $this->ids['Event'][$key] = (int) $event['id'];
     $this->ids['PriceSet'][$key] = $this->eventPriceSetCreate(55, 0, 'Radio', $options);
     CRM_Price_BAO_PriceSet::addTo('civicrm_event', $event['id'], $this->ids['PriceSet'][$key]);