commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / tests / phpunit / CRM / Utils / HookTest.php
1 <?php
2 require_once 'CiviTest/CiviUnitTestCase.php';
3
4 /**
5 * Class CRM_Utils_HookTest
6 */
7 class CRM_Utils_HookTest extends CiviUnitTestCase {
8
9 static $activeTest = NULL;
10
11 var $fakeModules;
12
13 var $log;
14
15 public function setUp() {
16 parent::setUp();
17 $this->fakeModules = array(
18 'hooktesta',
19 'hooktestb',
20 'hooktestc',
21 'hooktestd',
22 'hookteste',
23 );
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();
26 $this->log = array();
27 self::$activeTest = $this;
28 }
29
30 public function tearDown() {
31 self::$activeTest = $this;
32 parent::tearDown();
33 }
34
35 /**
36 * Verify that runHooks() is reentrant by invoking one hook which calls another hooks
37 */
38 public function testRunHooks_reentrancy() {
39 $arg1 = 'whatever';
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);
41 $this->assertEquals(
42 array(
43 'a-outer',
44 'b-outer-1',
45 'a-inner',
46 'b-inner',
47 'b-outer-2',
48 'c-outer',
49 ),
50 $this->log
51 );
52 }
53
54 /**
55 * Verify that the results of runHooks() are correctly merged
56 */
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);
59 $this->assertEquals(
60 array(
61 'from-module-a1',
62 'from-module-a2',
63 'from-module-e',
64 ),
65 $result
66 );
67 }
68
69 }
70
71 /* --- Library of test hook implementations --- */
72
73 /**
74 * Implements hook_civicrm_testRunHooks_outer().
75 */
76 function hooktesta_civicrm_testRunHooks_outer() {
77 $test = CRM_Utils_HookTest::$activeTest;
78 $test->log[] = 'a-outer';
79 }
80
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';
86 }
87
88 function hooktestc_civicrm_testRunHooks_outer() {
89 $test = CRM_Utils_HookTest::$activeTest;
90 $test->log[] = 'c-outer';
91 }
92
93 function hooktesta_civicrm_testRunHooks_inner() {
94 $test = CRM_Utils_HookTest::$activeTest;
95 $test->log[] = 'a-inner';
96 }
97
98 function hooktestb_civicrm_testRunHooks_inner() {
99 $test = CRM_Utils_HookTest::$activeTest;
100 $test->log[] = 'b-inner';
101 }
102
103 /**
104 * @return array
105 */
106 function hooktesta_civicrm_testRunHooks_merge() {
107 return array('from-module-a1', 'from-module-a2');
108 }
109
110 // OMIT: function hooktestb_civicrm_testRunHooks_merge
111
112 /**
113 * Implements hook_civicrm_testRunHooks_merge().
114 */
115 function hooktestc_civicrm_testRunHooks_merge() {
116 return array();
117 }
118
119 /**
120 * @return null
121 */
122 function hooktestd_civicrm_testRunHooks_merge() {
123 return NULL;
124 }
125
126 /**
127 * @return array
128 */
129 function hookteste_civicrm_testRunHooks_merge() {
130 return array('from-module-e');
131 }