SearchKit - Change @searchable annotation from boolean to option list
[civicrm-core.git] / tests / phpunit / api / v4 / Entity / ConformanceTest.php
index e9ec92d78eb51bb2afaf5ed5f22028174adef3b4..43af883e7159ff95f772aa55bbc8786c70171276 100644 (file)
@@ -43,6 +43,7 @@ class ConformanceTest extends UnitTestCase {
    */
   public function setUp(): void {
     $tablesToTruncate = [
+      'civicrm_case_type',
       'civicrm_custom_group',
       'civicrm_custom_field',
       'civicrm_group',
@@ -52,6 +53,7 @@ class ConformanceTest extends UnitTestCase {
     $this->dropByPrefix('civicrm_value_myfavorite');
     $this->cleanup(['tablesToTruncate' => $tablesToTruncate]);
     $this->setUpOptionCleanup();
+    $this->loadDataSet('CaseType');
     $this->loadDataSet('ConformanceTest');
     $this->creationParamProvider = \Civi::container()->get('test.param_provider');
     parent::setUp();
@@ -71,13 +73,9 @@ class ConformanceTest extends UnitTestCase {
    */
   public function getEntitiesHitech() {
     // Ensure all components are enabled so their entities show up
-    \CRM_Core_BAO_ConfigSetting::enableComponent('CiviEvent');
-    \CRM_Core_BAO_ConfigSetting::enableComponent('CiviGrant');
-    \CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
-    \CRM_Core_BAO_ConfigSetting::enableComponent('CiviContribute');
-    \CRM_Core_BAO_ConfigSetting::enableComponent('CiviCampaign');
-    \CRM_Core_BAO_ConfigSetting::enableComponent('CiviPledge');
-    \CRM_Core_BAO_ConfigSetting::enableComponent('CiviReport');
+    foreach (array_keys(\CRM_Core_Component::getComponents()) as $component) {
+      \CRM_Core_BAO_ConfigSetting::enableComponent($component);
+    }
     return $this->toDataProviderArray(Entity::get(FALSE)->execute()->column('name'));
   }
 
@@ -93,11 +91,13 @@ class ConformanceTest extends UnitTestCase {
   public function getEntitiesLotech() {
     $manual['add'] = [];
     $manual['remove'] = ['CustomValue'];
+    $manual['transform'] = ['CiviCase' => 'Case'];
 
     $scanned = [];
     $srcDir = dirname(__DIR__, 5);
     foreach ((array) glob("$srcDir/Civi/Api4/*.php") as $name) {
-      $scanned[] = preg_replace('/\.php/', '', basename($name));
+      $fileName = basename($name, '.php');
+      $scanned[] = $manual['transform'][$fileName] ?? $fileName;
     }
 
     $names = array_diff(
@@ -156,6 +156,11 @@ class ConformanceTest extends UnitTestCase {
     $this->assertNotEmpty($info['title_plural']);
     $this->assertNotEmpty($info['type']);
     $this->assertNotEmpty($info['description']);
+    $this->assertContains($info['searchable'], ['primary', 'secondary', 'none']);
+    // Bridge must be between exactly 2 entities
+    if (in_array('EntityBridge', $info['type'], TRUE)) {
+      $this->assertCount(2, $info['bridge']);
+    }
   }
 
   /**
@@ -173,7 +178,8 @@ class ConformanceTest extends UnitTestCase {
     $errMsg = sprintf('%s is missing required ID field', $entity);
     $subset = ['data_type' => 'Integer'];
 
-    $this->assertArraySubset($subset, $fields['id'], $errMsg);
+    $this->assertArrayHasKey('data_type', $fields['id'], $errMsg);
+    $this->assertEquals('Integer', $fields['id']['data_type']);
   }
 
   /**
@@ -228,7 +234,7 @@ class ConformanceTest extends UnitTestCase {
     catch (\API_Exception $e) {
       $exceptionThrown = $e->getMessage();
     }
-    $this->assertContains('id', $exceptionThrown);
+    $this->assertStringContainsString('id', $exceptionThrown);
   }
 
   /**
@@ -278,7 +284,7 @@ class ConformanceTest extends UnitTestCase {
     catch (\API_Exception $e) {
       $exceptionThrown = $e->getMessage();
     }
-    $this->assertContains('required', $exceptionThrown);
+    $this->assertStringContainsString('required', $exceptionThrown);
   }
 
   /**
@@ -294,8 +300,8 @@ class ConformanceTest extends UnitTestCase {
     catch (\API_Exception $e) {
       $exceptionThrown = $e->getMessage();
     }
-    $this->assertContains('debug', $exceptionThrown);
-    $this->assertContains('type', $exceptionThrown);
+    $this->assertStringContainsString('debug', $exceptionThrown);
+    $this->assertStringContainsString('type', $exceptionThrown);
   }
 
   /**