From: Eileen McNaughton Date: Thu, 28 Jul 2022 09:18:28 +0000 (+0100) Subject: Minor test cleanup X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f740d864175207e84c1811e5289a961fbb3eede4;p=civicrm-core.git Minor test cleanup --- diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index 640e5b3395..96a55b4fc3 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -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. diff --git a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php index f85200729e..91e467eac7 100644 --- a/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php +++ b/tests/phpunit/CRM/Contact/Page/View/UserDashBoardTest.php @@ -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', diff --git a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php index bfd0ea40f0..5c45f8f176 100644 --- a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php +++ b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php @@ -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', diff --git a/tests/phpunit/CRM/Core/CopyTest.php b/tests/phpunit/CRM/Core/CopyTest.php index 8829447410..e34d5d3f92 100644 --- a/tests/phpunit/CRM/Core/CopyTest.php +++ b/tests/phpunit/CRM/Core/CopyTest.php @@ -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, diff --git a/tests/phpunit/CRM/Event/Form/ParticipantTest.php b/tests/phpunit/CRM/Event/Form/ParticipantTest.php index 33e303b762..59fdb82032 100644 --- a/tests/phpunit/CRM/Event/Form/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/Form/ParticipantTest.php @@ -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) diff --git a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php index 37c649339d..ab19da3b92 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/ConfirmTest.php @@ -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' => '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'], ], - '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)]); @@ -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' => 'Tiny-tots (ages 5-8) - 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' => '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(['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(); diff --git a/tests/phpunit/CRM/Event/Form/Registration/RegisterTest.php b/tests/phpunit/CRM/Event/Form/Registration/RegisterTest.php index c631141fef..5afe62c87e 100644 --- a/tests/phpunit/CRM/Event/Form/Registration/RegisterTest.php +++ b/tests/phpunit/CRM/Event/Form/Registration/RegisterTest.php @@ -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]); diff --git a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php index 52a5b3dc32..ef491e0656 100644 --- a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php +++ b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php @@ -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. diff --git a/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php b/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php index 533086074d..72ffc40df4 100644 --- a/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php +++ b/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php @@ -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); } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index b46a7d985d..567d4fe047 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -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]);