CiviEventInspector - Prefer "event" nomenclature instead of "hook"
[civicrm-core.git] / tests / phpunit / Civi / Core / CiviEventInspectorTest.php
1 <?php
2 namespace Civi\Core;
3
4 /**
5 * Class CiviEventInspectorTest
6 * @group headless
7 */
8 class CiviEventInspectorTest extends \CiviUnitTestCase {
9
10 public function testGet() {
11 $inspector = new CiviEventInspector();
12 $eventDef = $inspector->get('hook_civicrm_alterSettingsMetaData');
13 $this->assertEquals('hook_civicrm_alterSettingsMetaData', $eventDef['name']);
14 $this->assertEquals(array('settingsMetaData', 'domainID', 'profile'), array_keys($eventDef['fields']));
15 $this->assertTrue($eventDef['is_hook']);
16 $this->assertTrue($eventDef['fields']['settingsMetaData']['ref']);
17 $this->assertFalse($eventDef['fields']['domainID']['ref']);
18 $this->assertEquals('&$settingsMetaData, $domainID, $profile', $eventDef['signature']);
19 $this->assertTrue($inspector->validate($eventDef));
20 }
21
22 public function testGetAll() {
23 $inspector = new CiviEventInspector();
24 $all = $inspector->getAll();
25 $this->assertTrue(count($all) > 1);
26 $this->assertTrue(isset($all['hook_civicrm_alterSettingsMetaData']));
27 foreach ($all as $name => $eventDef) {
28 $this->assertEquals($name, $eventDef['name']);
29 $this->assertNotEmpty($eventDef['description_html']);
30 $this->assertTrue($inspector->validate($eventDef));
31 }
32 }
33
34 public function testFind() {
35 $inspector = new CiviEventInspector();
36
37 $result_a = $inspector->find('/^hook_civicrm_post/');
38 $this->assertTrue(is_array($result_a['hook_civicrm_post']));
39 $this->assertFalse(isset($result_a['hook_civicrm_pre']));
40
41 $result_b = $inspector->find('/^hook_civicrm_pre/');
42 $this->assertTrue(is_array($result_b['hook_civicrm_pre']));
43 $this->assertFalse(isset($result_b['hook_civicrm_post']));
44 }
45
46 }