Test Failed
Push — CI ( 0f01dd...c95a04 )
by Adam
55:13
created

LogicHookTest::testgetHooks()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 40
rs 8.8571
c 1
b 0
f 1
cc 1
eloc 23
nc 1
nop 0
1
<?php
2
3
4
class LogicHookTest extends PHPUnit_Framework_TestCase {
5
6
7
	public function testLogicHook()
8
	{
9
		//execute the method and test if it doesn't throws an exception
10
		try {
11
			$LogicHook = new LogicHook();
12
			$this->assertTrue(true);
13
		}
14
		catch (Exception $e) {
15
			$this->fail();
16
		}
17
		
18
	}
19
20
	
21
	public function testinitialize()
22
	{
23
		//execute the method and test if it returns correct class instances
24
		$LogicHook = LogicHook::initialize();
25
		$this->assertInstanceOf('LogicHook',$LogicHook);
26
		
27
	}
28
29
	public function testsetBean()
30
	{
31
		//execute the method and test if it returns correct class instances
32
		
33
		$LogicHook = new LogicHook();
34
		$result = $LogicHook->setBean(new User());
35
		$this->assertInstanceOf('LogicHook',$result);
36
		$this->assertInstanceOf('User',$result->bean);		
37
	}
38
39
40
	public function testgetHooksMap()
41
	{
42
		//execute the method and test if it returns true
43
		
44
		$LogicHook = new LogicHook();
45
		$hook_map = $LogicHook->getHooksMap();
46
		$this->assertTrue(is_array($hook_map));
47
			
48
	}
49
50
	public function testgetHooksList()
51
	{
52
		//execute the method and test if it returns true
53
		
54
		$LogicHook = new LogicHook();
55
		$hookscan = $LogicHook->getHooksList();
56
		$this->assertTrue(is_array($hookscan));		
57
	
58
	}
59
60
    public function testscanHooksDir()
61
    {
62
    	error_reporting(E_ERROR | E_PARSE);
63
    	    	
64
    	//execute the method and test if it returns expected contents
65
    	
66
    	$expected_hook_map = array (
67
    			'before_save' =>
68
    			array (
69
    					array ( 'file' => 'custom/modules/Accounts/logic_hooks.php', 'index' => 0,),
70
    			),
71
    			'after_save' =>
72
    			array (
73
    					array ('file' => 'custom/modules/Accounts/logic_hooks.php', 'index' => 0,),
74
    					array ('file' => 'custom/modules/Accounts/logic_hooks.php', 'index' => 1,),
75
    					array ('file' => 'custom/modules/Accounts/logic_hooks.php','index' => 2,),
76
  						array ('file' => 'custom/modules/Accounts/logic_hooks.php','index' => 3,),
77
    			),
78
    			'after_relationship_add' =>
79
    			array (
80
    					array ('file' => 'custom/modules/Accounts/logic_hooks.php', 'index' => 0,),
81
    			),
82
    			'after_relationship_delete' =>
83
    			array (
84
						array ('file' => 'custom/modules/Accounts/logic_hooks.php','index' => 0,),
85
    			),
86
    	);
87
    	
88
 
89
    	$expected_hookscan = array (
90
    			'before_save' =>
91
    			array (
92
    					array (77, 'updateGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateGeocodeInfo',),
93
    			),
94
    			'after_save' =>
95
    			array (
96
    				    array (77, 'updateRelatedMeetingsGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateRelatedMeetingsGeocodeInfo',),
97
    					array (78, 'updateRelatedProjectGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateRelatedProjectGeocodeInfo', ),
98
    					array (79, 'updateRelatedOpportunitiesGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateRelatedOpportunitiesGeocodeInfo',),
99
    					array (80, 'updateRelatedCasesGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateRelatedCasesGeocodeInfo',),
100
    			),
101
    			'after_relationship_add' =>
102
    			array (
103
    					array ( 77, 'addRelationship', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'addRelationship',),
104
    			),
105
    			'after_relationship_delete' =>
106
    			array (
107
    					array ( 77, 'deleteRelationship', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'deleteRelationship',),
108
    			),
109
    	);
110
    	
111
    	$LogicHook = new LogicHook();
112
    	$LogicHook->scanHooksDir('custom/modules/Accounts');
113
    	$hook_map = $LogicHook->getHooksMap();
114
    	$hookscan = $LogicHook->getHooksList();
115
    	
116
    	
117
    	$this->assertSame($expected_hook_map,$hook_map);
118
    	$this->assertSame($expected_hookscan,$hookscan);
119
    	
120
    	
121
    }
122
123
124
    public function testrefreshHooks() 
125
    {
126
    	//execute the method and test if it doesn't throws an exception
127
    	
128
    	try {
129
    		LogicHook::refreshHooks();
130
    		$this->assertTrue(true);
131
    	}
132
    	catch (Exception $e) {
133
    		$this->fail();
134
    	}
135
    	
136
    }
137
138
	public function testloadHooks()
139
	{
140
		//execute the method and test if it returns expected contents
141
		
142
		$expected_accounts = array (
143
				'after_ui_frame' => Array (),
144
				'before_save' =>
145
				array (
146
						array (77, 'updateGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateGeocodeInfo',),
147
				),
148
				'after_save' =>
149
				array (
150
						array (77, 'updateRelatedMeetingsGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateRelatedMeetingsGeocodeInfo',),
151
						array (78, 'updateRelatedProjectGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateRelatedProjectGeocodeInfo', ),
152
						array (79, 'updateRelatedOpportunitiesGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateRelatedOpportunitiesGeocodeInfo',),
153
						array (80, 'updateRelatedCasesGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateRelatedCasesGeocodeInfo',),
154
				),
155
				'after_relationship_add' =>
156
				array (
157
						array ( 77, 'addRelationship', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'addRelationship',),
158
				),
159
				'after_relationship_delete' =>
160
				array (
161
						array ( 77, 'deleteRelationship', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'deleteRelationship',),
162
				),
163
		);
164
		
165
		$expected_default = array (
166
					'after_ui_footer' =>
167
					array (
168
							array (10,'popup_onload','modules/SecurityGroups/AssignGroups.php','AssignGroups','popup_onload',),
169
					),
170
					'after_ui_frame' =>
171
					array (
172
							array (20, 'mass_assign', 'modules/SecurityGroups/AssignGroups.php', 'AssignGroups', 'mass_assign',),
173
							array ( 1, 'Load Social JS', 'include/social/hooks.php', 'hooks', 'load_js',),
174
					),
175
					'after_save' =>
176
					array (
177
							array ( 30,'popup_select', 'modules/SecurityGroups/AssignGroups.php','AssignGroups','popup_select',),
178
							array ( 1, 'AOD Index Changes', 'modules/AOD_Index/AOD_LogicHooks.php', 'AOD_LogicHooks', 'saveModuleChanges',),
179
							array ( 99, 'AOW_Workflow', 'modules/AOW_WorkFlow/AOW_WorkFlow.php', 'AOW_WorkFlow','run_bean_flows',),
180
					),
181
					'after_delete' =>
182
					array (
183
							array ( 1, 'AOD Index changes', 'modules/AOD_Index/AOD_LogicHooks.php', 'AOD_LogicHooks','saveModuleDelete',),
184
					),
185
					'after_restore' =>
186
					array (
187
							array ( 1, 'AOD Index changes', 'modules/AOD_Index/AOD_LogicHooks.php', 'AOD_LogicHooks', 'saveModuleRestore',),
188
					),
189
				);
190
		
191
		
192
193
		$LogicHook = new LogicHook();
194
		
195
		//test with a valid module
196
		$accounts_hooks = $LogicHook->loadHooks('Accounts');
197
		$this->assertSame($expected_accounts, $accounts_hooks);
198
		
199
		//test with an invalid module, it will get the application hooks
200
		$default_hooks = $LogicHook->loadHooks('');
201
		$this->assertSame($expected_default, $default_hooks);
202
		
203
	}
204
205
	public function testgetHooks()
206
	{
207
		//execute the method and test if it returns expected contents
208
		
209
		$expected = array (
210
				'after_ui_frame' => Array (),
211
				'before_save' =>
212
				array (
213
						array (77, 'updateGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateGeocodeInfo',),
214
				),
215
				'after_save' =>
216
				array (
217
						array (77, 'updateRelatedMeetingsGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateRelatedMeetingsGeocodeInfo',),
218
						array (78, 'updateRelatedProjectGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateRelatedProjectGeocodeInfo', ),
219
						array (79, 'updateRelatedOpportunitiesGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateRelatedOpportunitiesGeocodeInfo',),
220
						array (80, 'updateRelatedCasesGeocodeInfo', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'updateRelatedCasesGeocodeInfo',),
221
				),
222
				'after_relationship_add' =>
223
				array (
224
						array ( 77, 'addRelationship', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'addRelationship',),
225
				),
226
				'after_relationship_delete' =>
227
				array (
228
						array ( 77, 'deleteRelationship', 'modules/Accounts/AccountsJjwg_MapsLogicHook.php', 'AccountsJjwg_MapsLogicHook', 'deleteRelationship',),
229
				),
230
		);
231
		
232
		$LogicHook = new LogicHook();
233
		
234
		//test with refresh false/default
235
		$hooks = $LogicHook->getHooks('Accounts');
236
		$this->assertSame($expected, $hooks);
237
		
238
		//test wit hrefresh true
239
		$hooks = $LogicHook->getHooks('Accounts',true);
240
		$this->assertSame($expected, $hooks);
241
		
242
		
243
		
244
	}
245
246
247
	public function testcall_custom_logic()
248
	{		
249
		//execute the method and test if it doesn't throws an exception
250
		
251
		$LogicHook = new LogicHook();
252
		$LogicHook->setBean(new Account());
253
		
254
		try {
255
			$LogicHook->call_custom_logic('', 'after_ui_footer');
256
			$this->assertTrue(true);
257
		}
258
		catch (Exception $e) {
259
			$this->fail();
260
		}
261
		
262
	}
263
264
265
	public function testprocess_hooks()
266
	{
267
		//execute the method and test if it doesn't throws an exception
268
		
269
		$LogicHook = new LogicHook();
270
		$LogicHook->setBean(new Account());
271
		$hooks = $LogicHook->loadHooks('');
272
		
273
		try {
274
			$LogicHook->process_hooks($hooks, 'after_ui_footer',array() );
275
			$this->assertTrue(true);
276
		}
277
		catch (Exception $e) {
278
			$this->fail();
279
		}
280
		
281
	}
282
	
283
}
284
?>
285