From b3721acefb754cc5e64bc6a799450b49d44ef37c Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 8 Jun 2023 10:47:11 +1200 Subject: [PATCH] Use EventTest helpers (a few more places) --- .../CRM/Core/BAO/ActionScheduleTest.php | 14 +++-------- .../CRM/Core/BAO/FinancialTrxnTest.php | 5 ++++ .../CRM/Core/BAO/RecurringEntityTest.php | 21 +++++++++------- .../Event/Form/ManageEvent/LocationTest.php | 25 ++++++++++++------- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php index b9076c26cc..920cfa878d 100644 --- a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php +++ b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php @@ -853,18 +853,13 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { * @throws \CRM_Core_Exception */ public function tearDown(): void { - $this->deleteTestObjects(); + $this->quickCleanUpFinancialEntities(); MembershipType::delete()->addWhere('name', 'NOT IN', ['General', 'Student', 'Lifetime'])->execute(); $this->quickCleanup([ 'civicrm_action_schedule', 'civicrm_action_log', - 'civicrm_membership', - 'civicrm_line_item', - 'civicrm_participant', - 'civicrm_event', 'civicrm_email', ], TRUE); - $this->quickCleanUpFinancialEntities(); parent::tearDown(); } @@ -2168,8 +2163,8 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'registration_start_date' => date('Ymd', strtotime('-5 day')), 'registration_end_date' => date('Ymd', strtotime('+7 day')), ]; - $event = $this->eventCreate($params); - $this->participantCreate(['contact_id' => $contact, 'event_id' => $event['id']]); + $event = $this->eventCreateUnpaid($params); + $this->participantCreate(['contact_id' => $contact, 'event_id' => $this->getEventID()]); //Create a scheduled reminder to send email 7 days before registration date. $actionSchedule = $this->fixtures['sched_event_type_start_1week_before']; @@ -2198,8 +2193,7 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { //Create an event with registration end date = 2 week from now. $params['end_date'] = date('Ymd', strtotime('+2 week')); $params['registration_end_date'] = date('Ymd', strtotime('+2 week')); - $event2 = $this->eventCreate($params); - $this->participantCreate(['contact_id' => $contact2, 'event_id' => $event2['id']]); + $this->participantCreate(['contact_id' => $contact2, 'event_id' => $this->eventCreateUnpaid($params, 'event_2')['id']]); //Assert there is no reminder sent to the contact. $this->assertCronRuns([ diff --git a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php index 959d063748..4efdb22044 100644 --- a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php +++ b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php @@ -17,6 +17,11 @@ use Civi\Api4\Contribution; */ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { + public function tearDown(): void { + $this->quickCleanUpFinancialEntities(); + parent::tearDown(); + } + /** * Check method create(). * diff --git a/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php b/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php index 9b9ef44e34..9ac465eb4e 100644 --- a/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php +++ b/tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php @@ -15,6 +15,11 @@ */ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { + public function tearDown(): void { + $this->quickCleanUpFinancialEntities(); + parent::tearDown(); + } + /** * Testing Activity Generation through Entity Recursion. */ @@ -84,11 +89,10 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { "start_action_date" => date("YmdHis"), "repetition_frequency_unit" => "week", "repetition_frequency_interval" => "3", - "start_action_condition" => "monday,tuesday,wednesday,thursday,friday,saturday", - "start_action_offset" => "2", + "start_action_condition" => 'monday,tuesday,wednesday,thursday,friday,saturday', + 'start_action_offset' => 2, ]; - $actionScheduleObj = CRM_Core_BAO_ActionSchedule::writeRecord($params); - return $actionScheduleObj; + return CRM_Core_BAO_ActionSchedule::writeRecord($params); } /** @@ -121,11 +125,10 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { /** * Testing Event Generation through Entity Recursion. */ - public function testRepeatEventCreation() { - $event = $this->eventCreate(); - $entity_table = "civicrm_event"; + public function testRepeatEventCreation(): void { + $event = $this->eventCreatePaid(); + $entity_table = 'civicrm_event'; $entity_id = $event["id"]; - CRM_Price_BAO_PriceSet::addTo($entity_table, $entity_id, 1); $actionScheduleObj = $this->createActionSchedule($entity_id, $entity_table); $recurringEntities = $this->createRecurringEntities($actionScheduleObj, $entity_id, $entity_table); $finalResult = CRM_Core_BAO_RecurringEntity::updateModeAndPriceSet($entity_id, $entity_table, CRM_Core_BAO_RecurringEntity::MODE_ALL_ENTITY_IN_SERIES, [], 2); @@ -134,7 +137,7 @@ class CRM_Core_BAO_RecurringEntityTest extends CiviUnitTestCase { $priceSetOne = CRM_Price_BAO_PriceSet::getFor($entity_table, $recurringEntities["civicrm_price_set_entity"][0]); $priceSetTwo = CRM_Price_BAO_PriceSet::getFor($entity_table, $recurringEntities["civicrm_price_set_entity"][1]); $this->assertEquals(2, $priceSetOne, "Price set id of the recurring event is not updated."); - $this->assertEquals(2, $priceSetTwo, "Price set id of the recurring event is not updated."); + $this->assertEquals(2, $priceSetTwo, 'Price set id of the recurring event is not updated.'); } /** diff --git a/tests/phpunit/CRM/Event/Form/ManageEvent/LocationTest.php b/tests/phpunit/CRM/Event/Form/ManageEvent/LocationTest.php index 24dcb83f63..035806843a 100644 --- a/tests/phpunit/CRM/Event/Form/ManageEvent/LocationTest.php +++ b/tests/phpunit/CRM/Event/Form/ManageEvent/LocationTest.php @@ -2,6 +2,7 @@ use Civi\Api4\Event; use Civi\Api4\Email; +use Civi\Api4\Generic\Result; /** * Test CRM_Event_Form_Registration functions. @@ -11,14 +12,19 @@ use Civi\Api4\Email; */ class CRM_Event_Form_ManageEvent_LocationTest extends CiviUnitTestCase { + public function tearDown(): void { + $this->quickCleanUpFinancialEntities(); + parent::tearDown(); + } + /** * Test the right emails exist after submitting the location form twice. * * @throws \CRM_Core_Exception * @throws \Civi\API\Exception\UnauthorizedException */ - public function testSubmit() { - $eventID = (int) $this->eventCreate()['id']; + public function testSubmit(): void { + $eventID = (int) $this->eventCreateUnpaid()['id']; $this->submitForm([], $eventID); $this->assertCorrectEmails($eventID); @@ -31,9 +37,11 @@ class CRM_Event_Form_ManageEvent_LocationTest extends CiviUnitTestCase { * Create() method * create various elements of location block * with civicrm_loc_block + * + * @throws \CRM_Core_Exception */ - public function testCreateWithLocBlock() { - $eventID = (int) $this->eventCreate()['id']; + public function testCreateWithLocBlock(): void { + $eventID = (int) $this->eventCreateUnpaid()['id']; $this->submitForm([ 'address' => [ '1' => [ @@ -115,8 +123,8 @@ class CRM_Event_Form_ManageEvent_LocationTest extends CiviUnitTestCase { * @throws \CRM_Core_Exception * @throws \Civi\API\Exception\UnauthorizedException */ - public function testUpdateLocationBlock() { - $eventID = (int) $this->eventCreate()['id']; + public function testUpdateLocationBlock(): void { + $eventID = (int) $this->eventCreateUnpaid()['id']; $this->submitForm([ 'address' => [ '1' => [ @@ -183,7 +191,7 @@ class CRM_Event_Form_ManageEvent_LocationTest extends CiviUnitTestCase { * * @return array */ - protected function getFormValues() { + protected function getFormValues(): array { return [ 'address' => [ @@ -241,9 +249,8 @@ class CRM_Event_Form_ManageEvent_LocationTest extends CiviUnitTestCase { * * @return \Civi\Api4\Generic\Result * @throws \CRM_Core_Exception - * @throws \Civi\API\Exception\UnauthorizedException */ - protected function assertCorrectEmails($eventID) { + protected function assertCorrectEmails(int $eventID): Result { $emails = Email::get() ->addWhere('email', 'IN', ['bigger_party@example.org', 'celebration@example.org']) ->addOrderBy('email', 'DESC') -- 2.25.1