Completed
Push — CI ( ee6bd7...0f01dd )
by Adam
22:32
created

UserPreferenceTest::testgetDefaultPreference()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 34
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 34
rs 8.5806
c 1
b 0
f 1
cc 4
eloc 17
nc 8
nop 0
1
<?php
2
3
class UserPreferenceTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
	public function test__construct()
7
	{
8
		//execute the contructor and check for the Object type and  attributes
9
		$userPreference = new UserPreference();
10
		
11
		$this->assertInstanceOf('UserPreference',$userPreference);
12
		$this->assertInstanceOf('SugarBean',$userPreference);
13
			
14
		$this->assertAttributeEquals('user_preferences', 'table_name', $userPreference);
15
		$this->assertAttributeEquals('UserPreferences', 'module_dir', $userPreference);
16
		$this->assertAttributeEquals('UserPreference', 'object_name', $userPreference);
17
18
		
19
		$this->assertAttributeEquals(true, 'new_schema', $userPreference);
20
		$this->assertAttributeEquals(true, 'disable_row_level_security', $userPreference);
21
		
22
	}
23
24
	
25
	public function testgetDefaultPreference( )
26
	{
27
		global $sugar_config;
28
		
29
		error_reporting(E_ERROR | E_PARSE);
30
		
31
		$userPreference = new UserPreference();
32
		
33
		//test with non global category
34
		$result = $userPreference->getDefaultPreference('chartEngine', 'Home'); 
35
		$this->assertEquals(null,$result);
36
		
37
		
38
		//test with default global category
39
		
40
		$result = $userPreference->getDefaultPreference('chartEngine'); 
41
		$this->assertEquals($sugar_config['chartEngine'] ,$result);
42
	
43
		
44
		$date_format = $sugar_config['datef'] != "" ? $sugar_config['datef'] : $sugar_config['default_date_format'];
45
		$result = $userPreference->getDefaultPreference('datef');
46
		$this->assertEquals($date_format, $result);
47
		
48
		
49
		$time_format = $sugar_config['timef'] != ""? $sugar_config['timef'] : $sugar_config['default_time_format'];
50
		$result = $userPreference->getDefaultPreference('timef');
51
		$this->assertEquals($time_format , $result);
52
		
53
		
54
		$email_link_type = $sugar_config['email_link_type'] != "" ? $sugar_config['email_link_type'] : $sugar_config['email_default_client'];
55
		$result = $userPreference->getDefaultPreference('email_link_type');
56
		$this->assertEquals($email_link_type , $result);
57
				
58
	}
59
60
61
	public function testSetAndGetPreference()
62
	{
63
		global $sugar_config;
64
		
65
		$user = new User();
66
		$user->retrieve("1");
67
68
		$userPreference = new UserPreference($user);
69
		
70
		//test setPreference method
71
		$userPreference->setPreference("test","test val","test_category");
72
		$result = $_SESSION[$user->user_name.'_PREFERENCES']['test_category']['test'];
73
		$this->assertEquals("test val", $result);
74
		
75
		
76
		//test getPreference method
77
		$result = $userPreference->getPreference("test", "test_category");
78
		$this->assertEquals("test val", $result);
79
		
80
		$result = $userPreference->getPreference("chartEngine");
81
		$this->assertEquals($sugar_config['chartEngine'], $result);
82
		
83
	}
84
85
	
86
	public function testloadPreferences( )
87
	{
88
		$user = new User();
89
		$user->retrieve("1");
90
		
91
		$userPreference = new UserPreference($user);
92
		
93
		$result = $userPreference->loadPreferences();
94
		
95
		$this->assertEquals(false, $result);
96
	}
97
98
99
	public function testreloadPreferences()
100
	{
101
102
		$user = new User();
103
		$user->retrieve("1");
104
		
105
		$userPreference = new UserPreference($user);
106
		
107
		$result = $userPreference->reloadPreferences();
108
		$this->assertEquals(false, $result);
109
		
110
	}
111
112
113
	public function testgetUserDateTimePreferences()
114
	{
115
116
		$user = new User();
117
		$user->retrieve("1");
118
		
119
		$userPreference = new UserPreference($user);
120
		
121
		$result = $userPreference->getUserDateTimePreferences();
122
		$this->assertTrue(is_array($result));
123
		
124
	}
125
126
127
	public function testSavePreferencesToDBAndResetPreferences( )
128
	{
129
		$user = new User();
130
		$user->retrieve("1");
131
		
132
		$userPreference = new UserPreference($user);
133
		
134
		//create a Preference record, save it to DB
135
		$userPreference->setPreference("test","test val","test_category");
136
		$userPreference->savePreferencesToDB();
137
		
138
		
139
		//retrieve it back and verify
140
		$result = $userPreference->retrieve_by_string_fields(array(
141
				'assigned_user_id' => $user->id,
142
				'category' => 'test_category',
143
		));
144
		$this->assertTrue(isset($result->id));
145
		
146
		
147
		//reset the preferences and verify that it is deleted
148
		$userPreference->resetPreferences();
149
		$result = $userPreference->retrieve_by_string_fields(array(
150
				'assigned_user_id' => $user->id,
151
				'category' => 'test_category',
152
		));
153
		$this->assertEquals(null,$result);
154
		
155
	}
156
157
158
	public function testupdateAllUserPrefs( )
159
	{	
160
		global $current_user;
161
162
		$current_user = new User();
163
		$current_user->retrieve("1");
164
		
165
		//UserPreference::updateAllUserPrefs("test","test val");
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
166
		
167
		$this->markTestIncomplete('Multiple errors in method: Unknown column user_preferences in field list');
168
		
169
	}
170
171
}
172