Add user preferences api and legacyhandler

This commit is contained in:
Ross Moroney 2020-03-25 10:15:37 +00:00 committed by Dillon-Brown
parent 1ab3d65b36
commit 6b2c10092d
31 changed files with 1159 additions and 111 deletions

View file

@ -17,7 +17,7 @@ class AppListStringsHandlerTest extends Unit
*/
protected $handler;

protected function _before()
protected function _before(): void
{
$projectDir = codecept_root_dir();
$legacyDir = $projectDir . '/legacy';
@ -31,7 +31,7 @@ class AppListStringsHandlerTest extends Unit
/**
* Test Invalid language handling in AppListStringsHandler
*/
public function testInvalidLanguageCheck()
public function testInvalidLanguageCheck(): void
{
$this->expectException(ItemNotFoundException::class);
$this->handler->getAppListStrings('invalid_lang');
@ -40,7 +40,7 @@ class AppListStringsHandlerTest extends Unit
/**
* Test default language retrieval in AppListStringsHandler
*/
public function testDefaultLanguageKey()
public function testDefaultLanguageKey(): void
{
$appListStrings = $this->handler->getAppListStrings('en_us');
static::assertNotNull($appListStrings);
@ -56,7 +56,7 @@ class AppListStringsHandlerTest extends Unit
* @param string $labelKey
* @param AppListStrings $appStrings
*/
protected function assertLanguageListKey(string $listKey, string $labelKey, AppListStrings $appStrings)
protected function assertLanguageListKey(string $listKey, string $labelKey, AppListStrings $appStrings): void
{
static::assertArrayHasKey($listKey, $appStrings->getItems());
static::assertNotEmpty($appStrings->getItems()[$listKey]);

View file

@ -17,7 +17,7 @@ class AppStringsHandlerTest extends Unit
*/
protected $handler;

protected function _before()
protected function _before(): void
{
$projectDir = codecept_root_dir();
$legacyDir = $projectDir . '/legacy';
@ -31,7 +31,7 @@ class AppStringsHandlerTest extends Unit
/**
* Test Invalid language handling in AppStringsHandler
*/
public function testInvalidLanguageCheck()
public function testInvalidLanguageCheck(): void
{
$this->expectException(ItemNotFoundException::class);
$this->handler->getAppStrings('invalid_lang');
@ -40,7 +40,7 @@ class AppStringsHandlerTest extends Unit
/**
* Test default language retrieval in AppStringsHandler
*/
public function testDefaultLanguageKey()
public function testDefaultLanguageKey(): void
{
$appStrings = $this->handler->getAppStrings('en_us');
static::assertNotNull($appStrings);
@ -62,7 +62,7 @@ class AppStringsHandlerTest extends Unit
* @param string $key
* @param AppStrings $appStrings
*/
protected function assertLanguageKey($key, AppStrings $appStrings)
protected function assertLanguageKey($key, AppStrings $appStrings): void
{
static::assertArrayHasKey($key, $appStrings->getItems());
static::assertNotEmpty($appStrings->getItems()[$key]);

View file

@ -18,7 +18,7 @@ class ModStringsHandlerTest extends Unit
*/
protected $handler;

protected function _before()
protected function _before(): void
{
$legacyModuleNameMap = [
'Home' => [
@ -366,7 +366,7 @@ class ModStringsHandlerTest extends Unit
/**
* Test Invalid language handling in ModStringsHandler
*/
public function testInvalidLanguageCheck()
public function testInvalidLanguageCheck(): void
{
$this->expectException(ItemNotFoundException::class);
$this->handler->getModStrings('invalid_lang');
@ -375,7 +375,7 @@ class ModStringsHandlerTest extends Unit
/**
* Test default language retrieval in ModStringsHandler
*/
public function testDefaultLanguageKey()
public function testDefaultLanguageKey(): void
{
$modStrings = $this->handler->getModStrings('en_us');
static::assertNotNull($modStrings);
@ -392,7 +392,7 @@ class ModStringsHandlerTest extends Unit
* @param string $key
* @param ModStrings $modStrings
*/
protected function assertLanguageKey($module, $key, ModStrings $modStrings)
protected function assertLanguageKey($module, $key, ModStrings $modStrings): void
{
static::assertArrayHasKey($module, $modStrings->getItems());
static::assertNotEmpty($modStrings->getItems()[$module]);

View file

@ -2146,6 +2146,45 @@ final class NavbarTest extends Unit
"icon" => "view"
]
]
],
'bugs' => [
'path' => 'bugs',
'defaultRoute' => './#/bugs/index',
'name' => 'bugs',
'labelKey' => 'Bugs',
'menu' => [
0 => [
'name' => 'Create',
'labelKey' => 'LNK_NEW_BUG',
'url' => './#/bugs/edit',
'params' => [
'return_module' => 'Bugs',
'return_action' => 'DetailView',
],
'icon' => 'plus'
],
1 => [
'name' => 'List',
'labelKey' => 'LNK_BUG_LIST',
'url' => './#/bugs/index',
'params' => [
'return_module' => 'Bugs',
'return_action' => 'DetailView'
],
'icon' => 'view'
],
2 => [
'name' => 'Import',
'labelKey' => 'LNK_IMPORT_BUGS',
'url' => './#/import/step1',
'params' => [
'import_module' => 'Bugs',
'return_module' => 'Bugs',
'return_action' => 'index'
],
'icon' => 'download'
]
]
]
];


View file

@ -16,7 +16,7 @@ class SystemConfigHandlerTest extends Unit
*/
protected $handler;

protected function _before()
protected function _before(): void
{
$exposedSystemConfigs = [
'default_language' => true,
@ -46,7 +46,7 @@ class SystemConfigHandlerTest extends Unit
/**
* Test empty config key handling in SystemConfigHandler
*/
public function testEmptySystemConfigKeyCheck()
public function testEmptySystemConfigKeyCheck(): void
{
$defaultLanguage = $this->handler->getSystemConfig('');
static::assertNull($defaultLanguage);
@ -55,7 +55,7 @@ class SystemConfigHandlerTest extends Unit
/**
* Test invalid config key handling in SystemConfigHandler
*/
public function testInvalidExposedSystemConfigCheck()
public function testInvalidExposedSystemConfigCheck(): void
{
$this->expectException(ItemNotFoundException::class);
$this->handler->getSystemConfig('dbconfig');
@ -64,7 +64,7 @@ class SystemConfigHandlerTest extends Unit
/**
* Test retrieval of first level system config in SystemConfigHandler
*/
public function testGetValidOneLevelSystemConfig()
public function testGetValidOneLevelSystemConfig(): void
{
$defaultLanguage = $this->handler->getSystemConfig('default_language');
static::assertNotNull($defaultLanguage);
@ -76,7 +76,7 @@ class SystemConfigHandlerTest extends Unit
/**
* Test retrieval of second level deep system config in SystemConfigHandler
*/
public function testGetValidTwoLevelSystemConfig()
public function testGetValidTwoLevelSystemConfig(): void
{
$defaultLanguage = $this->handler->getSystemConfig('passwordsetting');
static::assertNotNull($defaultLanguage);
@ -97,7 +97,7 @@ class SystemConfigHandlerTest extends Unit
/**
* Test retrieval of third level deep system config in SystemConfigHandler
*/
public function testGetValidThreeLevelSystemConfig()
public function testGetValidThreeLevelSystemConfig(): void
{
$defaultLanguage = $this->handler->getSystemConfig('search');
static::assertNotNull($defaultLanguage);

View file

@ -0,0 +1,70 @@
<?php namespace App\Tests;

use ApiPlatform\Core\Exception\ItemNotFoundException;
use Codeception\Test\Unit;
use SuiteCRM\Core\Legacy\UserPreferenceHandler;

class UserPreferencesHandlerTest extends Unit
{
/**
* @var UnitTester
*/
protected $tester;

/**
* @var UserPreferenceHandler
*/
protected $handler;

protected function _before(): void
{
$exposedUserPreferences = [
'global' => [
'timezone' => true
]
];

$projectDir = codecept_root_dir();
$legacyDir = $projectDir . '/legacy';
$legacySessionName = 'LEGACYSESSID';
$defaultSessionName = 'PHPSESSID';

$this->handler = new UserPreferenceHandler($projectDir, $legacyDir, $legacySessionName, $defaultSessionName,
$exposedUserPreferences);
}

// tests

/**
* Test empty config key handling in UserPreferenceHandler
*/
public function testEmptyUserPreferenceKeyCheck(): void
{
$noKeyUserPreference = $this->handler->getUserPreference('');
static::assertNull($noKeyUserPreference);
}

/**
* Test invalid config key handling in UserPreferenceHandler
*/
public function testInvalidExposedUserPreferenceCheck(): void
{
$this->expectException(ItemNotFoundException::class);
$this->handler->getUserPreference('dbconfig');
}

/**
* Test retrieval of first level user preference config in UserPreferenceHandler
*/
public function testGetUserPreferenceTimezone(): void
{
$userPref = $this->handler->getUserPreference('global');

static::assertNotNull($userPref);
static::assertEquals('global', $userPref->getId());

$userPreferences = $userPref->getItems();

static::assertEquals('UTC', $userPreferences['timezone']);
}
}