123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Backend\Model;
- /**
- * Test class for \Magento\Backend\Model\Auth.
- *
- * @magentoAppArea adminhtml
- */
- class MenuTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Backend\Model\Menu
- */
- private $model;
- /** @var \Magento\Framework\ObjectManagerInterface */
- private $objectManager;
- protected function setUp()
- {
- parent::setUp();
- \Magento\TestFramework\Helper\Bootstrap::getInstance()
- ->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
- $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
- $this->model = $this->objectManager->create(\Magento\Backend\Model\Auth::class);
- $this->objectManager->get(\Magento\Framework\Config\ScopeInterface::class)
- ->setCurrentScope(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
- }
- public function testMenuItemManipulation()
- {
- /* @var $menu \Magento\Backend\Model\Menu */
- $menu = $this->objectManager->create(\Magento\Backend\Model\Menu\Config::class)->getMenu();
- /* @var $itemFactory \Magento\Backend\Model\Menu\Item\Factory */
- $itemFactory = $this->objectManager->create(\Magento\Backend\Model\Menu\Item\Factory::class);
- // Add new item in top level
- $menu->add(
- $itemFactory->create(
- [
- 'id' => 'Magento_Backend::system2',
- 'title' => 'Extended System',
- 'module' => 'Magento_Backend',
- 'resource' => 'Magento_Backend::system2',
- ]
- )
- );
- // Add submenu
- $menu->add(
- $itemFactory->create(
- [
- 'id' => 'Magento_Backend::system2_acl',
- 'title' => 'Acl',
- 'module' => 'Magento_Backend',
- 'action' => 'admin/backend/acl/index',
- 'resource' => 'Magento_Backend::system2_acl',
- ]
- ),
- 'Magento_Backend::system2'
- );
- // Modify existing menu item
- $menu->get('Magento_Backend::system2')->setTitle('Base system')->setAction('admin/backend/system/base');
- // remove dependency from config
- // Change sort order
- $menu->reorder('Magento_Backend::system', 40);
- // Remove menu item
- $menu->remove('Magento_Backend::catalog_attribute');
- // Move menu item
- $menu->move('Magento_Catalog::catalog_products', 'Magento_Backend::system2');
- }
- /**
- * @magentoAppIsolation enabled
- */
- public function testSerialize()
- {
- /** @var Menu $menu */
- $menu = $this->objectManager->get(\Magento\Backend\Model\MenuFactory::class)->create();
- /* @var \Magento\Backend\Model\Menu\Item\Factory $itemFactory */
- $itemFactory = $this->objectManager->create(\Magento\Backend\Model\Menu\Item\Factory::class);
- // Add new item in top level
- $menu->add(
- $itemFactory->create(
- [
- 'id' => 'Magento_Backend::system3',
- 'title' => 'Extended System',
- 'module' => 'Magento_Backend',
- 'resource' => 'Magento_Backend::system3',
- 'dependsOnConfig' => 'dev/test/system',
- ]
- )
- );
- // Add submenu
- $menu->add(
- $itemFactory->create(
- [
- 'id' => 'Magento_Backend::system3_acl',
- 'title' => 'Acl',
- 'module' => 'Magento_Backend',
- 'action' => 'admin/backend/acl/index',
- 'resource' => 'Magento_Backend::system3_acl',
- ]
- ),
- 'Magento_Backend::system3'
- );
- $serializedString = $menu->serialize();
- $expected = '[{"parent_id":null,"module":"Magento_Backend","sort_index":null,'
- . '"dependsOnConfig":"dev\/test\/system",'
- . '"id":"Magento_Backend::system3","resource":"Magento_Backend::system3","path":"","action":null,'
- . '"dependsOnModule":null,"toolTip":null,"title":"Extended System",'
- . '"target":null,"sub_menu":[{"parent_id":null,"module":"Magento_Backend","sort_index":null,'
- . '"dependsOnConfig":null,"id":"Magento_Backend::system3_acl","resource":"Magento_Backend::system3_acl",'
- . '"path":"","action":"admin\/backend\/acl\/index","dependsOnModule":null,"toolTip":null,"title":"Acl",'
- . '"target":null,"sub_menu":null}]}]';
- $this->assertEquals($expected, $serializedString);
- }
- /**
- * @magentoAppIsolation enabled
- */
- public function testUnserialize()
- {
- $serializedMenu = '[{"parent_id":null,"module":"Magento_Backend","sort_index":null,'
- . '"dependsOnConfig":"dev\/test","id":"Magento_Backend::system3","resource":"Magento_Backend::system3",'
- . '"path":"","action":null,"dependsOnModule":null,"toolTip":null,"title":"Extended System",'
- . '"target":null,"sub_menu":[{"parent_id":null,"module":"Magento_Backend","sort_index":null,'
- . '"dependsOnConfig":null,"id":"Magento_Backend::system3_acl","resource":"Magento_Backend::system3_acl",'
- . '"path":"","action":"admin\/backend\/acl\/index","dependsOnModule":null,"toolTip":null,"title":"Acl",'
- . '"target":null,"sub_menu":null}]}]';
- /** @var Menu $menu */
- $menu = $this->objectManager->get(\Magento\Backend\Model\MenuFactory::class)->create();
- $menu->unserialize($serializedMenu);
- $expected = [
- [
- 'parent_id' => null,
- 'module' => 'Magento_Backend',
- 'sort_index' => null,
- 'dependsOnConfig' => 'dev/test',
- 'id' => 'Magento_Backend::system3',
- 'resource' => 'Magento_Backend::system3',
- 'path' => '',
- 'action' => null,
- 'dependsOnModule' => null,
- 'toolTip' => null,
- 'title' => 'Extended System',
- 'target' => null,
- 'sub_menu' =>
- [
- [
- 'parent_id' => null,
- 'module' => 'Magento_Backend',
- 'sort_index' => null,
- 'dependsOnConfig' => null,
- 'id' => 'Magento_Backend::system3_acl',
- 'resource' => 'Magento_Backend::system3_acl',
- 'path' => '',
- 'action' => 'admin/backend/acl/index',
- 'dependsOnModule' => null,
- 'toolTip' => null,
- 'title' => 'Acl',
- 'sub_menu' => null,
- 'target' => null
- ],
- ],
- ],
- ];
- $this->assertEquals($expected, $menu->toArray());
- }
- }
|