Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
MenuTest Class Reference
Inheritance diagram for MenuTest:

Public Member Functions

 testRenderNavigation ()
 

Protected Member Functions

 setUp ()
 
 prepareMenuConfig ()
 
 loginAdminUser ()
 
 tearDown ()
 

Protected Attributes

 $blockMenu
 
 $configCacheType
 
 $backupRegistrar
 

Detailed Description

Test class for \Magento\Backend\Block\Menu @magentoAppArea adminhtml @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 16 of file MenuTest.php.

Member Function Documentation

◆ loginAdminUser()

loginAdminUser ( )
protected
Returns
void

Definition at line 141 of file MenuTest.php.

142  {
144  ->get(\Magento\Backend\Model\UrlInterface::class)
145  ->turnOffSecretKey();
146 
147  $auth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Auth::class);
148  $auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD);
149  }

◆ prepareMenuConfig()

prepareMenuConfig ( )
protected
Returns
\Magento\Backend\Model\Menu\Config

Definition at line 88 of file MenuTest.php.

89  {
90  $this->loginAdminUser();
91 
92  $componentRegistrar = new \Magento\Framework\Component\ComponentRegistrar();
93  $libraryPath = $componentRegistrar->getPath(ComponentRegistrar::LIBRARY, 'magento/framework');
94 
95  $reflection = new \ReflectionClass(\Magento\Framework\Component\ComponentRegistrar::class);
96  $paths = $reflection->getProperty('paths');
97  $paths->setAccessible(true);
98 
99  $paths->setValue(
100  [
105  ]
106  );
107  $paths->setAccessible(false);
108 
110 
113  'Magento_Backend',
114  __DIR__ . '/_files/menu/Magento/Backend'
115  );
116 
117  /* @var $validationState \Magento\Framework\App\Arguments\ValidationState */
119  \Magento\Framework\App\Arguments\ValidationState::class,
120  ['appMode' => State::MODE_DEFAULT]
121  );
122 
123  /* @var $configReader \Magento\Backend\Model\Menu\Config\Reader */
125  \Magento\Backend\Model\Menu\Config\Reader::class,
126  ['validationState' => $validationState]
127  );
128 
129  return \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
130  \Magento\Backend\Model\Menu\Config::class,
131  [
132  'configReader' => $configReader,
133  'configCacheType' => $this->configCacheType
134  ]
135  );
136  }
$componentRegistrar
Definition: bootstrap.php:23
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
static register($type, $componentName, $path)
if(isset($opts->l)) $libraryPath
$paths
Definition: _bootstrap.php:83

◆ setUp()

setUp ( )
protected

Definition at line 36 of file MenuTest.php.

37  {
38  $this->configCacheType = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
39  \Magento\Framework\App\Cache\Type\Config::class
40  );
41  $this->configCacheType->save('', \Magento\Backend\Model\Menu\Config::CACHE_MENU_OBJECT);
42 
43  $reflection = new \ReflectionClass(\Magento\Framework\Component\ComponentRegistrar::class);
44  $paths = $reflection->getProperty('paths');
45  $paths->setAccessible(true);
46  $this->backupRegistrar = $paths->getValue();
47  $paths->setAccessible(false);
48 
49  $this->menuConfig = $this->prepareMenuConfig();
50 
52  \Magento\Backend\Block\Menu::class,
53  ['menuConfig' => $this->menuConfig]
54  );
55  }
$paths
Definition: _bootstrap.php:83

◆ tearDown()

tearDown ( )
protected
Returns
void

Definition at line 154 of file MenuTest.php.

155  {
156  $this->configCacheType->save('', \Magento\Backend\Model\Menu\Config::CACHE_MENU_OBJECT);
157  $reflection = new \ReflectionClass(\Magento\Framework\Component\ComponentRegistrar::class);
158  $paths = $reflection->getProperty('paths');
159  $paths->setAccessible(true);
160  $paths->setValue($this->backupRegistrar);
161  $paths->setAccessible(false);
162  }
$paths
Definition: _bootstrap.php:83

◆ testRenderNavigation()

testRenderNavigation ( )

Verify that Admin Navigation Menu elements have correct titles & are located on correct levels

Definition at line 60 of file MenuTest.php.

61  {
62  $menuHtml = $this->blockMenu->renderNavigation($this->menuConfig->getMenu());
63  $menu = new \SimpleXMLElement($menuHtml);
64 
65  $item = $menu->xpath('/ul/li/a/span')[0];
66  $this->assertEquals('System', (string)$item, '"System" item is absent or located on wrong menu level.');
67 
68  $item = $menu->xpath('/ul//ul/li/strong/span')[0];
69  $this->assertEquals('Report', (string)$item, '"Report" item is absent or located on wrong menu level.');
70 
71  $liTitles = [
72  'Private Sales',
73  'Invite',
74  'Invited Customers',
75  ];
76  foreach ($menu->xpath('/ul//ul//ul/li/a/span') as $sortOrder => $item) {
77  $this->assertEquals(
78  $liTitles[$sortOrder],
79  (string)$item,
80  '"' . $liTitles[$sortOrder] . '" item is absent or located on wrong menu level.'
81  );
82  }
83  }

Field Documentation

◆ $backupRegistrar

$backupRegistrar
protected

Definition at line 29 of file MenuTest.php.

◆ $blockMenu

Magento Backend Block Menu $blockMenu
protected

Definition at line 21 of file MenuTest.php.

◆ $configCacheType

$configCacheType
protected

Definition at line 24 of file MenuTest.php.


The documentation for this class was generated from the following file: