4 * Class CRM_Utils_HookTest
7 class CRM_Utils_HookTest
extends CiviUnitTestCase
{
9 public static $activeTest = NULL;
15 public function setUp(): void
{
17 $this->fakeModules
= [
24 // our goal is to test a helper in CRM_Utils_Hook, but we need a concrete class
25 $this->hook
= new CRM_Utils_Hook_UnitTests();
27 self
::$activeTest = $this;
30 public function tearDown(): void
{
31 self
::$activeTest = $this;
36 * Verify that runHooks() is reentrant by invoking one hook which calls another hooks
38 public function testRunHooks_reentrancy() {
40 $this->hook
->runHooks($this->fakeModules
, 'civicrm_testRunHooks_outer', 1, $arg1, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject);
55 * Verify that the results of runHooks() are correctly merged
57 public function testRunHooks_merge() {
58 $result = $this->hook
->runHooks($this->fakeModules
, 'civicrm_testRunHooks_merge', 0, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject);
71 /* --- Library of test hook implementations --- */
74 * Implements hook_civicrm_testRunHooks_outer().
76 function hooktesta_civicrm_testRunHooks_outer() {
77 $test = CRM_Utils_HookTest
::$activeTest;
78 $test->log
[] = 'a-outer';
81 function hooktestb_civicrm_testRunHooks_outer() {
82 $test = CRM_Utils_HookTest
::$activeTest;
83 $test->log
[] = 'b-outer-1';
84 $test->hook
->runHooks($test->fakeModules
, 'civicrm_testRunHooks_inner', 0, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject, CRM_Utils_Hook
::$_nullObject);
85 $test->log
[] = 'b-outer-2';
88 function hooktestc_civicrm_testRunHooks_outer() {
89 $test = CRM_Utils_HookTest
::$activeTest;
90 $test->log
[] = 'c-outer';
93 function hooktesta_civicrm_testRunHooks_inner() {
94 $test = CRM_Utils_HookTest
::$activeTest;
95 $test->log
[] = 'a-inner';
98 function hooktestb_civicrm_testRunHooks_inner() {
99 $test = CRM_Utils_HookTest
::$activeTest;
100 $test->log
[] = 'b-inner';
106 function hooktesta_civicrm_testRunHooks_merge() {
107 return ['from-module-a1', 'from-module-a2'];
110 // OMIT: function hooktestb_civicrm_testRunHooks_merge
113 * Implements hook_civicrm_testRunHooks_merge().
115 function hooktestc_civicrm_testRunHooks_merge() {
122 function hooktestd_civicrm_testRunHooks_merge() {
129 function hookteste_civicrm_testRunHooks_merge() {
130 return ['from-module-e'];