228 lines
6.6 KiB
PHP
228 lines
6.6 KiB
PHP
<?php
|
|
|
|
namespace LoretaAudit\Tests\UnitTests\App\PubUsers;
|
|
|
|
use BRSystems\Core\App\pubSysDashboard\pubSysDashboard;
|
|
use BRSystems\Core\App\pubUsers\inc\pubUsersCfg;
|
|
use LoretaAudit\Tests\BasePhpUnitCase;
|
|
use LoretaAudit\Tests\DataSetup\Constants\SiteMap;
|
|
use LoretaAudit\Tests\DataSetup\Constants\siteUsers;
|
|
|
|
class UserAdvCfgTest extends BasePhpUnitCase
|
|
{
|
|
private pubSysDashboard $pubSysDashboard;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
// Init base structure
|
|
$this->unitTestsAreRunning = true;
|
|
$this->resetGetAndPost();
|
|
parent::setUp();
|
|
|
|
// Create new class
|
|
$this->pubSysDashboard = $this->initBaseClassObjectBySiteMapId(SiteMap::SYSTEM_DASHBOARD);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
$this->reloadDbTables(['mod_users', 'mod_account_manager']);
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function testGetUserAdvCfgTest(): void
|
|
{
|
|
// Get partners settings
|
|
$data = $this->pubSysDashboard->controller->oUser->getUserAdvCfgData(
|
|
pubUsersCfg::ADV_KEY_TBL,
|
|
'pubPartners',
|
|
pubUsersCfg::ADV_PROP_SORT
|
|
);
|
|
|
|
$this->assertEquals(
|
|
[
|
|
'sortWay' => 0,
|
|
'sortBy' => 'a_title'
|
|
],
|
|
$data
|
|
);
|
|
}
|
|
|
|
public function testSaveUserAdvCfgTest(): void
|
|
{
|
|
$saveData = [
|
|
'sortWay' => 0,
|
|
'sortBy' => 'a_ap_nr_custom_column'
|
|
];
|
|
|
|
$this->pubSysDashboard->controller->oUser->updateUserAdvCfgData(
|
|
pubUsersCfg::ADV_KEY_TBL,
|
|
'pubPartners',
|
|
pubUsersCfg::ADV_PROP_SORT,
|
|
$saveData
|
|
);
|
|
|
|
$this->assertEquals(
|
|
$this->pubSysDashboard->controller->oUser->getUserAdvCfgData(
|
|
pubUsersCfg::ADV_KEY_TBL,
|
|
'pubPartners',
|
|
pubUsersCfg::ADV_PROP_SORT
|
|
),
|
|
$saveData
|
|
);
|
|
}
|
|
|
|
public function testInitBaseAdvCfg(): void
|
|
{
|
|
$loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed);
|
|
|
|
// Delete user cfg
|
|
$this->cDb->_queryUpdate('mod_users', ['user_cfg' => ''], ['id' => $loginData['id']]);
|
|
|
|
// Test to load default values from empty user cfg
|
|
$userConfig = new pubUsersCfg($this->pubSysDashboard, $loginData['id']);
|
|
|
|
$wholeBaseCfg = $userConfig->getBaseCFG();
|
|
|
|
$this->assertEquals(
|
|
[
|
|
'bFullScreen' => 1,
|
|
'bUseDarkMode' => 0,
|
|
/*'logoAnimation' => 1,
|
|
'logoSmall' => 0,*/
|
|
'bShowBtnLabels' => 1,
|
|
],
|
|
$wholeBaseCfg[pubUsersCfg::bools]
|
|
);
|
|
|
|
$this->assertEquals(
|
|
[
|
|
'iRecordsPerPage' => 20,
|
|
'iActiveYear' => [],
|
|
'vFavoriteCompanyList' => [],
|
|
],
|
|
$userConfig->getBaseCFG(pubUsersCfg::values)
|
|
);
|
|
}
|
|
|
|
public function testGetAndSetProperty(): void
|
|
{
|
|
$loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed);
|
|
|
|
// Delete user cfg
|
|
$this->cDb->_queryUpdate('mod_users', ['user_cfg' => ''], ['id' => $loginData['id']]);
|
|
|
|
// Test to load default values from empty user cfg
|
|
$userConfig = new pubUsersCfg($this->pubSysDashboard, $loginData['id']);
|
|
|
|
$this->assertFalse(
|
|
$userConfig->getProperty('None_existing_property')
|
|
);
|
|
|
|
$userConfig->addProperties('bUseDarkMode', '2025-YEAR');
|
|
$this->assertEquals(
|
|
'2025-YEAR',
|
|
$userConfig->getProperty('bUseDarkMode')
|
|
);
|
|
|
|
// Test table properties
|
|
$this->assertFalse(
|
|
$userConfig->getTableProperty('None_existing_property')
|
|
);
|
|
|
|
$this->assertEquals(
|
|
[],
|
|
$userConfig->getTableProperty('pubPartners')
|
|
);
|
|
|
|
$this->setPost(['table' => 1]);
|
|
$userConfig->addProperties('pubPartners', ['a' => 1]);
|
|
|
|
$this->assertEquals(
|
|
['a' => 1],
|
|
$userConfig->getTableProperty('pubPartners')
|
|
);
|
|
|
|
// Array save
|
|
$userConfig->addProperties(
|
|
[
|
|
'pubPartners' => ['aa' => 1, 'a' => 2],
|
|
'pubUserManager' => ['bb' => 1]
|
|
]
|
|
);
|
|
|
|
$this->assertEquals(
|
|
['aa' => 1, 'a' => 2],
|
|
$userConfig->getTableProperty('pubPartners')
|
|
);
|
|
$this->assertEquals(
|
|
['bb' => 1],
|
|
$userConfig->getTableProperty('pubUserManager')
|
|
);
|
|
}
|
|
|
|
public function testAddPropertiesAdvanced(): void
|
|
{
|
|
$loginData = $this->getLoginCredentialsByType(siteUsers::loginAppSelfEmployed);
|
|
|
|
// Delete user cfg
|
|
$this->cDb->_queryUpdate('mod_users', ['user_cfg' => ''], ['id' => $loginData['id']]);
|
|
|
|
// Test to load default values from empty user cfg
|
|
$userConfig = new pubUsersCfg($this->pubSysDashboard, $loginData['id']);
|
|
|
|
// Test plugins
|
|
$this->assertEquals(
|
|
[],
|
|
$userConfig->getUserCFG(pubUsersCfg::plugins)
|
|
);
|
|
$userConfig->addPropertiesAdvanced(['nonexisting_plugin' => 1], pubUsersCfg::plugins);
|
|
$this->assertEquals(
|
|
[],
|
|
$userConfig->getUserCFG(pubUsersCfg::plugins)
|
|
);
|
|
|
|
// Test values
|
|
$this->assertEquals(
|
|
[
|
|
'iRecordsPerPage' => 20,
|
|
'iActiveYear' => [],
|
|
pubUsersCfg::BaseValuesFavoriteCompanyList => [],
|
|
],
|
|
$userConfig->getUserCFG(pubUsersCfg::values)
|
|
);
|
|
$userConfig->addPropertiesAdvanced(
|
|
['iRecordsPerPage' => 10, 'iActiveYear' => [1,2,3]],
|
|
pubUsersCfg::values
|
|
);
|
|
$this->assertEquals(
|
|
[
|
|
'iRecordsPerPage' => 10,
|
|
'iActiveYear' => [1,2,3],
|
|
pubUsersCfg::BaseValuesFavoriteCompanyList => [],
|
|
],
|
|
$userConfig->getUserCFG(pubUsersCfg::values)
|
|
);
|
|
|
|
// Test advanced value setup
|
|
$this->assertEquals(
|
|
[
|
|
'vDashboardCFG' => [],
|
|
'vAdditionalTableData' => [],
|
|
],
|
|
$userConfig->getUserCFG(pubUsersCfg::values_adv)
|
|
);
|
|
$userConfig->addPropertiesAdvanced(
|
|
['vDashboardCFG' => [10], 'vAdditionalTableData' => [1,2,3]],
|
|
pubUsersCfg::values_adv
|
|
);
|
|
$this->assertEquals(
|
|
[
|
|
'vDashboardCFG' => [10],
|
|
'vAdditionalTableData' => [1,2,3],
|
|
],
|
|
$userConfig->getUserCFG(pubUsersCfg::values_adv)
|
|
);
|
|
|
|
}
|
|
}
|