Skip to content

Commit 64ba417

Browse files
committed
Merge branch 'MAGETWO-34477' into MAGETWO-35150-PR
Conflicts: app/code/Magento/Backend/Block/Menu.php
2 parents ec41e40 + 710a4e4 commit 64ba417

File tree

4 files changed

+148
-14
lines changed

4 files changed

+148
-14
lines changed

app/code/Magento/Backend/Block/Menu.php

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,24 @@ protected function _renderItemCssClass($menuItem, $level)
210210
*/
211211
protected function _renderAnchor($menuItem, $level)
212212
{
213-
return '<a href="' . $menuItem->getUrl() . '" ' . $this->_renderItemAnchorTitle(
214-
$menuItem
215-
) . $this->_renderItemOnclickFunction(
216-
$menuItem
217-
) . ' class="' . $this->_renderAnchorCssClass(
218-
$menuItem,
219-
$level
220-
) . '">' . '<span>' . $this->_getAnchorLabel(
221-
$menuItem
222-
) . '</span>' . '</a>';
213+
if ($level == 1 && $menuItem->getUrl() == '#') {
214+
$output = '<strong class="submenu-group-title" role="presentation">'
215+
. '<span>' . $this->_getAnchorLabel($menuItem) . '</span>'
216+
. '</strong>';
217+
} else {
218+
$output = '<a href="' . $menuItem->getUrl() . '" ' . $this->_renderItemAnchorTitle(
219+
$menuItem
220+
) . $this->_renderItemOnclickFunction(
221+
$menuItem
222+
) . ' class="' . $this->_renderAnchorCssClass(
223+
$menuItem,
224+
$level
225+
) . '">' . '<span>' . $this->_getAnchorLabel(
226+
$menuItem
227+
) . '</span>' . '</a>';
228+
}
229+
230+
return $output;
223231
}
224232

225233
/**
@@ -397,15 +405,16 @@ protected function _columnBrake($items, $limit)
397405
* @param \Magento\Backend\Model\Menu\Item $menuItem
398406
* @param int $level
399407
* @param int $limit
408+
* @param $id int
400409
* @return string HTML code
401410
*/
402-
protected function _addSubMenu($menuItem, $level, $limit)
411+
protected function _addSubMenu($menuItem, $level, $limit, $id = null)
403412
{
404413
$output = '';
405414
if (!$menuItem->hasChildren()) {
406415
return $output;
407416
}
408-
$output .= '<div class="submenu">';
417+
$output .= '<div class="submenu"' . ($level == 0 && isset($id) ? ' aria-labelledby="' . $id . '"' : '') . '>';
409418
$colStops = null;
410419
if ($level == 0 && $limit) {
411420
$colStops = $this->_columnBrake($menuItem->getChildren(), $limit);
@@ -426,6 +435,7 @@ protected function _addSubMenu($menuItem, $level, $limit)
426435
* @param int $limit
427436
* @param array $colBrakes
428437
* @return string HTML
438+
* @SuppressWarnings(PHPMD.NPathComplexity)
429439
*/
430440
public function renderNavigation($menu, $level = 0, $limit = 0, $colBrakes = [])
431441
{
@@ -443,18 +453,21 @@ public function renderNavigation($menu, $level = 0, $limit = 0, $colBrakes = [])
443453
$output .= '</ul></li><li class="column"><ul role="menu">';
444454
}
445455

456+
$id = $this->getJsId($menuItem->getId());
446457
$output .= '<li ' . $this->getUiId(
447458
$menuItem->getId()
448459
) . ' class="item-' . $itemClass . ' ' . $this->_renderItemCssClass(
449460
$menuItem,
450461
$level
451-
) . '" role="menu-item">' . $this->_renderAnchor(
462+
) . ($level == 0 ? '" id="' . $id . '" aria-haspopup="true' : '')
463+
. '" role="menu-item">' . $this->_renderAnchor(
452464
$menuItem,
453465
$level
454466
) . $this->_addSubMenu(
455467
$menuItem,
456468
$level,
457-
$limit
469+
$limit,
470+
$id
458471
) . '</li>';
459472
$itemPosition++;
460473
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Block;
7+
8+
use Magento\Framework\App\Bootstrap;
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\App\State;
11+
12+
/**
13+
* Test class for \Magento\Backend\Block\Menu
14+
*/
15+
class MenuTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var \Magento\Backend\Block\Menu $blockMenu
19+
*/
20+
protected $blockMenu;
21+
22+
/** @var \Magento\Framework\App\Cache\Type\Config $configCacheType */
23+
protected $configCacheType;
24+
25+
protected function setUp()
26+
{
27+
$this->configCacheType = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
28+
'Magento\Framework\App\Cache\Type\Config'
29+
);
30+
$this->configCacheType->save('', \Magento\Backend\Model\Menu\Config::CACHE_MENU_OBJECT);
31+
32+
$this->blockMenu = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
33+
'Magento\Backend\Block\Menu'
34+
);
35+
}
36+
37+
public function testRenderNavigation()
38+
{
39+
$menuConfig = $this->prepareMenuConfig();
40+
41+
$this->assertStringEqualsFile(
42+
__DIR__ . '/_files/menu/expected.txt',
43+
$this->blockMenu->renderNavigation($menuConfig->getMenu())
44+
);
45+
}
46+
47+
/**
48+
* @return \Magento\Backend\Model\Menu\Config
49+
*/
50+
protected function prepareMenuConfig()
51+
{
52+
$this->loginAdminUser();
53+
54+
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize(
55+
[
56+
Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS => [
57+
DirectoryList::MODULES => ['path' => __DIR__ . '/_files/menu'],
58+
],
59+
]
60+
);
61+
62+
/* @var $validationState \Magento\Framework\App\Arguments\ValidationState */
63+
$validationState = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
64+
'Magento\Framework\App\Arguments\ValidationState',
65+
['appMode' => State::MODE_DEFAULT]
66+
);
67+
68+
/* @var $configReader \Magento\Backend\Model\Menu\Config\Reader */
69+
$configReader = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
70+
'Magento\Backend\Model\Menu\Config\Reader',
71+
['validationState' => $validationState]
72+
);
73+
74+
return \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
75+
'Magento\Backend\Model\Menu\Config',
76+
[
77+
'configReader' => $configReader,
78+
'configCacheType' => $this->configCacheType
79+
]
80+
);
81+
}
82+
83+
/**
84+
* @return void
85+
*/
86+
protected function loginAdminUser()
87+
{
88+
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()
89+
->get('Magento\Backend\Model\UrlInterface')
90+
->turnOffSecretKey();
91+
92+
$auth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Backend\Model\Auth');
93+
$auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD);
94+
}
95+
96+
/**
97+
* @return void
98+
*/
99+
protected function tearDown()
100+
{
101+
$this->configCacheType->save('', \Magento\Backend\Model\Menu\Config::CACHE_MENU_OBJECT);
102+
}
103+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config>
9+
<menu>
10+
<add id="Magento_Backend::system" title="System" module="Magento_Backend" sortOrder="30" resource="Magento_Backend::system"/>
11+
<add id="Magento_Backend::system_report" title="Report" module="Magento_Backend" sortOrder="10" parent="Magento_Backend::system" resource="Magento_Backend::report"/>
12+
13+
<add id="Magento_Backend::system_report_private_sales" title="Private Sales" module="Magento_Backend" sortOrder="10" parent="Magento_Backend::system_report" resource="Magento_Backend::report_private_sales" />
14+
<add id="Magento_Backend::system_report_magento_invite_general" title="Invite" module="Magento_Backend" sortOrder="20" parent="Magento_Backend::system_report" resource="Magento_Backend::report_magento_invite_general"/>
15+
<add id="Magento_Backend::system_report_magento_invite_customer" title="Invited Customers" module="Magento_Backend" sortOrder="30" parent="Magento_Backend::system_report" resource="Magento_Backend::report_magento_invite_customer"/>
16+
</menu>
17+
</config>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ul id="nav" ><li data-ui-id="magento-backend-system" class="item-system parent last level-0" id="magento-backend-system" aria-haspopup="true"><a href="#" onclick="return false;" class=""><span>System</span></a><div class="submenu" aria-labelledby="magento-backend-system"><ul ><li data-ui-id="magento-backend-system-report" class="item-system-report parent level-1"><strong class="submenu-group-title" role="presentation"><span>Report</span></strong><div class="submenu"><ul ><li data-ui-id="magento-backend-system-report-private-sales" class="item-system-report-private-sales level-2"><a href="#" onclick="return false;" class=""><span>Private Sales</span></a></li><li data-ui-id="magento-backend-system-report-magento-invite-general" class="item-system-report-magento-invite-general level-2"><a href="#" onclick="return false;" class=""><span>Invite</span></a></li><li data-ui-id="magento-backend-system-report-magento-invite-customer" class="item-system-report-magento-invite-customer level-2"><a href="#" onclick="return false;" class=""><span>Invited Customers</span></a></li></ul></div></li></ul></div></li></ul>

0 commit comments

Comments
 (0)