From a5d9b15dfe0a75cc1b324a8a273bfba0538b0399 Mon Sep 17 00:00:00 2001 From: odain Date: Wed, 17 May 2023 15:12:27 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B06293-add=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PopoverMenu/PopoverMenuFactory.php | 12 +-- .../PopoverMenu/PopoverMenuFactoryTest.php | 96 +++++++++++++++++++ 2 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 tests/php-unit-tests/unitary-tests/application/UI/Base/Component/PopoverMenu/PopoverMenuFactoryTest.php diff --git a/sources/Application/UI/Base/Component/PopoverMenu/PopoverMenuFactory.php b/sources/Application/UI/Base/Component/PopoverMenu/PopoverMenuFactory.php index 66bef8980..cd8670937 100644 --- a/sources/Application/UI/Base/Component/PopoverMenu/PopoverMenuFactory.php +++ b/sources/Application/UI/Base/Component/PopoverMenu/PopoverMenuFactory.php @@ -62,23 +62,13 @@ class PopoverMenuFactory // Allowed portals $aAllowedPortalsItems = static::PrepareAllowedPortalsItemsForUserMenu(); self::AddPopoverMenuItems($aAllowedPortalsItems, $aUserMenuItems); - /*if (!empty($aAllowedPortalsItems)) { - $oMenu->AddSection('allowed_portals') - ->SetItems('allowed_portals', $aAllowedPortalsItems); - }*/ // User related pages self::AddPopoverMenuItems(static::PrepareUserRelatedItemsForUserMenu(), $aUserMenuItems); - /*$oMenu->AddSection('user_related') - ->SetItems('user_related', static::PrepareUserRelatedItemsForUserMenu());*/ // API: iPopupMenuExtension::MENU_USER_ACTIONS $aAPIItems = static::PrepareAPIItemsForUserMenu($oMenu); self::AddPopoverMenuItems($aAPIItems, $aUserMenuItems); - /*if (count($aAPIItems) > 0) { - $oMenu->AddSection('popup_menu_extension-menu_user_actions') - ->SetItems('popup_menu_extension-menu_user_actions', $aAPIItems); - }*/ // Misc links /*$oMenu->AddSection('misc') @@ -112,7 +102,7 @@ class PopoverMenuFactory */ private static function SortPopoverMenuItems(array &$aUserMenuItems) : void { $aSortedMenusFromConfig = MetaModel::GetConfig()->Get('navigation_menu.sorted_popup_user_menu_items'); - if (empty($aSortedMenusFromConfig)){ + if (!is_array($aSortedMenusFromConfig) || empty($aSortedMenusFromConfig)){ return; } diff --git a/tests/php-unit-tests/unitary-tests/application/UI/Base/Component/PopoverMenu/PopoverMenuFactoryTest.php b/tests/php-unit-tests/unitary-tests/application/UI/Base/Component/PopoverMenu/PopoverMenuFactoryTest.php new file mode 100644 index 000000000..5072c2aa3 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/application/UI/Base/Component/PopoverMenu/PopoverMenuFactoryTest.php @@ -0,0 +1,96 @@ + [ + 'aConf' => null, + 'aExpectedMenuUIDs' => $aNotSortedMenuUIDs + ], + 'not an array conf' => [ + 'aConf' => "wrong conf", + 'aExpectedMenuUIDs' => $aNotSortedMenuUIDs + ], + 'default conf' => [ + 'aConf' => [], + 'aExpectedMenuUIDs' => $aNotSortedMenuUIDs + ], + 'same order in conf' => [ + 'aConf' => [ + 'portal:itop-portal', + 'UI:Preferences', + 'UI:Help', + 'UI:AboutBox', + ], + 'aExpectedMenuUIDs' => $aNotSortedMenuUIDs + ], + 'first menus sorted and last one missing in conf' => [ + 'aConf' => [ + "portal:itop-portal", + "UI:Preferences", + ], + 'aExpectedMenuUIDs' => $aNotSortedMenuUIDs + ], + 'some menus but not all sorted' => [ + 'aConf' => [ + 'UI:Preferences', + 'UI:AboutBox', + ], + 'aExpectedMenuUIDs' => [ + 'UI_Preferences', + 'UI_AboutBox', + 'portal_itop_portal', + 'UI_Help', + ] + ], + 'all user menu sorted' => [ + 'aConf' => [ + 'UI:Preferences', + 'UI:AboutBox', + 'portal:itop-portal', + 'UI:Help', + ], + 'aExpectedMenuUIDs' => [ + 'UI_Preferences', + 'UI_AboutBox', + 'portal_itop_portal', + 'UI_Help', + ] + ], + ]; + } + /** + * @dataProvider MakeUserMenuForNavigationMenuProvider + */ + public function testMakeUserMenuForNavigationMenu($aConf, $aExpectedMenuUIDs){ + if (! is_null($aConf)){ + \MetaModel::GetConfig()->Set('navigation_menu.sorted_popup_user_menu_items', $aConf); + } + + $aRes = PopoverMenuFactory::MakeUserMenuForNavigationMenu()->GetSections(); + $this->assertTrue(array_key_exists('misc', $aRes)); + $aUIDsWithDummyRandoString = array_keys($aRes['misc']['aItems']); + //replace ibo-popover-menu--item-6464cdca5ecf4214716943--UI_AboutBox by UI_AboutBox (for ex) + $aUIDs = preg_replace('/ibo-popover-menu--item-([^\-]+)--/', '', $aUIDsWithDummyRandoString); + $this->assertEquals($aExpectedMenuUIDs, $aUIDs); + } +}