mirror of
https://github.com/salesagility/SuiteCRM.git
synced 2025-02-21 20:56:08 +00:00

- File: '... /tests/unit/phpunit/modules/ACLActions/ACLActionTest.php' - Replaced 4 occurrence(s) of 'new ACLAction()' - Replaced 1 occurrence(s) of 'new User()' - File: '... /tests/unit/phpunit/modules/ProjectTask/ProjectTaskTest.php' - Replaced 19 occurrence(s) of 'new ProjectTask()' - Replaced 1 occurrence(s) of 'new User()' - File: '... /tests/unit/phpunit/modules/Alerts/AlertTest.php' - Replaced 1 occurrence(s) of 'new User()' - Replaced 2 occurrence(s) of 'new Alert()' - File: '... /tests/unit/phpunit/modules/ACLRoles/ACLRoleTest.php' - Replaced 10 occurrence(s) of 'new ACLRole()' - Replaced 1 occurrence(s) of 'new User()' - File: '... /tests/unit/phpunit/modules/jjwg_Markers/jjwg_MarkersTest.php' - Replaced 5 occurrence(s) of 'new jjwg_Markers()' - File: '... /tests/unit/phpunit/modules/Tasks/TaskTest.php' - Replaced 12 occurrence(s) of 'new Task()' - Replaced 1 occurrence(s) of 'new User()' - File: '... /tests/unit/phpunit/modules/CampaignLog/CampaignLogTest.php' - Replaced 4 occurrence(s) of 'new CampaignLog()' - Replaced 1 occurrence(s) of 'new User()' - File: '... /tests/unit/phpunit/modules/UserPreferences/UserPreferenceTest.php' - Replaced 5 occurrence(s) of 'new User()' - Replaced 2 occurrence(s) of 'new UserPreference()' - File: '... /tests/unit/phpunit/modules/Favorites/FavoritesTest.php' - Replaced 4 occurrence(s) of 'new Favorites()' - File: '... /tests/unit/phpunit/modules/AOR_Scheduled_Reports/AOR_Scheduled_ReportsTest.php' - Replaced 1 occurrence(s) of 'new User()' - Replaced 1 occurrence(s) of 'new AOR_Report()' - Replaced 5 occurrence(s) of 'new AOR_Scheduled_Reports()'
143 lines
5.2 KiB
PHP
143 lines
5.2 KiB
PHP
<?php
|
|
|
|
use SuiteCRM\Test\SuitePHPUnitFrameworkTestCase;
|
|
|
|
class UserPreferenceTest extends SuitePHPUnitFrameworkTestCase
|
|
{
|
|
public function setUp()
|
|
{
|
|
parent::setUp();
|
|
|
|
global $current_user;
|
|
get_sugar_config_defaults();
|
|
$current_user = BeanFactory::newBean('Users');
|
|
}
|
|
|
|
public function testgetUserDateTimePreferences()
|
|
{
|
|
$user = BeanFactory::newBean('Users');
|
|
$user->retrieve('1');
|
|
|
|
$userPreference = new UserPreference($user);
|
|
|
|
$result = $userPreference->getUserDateTimePreferences();
|
|
$this->assertTrue(is_array($result));
|
|
}
|
|
|
|
public function testSetAndGetPreference()
|
|
{
|
|
$this->markTestIncomplete('state is incorrect');
|
|
|
|
global $sugar_config;
|
|
|
|
$user = BeanFactory::newBean('Users');
|
|
$user->retrieve('1');
|
|
|
|
$userPreference = new UserPreference($user);
|
|
|
|
//test setPreference method
|
|
$userPreference->setPreference('test', 'test val', 'test_category');
|
|
|
|
if (!isset($_SESSION[$user->user_name.'_PREFERENCES']['test_category']['test'])) {
|
|
LoggerManager::getLogger()->warn('no session');
|
|
$result = null;
|
|
self::markTestIncomplete('environment dependency: This test needs session');
|
|
} else {
|
|
$result = $_SESSION[$user->user_name.'_PREFERENCES']['test_category']['test'];
|
|
}
|
|
|
|
$this->assertEquals('test val', $result);
|
|
|
|
//test getPreference method
|
|
$result = $userPreference->getPreference('test', 'test_category');
|
|
$this->assertEquals('test val', $result);
|
|
|
|
$result = $userPreference->getPreference('chartEngine');
|
|
$this->assertEquals($sugar_config['chartEngine'], $result);
|
|
}
|
|
|
|
public function testgetDefaultPreference()
|
|
{
|
|
global $sugar_config;
|
|
$userPreference = BeanFactory::newBean('UserPreferences');
|
|
|
|
//test with non global category
|
|
$result = $userPreference->getDefaultPreference('chartEngine', 'Home');
|
|
$this->assertEquals(null, $result);
|
|
|
|
//test with default global category
|
|
|
|
$result = $userPreference->getDefaultPreference('chartEngine');
|
|
$this->assertEquals($sugar_config['chartEngine'], $result);
|
|
|
|
$date_format = $sugar_config['datef'] != '' ? $sugar_config['datef'] : $sugar_config['default_date_format'];
|
|
$result = $userPreference->getDefaultPreference('datef');
|
|
$this->assertEquals($date_format, $result);
|
|
|
|
$time_format = $sugar_config['timef'] != '' ? $sugar_config['timef'] : $sugar_config['default_time_format'];
|
|
$result = $userPreference->getDefaultPreference('timef');
|
|
$this->assertEquals($time_format, $result);
|
|
|
|
$email_link_type = (isset($sugar_config['email_link_type']) ? $sugar_config['email_link_type'] : null) != '' ? (isset($sugar_config['email_link_type']) ? $sugar_config['email_link_type'] : null) : $sugar_config['email_default_client'];
|
|
$result = $userPreference->getDefaultPreference('email_link_type');
|
|
$this->assertEquals($email_link_type, $result);
|
|
}
|
|
|
|
public function test__construct()
|
|
{
|
|
// execute the constructor and check for the Object type and attributes
|
|
$userPreference = BeanFactory::newBean('UserPreferences');
|
|
|
|
$this->assertInstanceOf('UserPreference', $userPreference);
|
|
$this->assertInstanceOf('SugarBean', $userPreference);
|
|
|
|
$this->assertAttributeEquals('user_preferences', 'table_name', $userPreference);
|
|
$this->assertAttributeEquals('UserPreferences', 'module_dir', $userPreference);
|
|
$this->assertAttributeEquals('UserPreference', 'object_name', $userPreference);
|
|
|
|
$this->assertAttributeEquals(true, 'new_schema', $userPreference);
|
|
$this->assertAttributeEquals(true, 'disable_row_level_security', $userPreference);
|
|
}
|
|
|
|
public function testSavePreferencesToDBAndResetPreferences()
|
|
{
|
|
self::markTestIncomplete('environment dependency');
|
|
|
|
$user = BeanFactory::newBean('Users');
|
|
$user->retrieve('1');
|
|
|
|
$userPreference = new UserPreference($user);
|
|
|
|
//create a Preference record, save it to DB
|
|
$userPreference->setPreference('test', 'test val', 'test_category');
|
|
$userPreference->savePreferencesToDB();
|
|
|
|
//retrieve it back and verify
|
|
$result = $userPreference->retrieve_by_string_fields(array(
|
|
'assigned_user_id' => $user->id,
|
|
'category' => 'test_category',
|
|
));
|
|
|
|
//$this->assertFalse(isset($result->id));
|
|
|
|
//reset the preferences and verify that it is deleted
|
|
$userPreference->resetPreferences();
|
|
$result = $userPreference->retrieve_by_string_fields(array(
|
|
'assigned_user_id' => $user->id,
|
|
'category' => 'test_category',
|
|
));
|
|
$this->assertEquals(null, $result);
|
|
}
|
|
|
|
public function testupdateAllUserPrefs()
|
|
{
|
|
global $current_user;
|
|
|
|
$current_user = BeanFactory::newBean('Users');
|
|
$current_user->retrieve('1');
|
|
|
|
//UserPreference::updateAllUserPrefs("test","test val");
|
|
|
|
$this->markTestIncomplete('Multiple errors in method: Unknown column user_preferences in field list');
|
|
}
|
|
}
|