Merge pull request #16541 from bhahumanists/subtype-issue-991
[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(['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 $this->assertTrue($eventDef['stub'] instanceof \ReflectionMethod);
22 $this->assertTrue($eventDef['stub']->isStatic());
23 }
24
25 public function testGetAll() {
26 $inspector = new CiviEventInspector();
27 $all = $inspector->getAll();
28 $this->assertTrue(count($all) > 1);
29 $this->assertTrue(isset($all['hook_civicrm_alterSettingsMetaData']));
30 foreach ($all as $name => $eventDef) {
31 $this->assertEquals($name, $eventDef['name']);
32 $this->assertTrue($inspector->validate($eventDef));
33 if (isset($eventDef['stub'])) {
34 $this->assertTrue($eventDef['stub'] instanceof \ReflectionMethod);
35 $this->assertTrue($eventDef['stub']->isStatic());
36 }
37 }
38 }
39
40 public function testFind() {
41 $inspector = new CiviEventInspector();
42
43 $result_a = $inspector->find('/^hook_civicrm_post/');
44 $this->assertTrue(is_array($result_a['hook_civicrm_post']));
45 $this->assertFalse(isset($result_a['hook_civicrm_pre']));
46
47 $result_b = $inspector->find('/^hook_civicrm_pre/');
48 $this->assertTrue(is_array($result_b['hook_civicrm_pre']));
49 $this->assertFalse(isset($result_b['hook_civicrm_post']));
50 }
51
52 }