N°5620 - conf param renaming + backward compatibility test

This commit is contained in:
odain
2022-11-21 09:56:56 +01:00
parent 174cace20a
commit 0b03b3ef4d
3 changed files with 95 additions and 10 deletions

View File

@@ -333,14 +333,6 @@ class Config
'source_of_value' => '',
'show_in_conf_sample' => false,
],
'allow_menu_organization_filter' => [
'type' => 'bool',
'description' => 'Display organization filter in menu',
'default' => true,
'value' => true,
'source_of_value' => '',
'show_in_conf_sample' => false,
],
'allow_target_creation' => [
'type' => 'bool',
'description' => 'Displays the + button on external keys to create target objects',
@@ -1246,6 +1238,14 @@ class Config
'source_of_value' => '',
'show_in_conf_sample' => false,
],
'navigation_menu.show_organization_filter' => [
'type' => 'bool',
'description' => 'Display organization filter in menu',
'default' => true,
'value' => true,
'source_of_value' => '',
'show_in_conf_sample' => false,
],
'quick_create.enabled' => [
'type' => 'bool',
'description' => 'Whether or not the quick create is enabled',

View File

@@ -19,7 +19,6 @@
namespace Combodo\iTop\Application\UI\Base\Layout\NavigationMenu;
use ApplicationContext;
use ApplicationMenu;
use appUserPreferences;
@@ -290,6 +289,10 @@ class NavigationMenu extends UIBlock implements iKeyboardShortcut
}
}
private function IsOrgMenuFilterAllowed() : bool {
return MetaModel::GetConfig()->Get('navigation_menu.show_organization_filter');
}
/**
* @return void
* @throws \CoreException
@@ -301,7 +304,7 @@ class NavigationMenu extends UIBlock implements iKeyboardShortcut
$this->bHasSiloSelected = false;
$this->sSiloLabel = null;
if (! MetaModel::GetConfig()->Get('allow_menu_organization_filter')){
if (! $this->IsOrgMenuFilterAllowed()){
return;
}

View File

@@ -0,0 +1,82 @@
<?php
namespace UI\Base\Layout;
use ApplicationContext;
use Combodo\iTop\Application\UI\Base\Component\PopoverMenu\PopoverMenu;
use Combodo\iTop\Application\UI\Base\Layout\NavigationMenu\NavigationMenu;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
class NavigationMenuTest extends ItopDataTestCase {
private $oConfigToRestore;
public function setUp(): void
{
parent::setUp();
require_once(APPROOT.'application/themehandler.class.inc.php');
$this->oConfigToRestore = null;
}
public function tearDown(): void
{
if (! is_null($this->oConfigToRestore)){
$oReflexionClass = new \ReflectionClass(\MetaModel::class);
$oReflexionClass->setStaticPropertyValue('m_oConfig', $this->oConfigToRestore);
}
}
public function IsAllowedProvider(){
return [
'show menu' => [ true ],
'hide menu' => [ false ],
];
}
/**
* @dataProvider IsAllowedProvider
* test used to make sure backward compatibility is ensured
*/
public function testIsAllowed($bExpectedIsAllowed=true){
\MetaModel::GetConfig()->Set('navigation_menu.show_organization_filter', $bExpectedIsAllowed);
$oNavigationMenu = new NavigationMenu(
$this->createMock(ApplicationContext::class),
$this->createMock(PopoverMenu::class));
$isAllowed = $this->InvokeNonPublicMethod(NavigationMenu::class, "IsOrgMenuFilterAllowed", $oNavigationMenu, []);
$this->assertEquals($bExpectedIsAllowed, $isAllowed);
}
public function testIsAllowedWithNoConfVariable(){
\MetaModel::GetConfig()->Set('navigation_menu.show_organization_filter', false);
$sTmpFilePath = tempnam(sys_get_temp_dir(), 'test_');
$oInitConfig = \MetaModel::GetConfig();
$oInitConfig->WriteToFile($sTmpFilePath);
//remove variable for the test
$aLines = file($sTmpFilePath);
$aRows = array();
foreach ($aLines as $key => $sLine) {
if (!preg_match('/navigation_menu.show_organization_filter/', $sLine)) {
$aRows[] = $sLine;
}
}
file_put_contents($sTmpFilePath, implode("\n", $aRows));
$oTempConfig = new \Config($sTmpFilePath);
$this->oConfigToRestore = $oInitConfig;
$oReflexionClass = new \ReflectionClass(\MetaModel::class);
$oReflexionClass->setStaticPropertyValue('m_oConfig', $oTempConfig);
$oNavigationMenu = new NavigationMenu(
$this->createMock(ApplicationContext::class),
$this->createMock(PopoverMenu::class)
);
$isAllowed = $this->InvokeNonPublicMethod(NavigationMenu::class, "IsOrgMenuFilterAllowed", $oNavigationMenu, []);
$this->assertEquals(true, $isAllowed);
}
}