Merge pull request #11250 from agh1/no-update-indices
[civicrm-core.git] / tests / phpunit / Civi / Core / CiviEventInspectorTest.php
index 0cdc90f8b63b8f6d385dba05b25eb0fb920a818b..144232d50f709c39ecb1da4899e913849e0bf814 100644 (file)
@@ -9,13 +9,17 @@ class CiviEventInspectorTest extends \CiviUnitTestCase {
 
   public function testGet() {
     $inspector = new CiviEventInspector();
-    $hook = $inspector->get('hook_civicrm_alterSettingsMetaData');
-    $this->assertEquals('hook_civicrm_alterSettingsMetaData', $hook['name']);
-    $this->assertEquals(array('settingsMetaData', 'domainID', 'profile'), array_keys($hook['fields']));
-    $this->assertTrue($hook['fields']['settingsMetaData']['ref']);
-    $this->assertFalse($hook['fields']['domainID']['ref']);
-    $this->assertEquals('&$settingsMetaData, $domainID, $profile', $hook['signature']);
-    $this->assertTrue($inspector->validate($hook));
+    $eventDef = $inspector->get('hook_civicrm_alterSettingsMetaData');
+    $this->assertEquals('hook_civicrm_alterSettingsMetaData', $eventDef['name']);
+    $this->assertEquals(array('settingsMetaData', 'domainID', 'profile'), array_keys($eventDef['fields']));
+    $this->assertEquals('hook', $eventDef['type']);
+    $this->assertNotEmpty($eventDef['description_html']);
+    $this->assertTrue($eventDef['fields']['settingsMetaData']['ref']);
+    $this->assertFalse($eventDef['fields']['domainID']['ref']);
+    $this->assertEquals('&$settingsMetaData, $domainID, $profile', $eventDef['signature']);
+    $this->assertTrue($inspector->validate($eventDef));
+    $this->assertTrue($eventDef['stub'] instanceof \ReflectionMethod);
+    $this->assertTrue($eventDef['stub']->isStatic());
   }
 
   public function testGetAll() {
@@ -23,11 +27,26 @@ class CiviEventInspectorTest extends \CiviUnitTestCase {
     $all = $inspector->getAll();
     $this->assertTrue(count($all) > 1);
     $this->assertTrue(isset($all['hook_civicrm_alterSettingsMetaData']));
-    foreach ($all as $name => $hook) {
-      $this->assertEquals($name, $hook['name']);
-      $this->assertNotEmpty($hook['description_html']);
-      $this->assertTrue($inspector->validate($hook));
+    foreach ($all as $name => $eventDef) {
+      $this->assertEquals($name, $eventDef['name']);
+      $this->assertTrue($inspector->validate($eventDef));
+      if (isset($eventDef['stub'])) {
+        $this->assertTrue($eventDef['stub'] instanceof \ReflectionMethod);
+        $this->assertTrue($eventDef['stub']->isStatic());
+      }
     }
   }
 
+  public function testFind() {
+    $inspector = new CiviEventInspector();
+
+    $result_a = $inspector->find('/^hook_civicrm_post/');
+    $this->assertTrue(is_array($result_a['hook_civicrm_post']));
+    $this->assertFalse(isset($result_a['hook_civicrm_pre']));
+
+    $result_b = $inspector->find('/^hook_civicrm_pre/');
+    $this->assertTrue(is_array($result_b['hook_civicrm_pre']));
+    $this->assertFalse(isset($result_b['hook_civicrm_post']));
+  }
+
 }