Use EventTest helpers (a few more places)
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 7 Jun 2023 22:47:11 +0000 (10:47 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 7 Jun 2023 22:47:11 +0000 (10:47 +1200)
tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php
tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php
tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php
tests/phpunit/CRM/Event/Form/ManageEvent/LocationTest.php

index b9076c26cc964481f050ea5d39b978d2694c7a8a..920cfa878dce681ba516854446d12fd5ad21b278 100644 (file)
@@ -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([
index 959d063748c6d381f9025c2f8afbc6be69bccddb..4efdb2204429d363871ab465e2a6c43954db7167 100644 (file)
@@ -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().
    *
index 9b9ef44e347758e37931751b74c1526e83bcc932..9ac465eb4e60d81e6e2ac664dc704f05c37e545b 100644 (file)
  */
 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.');
   }
 
   /**
index 24dcb83f63a87213dd6ef250ca4fec8ddd3f412c..035806843aac0af4d75eb5b3a27bbd3c4cb10027 100644 (file)
@@ -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')