Skip to content

Commit 26f5eac

Browse files
author
okarpenko
committed
MAGETWO-30068: Customer menu tabs aren't displayed as selected for child pages
- Add plugin for selecting menu
1 parent 71075b4 commit 26f5eac

File tree

3 files changed

+152
-0
lines changed
  • app/code/Magento/Theme/etc
  • dev/tests/unit/testsuite/Magento/View/Element/Html/Link/Current

3 files changed

+152
-0
lines changed

app/code/Magento/Theme/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@
5252
<type name="Magento\Framework\Url\ScopeInterface">
5353
<plugin name="urlSignature" type="Magento\Theme\Model\Url\Plugin\Signature"/>
5454
</type>
55+
<type name="Magento\Framework\View\Element\Html\Link\Current">
56+
<plugin name="saleOrderViewMenu" type="Magento\Framework\View\Plugin\Element\Html\Link\Current"/>
57+
</type>
5558
</config>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\View\Element\Html\Link\Current;
7+
8+
use Magento\Framework\View\Plugin\Element\Html\Link as Plugin;
9+
use Magento\TestFramework\Helper\ObjectManager as ObjectManagerHelper;
10+
11+
class PluginTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var ObjectManagerHelper
15+
*/
16+
protected $objectManagerHelper;
17+
18+
/**
19+
* @var \PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $link;
22+
23+
/**
24+
* @var \PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
protected $plugin;
27+
28+
/**
29+
* @var \PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
protected $request;
32+
33+
protected function setUp()
34+
{
35+
$this->objectManagerHelper = new ObjectManagerHelper($this);
36+
37+
$context = $this->getMock(
38+
'Magento\Framework\View\Element\Template\Context',
39+
null,
40+
[],
41+
'',
42+
false
43+
);
44+
$defaultPath = $this->getMock(
45+
'Magento\Framework\App\DefaultPath\DefaultPath',
46+
null,
47+
[],
48+
'',
49+
false
50+
);
51+
$this->link = $this->getMock(
52+
'Magento\Framework\View\Element\Html\Link\Current',
53+
[
54+
'getRequest',
55+
'getNameInLayout'
56+
],
57+
[$context, $defaultPath]
58+
);
59+
$this->request = $this->getMock(
60+
'Magento\Framework\App\Request\Http',
61+
[
62+
'getModuleName',
63+
'getControllerName',
64+
'getActionName'
65+
],
66+
[],
67+
'',
68+
false
69+
);
70+
$this->plugin = new Plugin\Current();
71+
72+
$this->configuringLinkObject();
73+
}
74+
75+
protected function configuringLinkObject()
76+
{
77+
$this->configuringRequestObject();
78+
79+
$this->link
80+
->expects($this->once())
81+
->method('getRequest')
82+
->will($this->returnValue($this->request));
83+
$this->link
84+
->expects($this->once())
85+
->method('getNameInLayout')
86+
->will($this->returnValue('customer-account-navigation-orders-link'));
87+
}
88+
89+
90+
protected function configuringRequestObject()
91+
{
92+
$this->request
93+
->expects($this->once())
94+
->method('getModuleName')
95+
->will($this->returnValue('sales'));
96+
$this->request
97+
->expects($this->once())
98+
->method('getControllerName')
99+
->will($this->returnValue('order'));
100+
$this->request
101+
->expects($this->once())
102+
->method('getActionName')
103+
->will($this->returnValue('view'));
104+
}
105+
106+
public function testIsCurrentOnSalesOrderViewPage()
107+
{
108+
$this->plugin->beforeIsCurrent($this->link);
109+
110+
$this->assertTrue($this->link->getData('current'));
111+
}
112+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\View\Plugin\Element\Html\Link;
7+
8+
use Magento\Framework\View\Element\Html\Link;
9+
10+
class Current
11+
{
12+
public function beforeIsCurrent(\Magento\Framework\View\Element\Html\Link\Current $subject)
13+
{
14+
if (
15+
$this->isSalesOrderViewPage($subject)
16+
&& 'customer-account-navigation-orders-link' == $subject->getNameInLayout()
17+
) {
18+
$subject->setData('current', true);
19+
}
20+
}
21+
22+
/**
23+
* @return bool
24+
*/
25+
public function isSalesOrderViewPage(\Magento\Framework\View\Element\Html\Link\Current $subject)
26+
{
27+
$request = $subject->getRequest();
28+
if (
29+
$request->getModuleName() == 'sales'
30+
&& $request->getControllerName() == 'order'
31+
&& $request->getActionName() == 'view'
32+
) {
33+
return true;
34+
}
35+
return false;
36+
}
37+
}

0 commit comments

Comments
 (0)