Test tearDown fixes
[civicrm-core.git] / tests / phpunit / CRM / Case / BAO / CaseTest.php
index 588162c30d9804f69ae473feb650271529425bf8..251c2b6f613c0798b98791a06a3429fc45585296 100644 (file)
@@ -18,6 +18,8 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase {
       'civicrm_case_contact',
       'civicrm_case_activity',
       'civicrm_case_type',
+      'civicrm_file',
+      'civicrm_entity_file',
       'civicrm_activity_contact',
       'civicrm_managed',
       'civicrm_relationship',
@@ -37,7 +39,7 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase {
   /**
    * Make sure that the latest case activity works accurately.
    */
-  public function testCaseActivity() {
+  public function testCaseActivity(): void {
     $userID = $this->createLoggedInUser();
 
     $addTimeline = civicrm_api3('Case', 'addtimeline', [
@@ -57,8 +59,8 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase {
   }
 
   protected function tearDown(): void {
-    parent::tearDown();
     $this->quickCleanup($this->tablesToTruncate, TRUE);
+    parent::tearDown();
   }
 
   public function testAddCaseToContact() {
@@ -1201,4 +1203,35 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase {
     $this->assertArrayHasKey($caseId, CRM_Case_BAO_Case::getCases(FALSE, ['type' => 'any']));
   }
 
+  /**
+   * Test a high number of assigned case roles.
+   */
+  public function testGoingTo11() {
+    $loggedInUser = $this->createLoggedInUser();
+    $individual = $this->individualCreate();
+    $caseObj = $this->createCase($individual, $loggedInUser);
+    $caseId = $caseObj->id;
+
+    // Create lots of assigned roles
+    for ($i = 1; $i <= 30; $i++) {
+      // create a new type
+      $relationship_type_id = $this->callAPISuccess('RelationshipType', 'create', [
+        'name_a_b' => "has as Wizard level $i",
+        'name_b_a' => "is Wizard level $i for",
+      ])['id'];
+
+      // Now make a new person and give them the role
+      $contact_id = $this->individualCreate([], 0, TRUE);
+      $this->callAPISuccess('Relationship', 'create', [
+        'case_id' => $caseId,
+        'contact_id_a' => $individual,
+        'contact_id_b' => $contact_id,
+        'relationship_type_id' => $relationship_type_id,
+      ]);
+    }
+
+    // Note the stock case type adds a manager role for the logged in user so it's 31 not 30.
+    $this->assertCount(31, CRM_Case_BAO_Case::getCaseRoles($individual, $caseId), 'Why not just make ten louder?');
+  }
+
 }