2 require_once 'CiviTest/CiviUnitTestCase.php';
5 * Class CRM_Utils_HookTest
7 class CRM_Utils_HookTest
extends CiviUnitTestCase
{
9 static $activeTest = NULL;
17 $this->fakeModules
= array(
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;
31 self
::$activeTest = $this;
36 * Verify that runHooks() is reentrant by invoking one hook which calls another hooks
38 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 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);
70 /* --- Library of test hook implementations ---- */
72 function hooktesta_civicrm_testRunHooks_outer() {
73 $test = CRM_Utils_HookTest
::$activeTest;
74 $test->log
[] = 'a-outer';
77 function hooktestb_civicrm_testRunHooks_outer() {
78 $test = CRM_Utils_HookTest
::$activeTest;
79 $test->log
[] = 'b-outer-1';
80 $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);
81 $test->log
[] = 'b-outer-2';
84 function hooktestc_civicrm_testRunHooks_outer() {
85 $test = CRM_Utils_HookTest
::$activeTest;
86 $test->log
[] = 'c-outer';
89 function hooktesta_civicrm_testRunHooks_inner() {
90 $test = CRM_Utils_HookTest
::$activeTest;
91 $test->log
[] = 'a-inner';
94 function hooktestb_civicrm_testRunHooks_inner() {
95 $test = CRM_Utils_HookTest
::$activeTest;
96 $test->log
[] = 'b-inner';
99 function hooktesta_civicrm_testRunHooks_merge() {
100 return array('from-module-a1', 'from-module-a2');
103 // OMIT: function hooktestb_civicrm_testRunHooks_merge
105 function hooktestc_civicrm_testRunHooks_merge() {
109 function hooktestd_civicrm_testRunHooks_merge() {
113 function hookteste_civicrm_testRunHooks_merge() {
114 return array('from-module-e');