diff --git a/core/config.class.inc.php b/core/config.class.inc.php index 24df38c92..922293951 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -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', diff --git a/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenu.php b/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenu.php index 96ef70cc5..325b2783b 100644 --- a/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenu.php +++ b/sources/application/UI/Base/Layout/NavigationMenu/NavigationMenu.php @@ -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; } diff --git a/test/application/UI/Base/Layout/NavigationMenuTest.php b/test/application/UI/Base/Layout/NavigationMenuTest.php new file mode 100644 index 000000000..d63aee192 --- /dev/null +++ b/test/application/UI/Base/Layout/NavigationMenuTest.php @@ -0,0 +1,82 @@ +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); + } +}