CiviEventInspector - Include metadata about some non-hook events
[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->assertEquals('hook', $eventDef['type']);
16 $this->assertNotEmpty($eventDef['description_html']);
17 $this->assertTrue($eventDef['fields']['settingsMetaData']['ref']);
18 $this->assertFalse($eventDef['fields']['domainID']['ref']);
19 $this->assertEquals('&$settingsMetaData, $domainID, $profile', $eventDef['signature']);
20 $this->assertTrue($inspector->validate($eventDef));
21 }
22
23 public function testGetAll() {
24 $inspector = new CiviEventInspector();
25 $all = $inspector->getAll();
26 $this->assertTrue(count($all) > 1);
27 $this->assertTrue(isset($all['hook_civicrm_alterSettingsMetaData']));
28 foreach ($all as $name => $eventDef) {
29 $this->assertEquals($name, $eventDef['name']);
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 }