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

security_utilsTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 123
rs 10
c 1
b 0
f 1
1
<?php
2
3
require_once 'include/utils/security_utils.php';
4
class security_utilsTest extends PHPUnit_Framework_TestCase
5
{
6
	
7
	public function testquery_module_access_list()
8
	{
9
10
		//execute the method and test it it returns expected contents
11
		
12
		$user = new User('1');
13
		$expected = array (
14
				'Home' => 'Home',
15
				'Accounts' => 'Accounts',
16
				'Contacts' => 'Contacts',
17
				'Opportunities' => 'Opportunities',
18
				'Leads' => 'Leads',
19
				'AOS_Quotes' => 'AOS_Quotes',
20
				'Calendar' => 'Calendar',
21
				'Documents' => 'Documents',
22
				'Emails' => 'Emails',
23
				'Campaigns' => 'Campaigns',
24
				'Calls' => 'Calls',
25
				'Meetings' => 'Meetings',
26
				'Tasks' => 'Tasks',
27
				'Notes' => 'Notes',
28
				'AOS_Invoices' => 'AOS_Invoices',
29
				'AOS_Contracts' => 'AOS_Contracts',
30
				'Cases' => 'Cases',
31
				'Prospects' => 'Prospects',
32
				'ProspectLists' => 'ProspectLists',
33
				'Project' => 'Project',
34
				'AM_ProjectTemplates' => 'AM_ProjectTemplates',
35
				'FP_events' => 'FP_events',
36
				'FP_Event_Locations' => 'FP_Event_Locations',
37
				'AOS_Products' => 'AOS_Products',
38
				'AOS_Product_Categories' => 'AOS_Product_Categories',
39
				'AOS_PDF_Templates' => 'AOS_PDF_Templates',
40
				'jjwg_Maps' => 'jjwg_Maps',
41
				'jjwg_Markers' => 'jjwg_Markers',
42
				'jjwg_Areas' => 'jjwg_Areas',
43
				'jjwg_Address_Cache' => 'jjwg_Address_Cache',
44
				'AOR_Reports' => 'AOR_Reports',
45
				'AOW_WorkFlow' => 'AOW_WorkFlow',
46
				'AOK_KnowledgeBase' => 'AOK_KnowledgeBase',
47
				'AOK_Knowledge_Base_Categories' => 'AOK_Knowledge_Base_Categories',
48
		);		
49
		
50
		$actual = query_module_access_list($user);
51
		$this->assertSame($expected,$actual);
52
		
53
				
54
	}
55
	
56
	public function testquery_user_has_roles()
57
	{
58
		error_reporting(E_ERROR | E_PARSE);
59
		
60
		//execute the method and test it it returns expected contents
61
		
62
		$expected = "0";
63
		$actual = query_user_has_roles('1');
64
		$this->assertSame($expected,$actual);
65
		
66
	}
67
	
68
	public function testget_user_allowed_modules()
69
	{
70
		//execute the method and test it it returns expected contents
71
		
72
		$expected = Array();
73
		$actual = get_user_allowed_modules('1');
74
		$this->assertSame($expected,$actual);
75
	
76
	}
77
	
78
	public function testget_user_disallowed_modules()
79
	{
80
		//execute the method and test it it returns expected contents
81
		
82
		$expected = array (
83
				'Bugs' => 'Bugs',
84
                'Reminders' => 'Reminders',
85
                'Reminders_Invitees' => 'Reminders_Invitees',
86
				'AOR_Scheduled_Reports' => 'AOR_Scheduled_Reports',
87
				'SecurityGroups' => 'SecurityGroups',
88
		);
89
		
90
		$allowed = query_module_access_list(new User('1'));
91
		$actual = get_user_disallowed_modules('1',$allowed);
92
	
93
		$this->assertSame($expected,$actual);
94
		
95
				
96
	}
97
	
98
	public function testquery_client_ip()
99
	{
100
		//test without setting any server parameters
101
		$this->assertSame(Null,query_client_ip());
102
103
		//test with server params set
104
		$_SERVER['REMOTE_ADDR'] = "1.1.1.3";
105
		$this->assertSame("1.1.1.3",query_client_ip());
106
		
107
		$_SERVER['HTTP_FROM'] = "1.1.1.2";
108
		$this->assertSame("1.1.1.2",query_client_ip());
109
		
110
		$_SERVER['HTTP_CLIENT_IP'] = "1.1.1.1";
111
		$this->assertSame("1.1.1.1",query_client_ip());
112
		
113
	}
114
	
115
	
116
	public function testget_val_array()
117
	{
118
		//execute the method and test it it returns expected contents
119
		$tempArray = Array("key1"=>"val1","key2"=>"val2","key3"=>"val3");
120
		$expected = Array("key1"=>"key1","key2"=>"key2","key3"=>"key3");
121
		$actual = get_val_array($tempArray);
122
		$this->assertSame($expected,$actual);
123
		
124
	}
125
	
126
}
127