Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-08-10-18-35-58
[civicrm-core.git] / tests / phpunit / CRM / Utils / HookTest.php
1 <?php
2 require_once 'CiviTest/CiviUnitTestCase.php';
3 class CRM_Utils_HookTest extends CiviUnitTestCase {
4
5 static $activeTest = NULL;
6
7 var $fakeModules;
8
9 var $log;
10
11 function setUp() {
12 parent::setUp();
13 $this->fakeModules = array(
14 'hooktesta',
15 'hooktestb',
16 'hooktestc',
17 );
18 // our goal is to test a helper in CRM_Utils_Hook, but we need a concrete class
19 $this->hook = new CRM_Utils_Hook_UnitTests();
20 $this->log = array();
21 self::$activeTest = $this;
22 }
23
24 function tearDown() {
25 self::$activeTest = $this;
26 parent::tearDown();
27 }
28
29 /**
30 * Verify that runHooks() is reentrant by invoking one hook which calls another hooks
31 */
32 function testRunHooks_reentrancy() {
33 $arg1 = 'whatever';
34 $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);
35 $this->assertEquals(
36 array(
37 'a-outer',
38 'b-outer-1',
39 'a-inner',
40 'b-inner',
41 'b-outer-2',
42 'c-outer',
43 ),
44 $this->log
45 );
46 }
47 }
48
49 /* --- Library of test hook implementations ---- */
50
51 function hooktesta_civicrm_testRunHooks_outer() {
52 $test = CRM_Utils_HookTest::$activeTest;
53 $test->log[] = 'a-outer';
54 }
55
56 function hooktestb_civicrm_testRunHooks_outer() {
57 $test = CRM_Utils_HookTest::$activeTest;
58 $test->log[] = 'b-outer-1';
59 $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);
60 $test->log[] = 'b-outer-2';
61 }
62
63 function hooktestc_civicrm_testRunHooks_outer() {
64 $test = CRM_Utils_HookTest::$activeTest;
65 $test->log[] = 'c-outer';
66 }
67
68 function hooktesta_civicrm_testRunHooks_inner() {
69 $test = CRM_Utils_HookTest::$activeTest;
70 $test->log[] = 'a-inner';
71 }
72
73 function hooktestb_civicrm_testRunHooks_inner() {
74 $test = CRM_Utils_HookTest::$activeTest;
75 $test->log[] = 'b-inner';
76 }