Skip to content

Commit 56703c5

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-30068' into BUGS
2 parents 02b5f9a + 4b7315a commit 56703c5

File tree

4 files changed

+98
-38
lines changed

4 files changed

+98
-38
lines changed

app/code/Magento/Sales/Controller/AbstractController/View.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function execute()
5252
$resultPage = $this->resultPageFactory->create();
5353
$resultPage->getLayout()->initMessages();
5454

55+
/** @var \Magento\Framework\View\Element\Html\Links $navigationBlock */
5556
$navigationBlock = $resultPage->getLayout()->getBlock('customer_account_navigation');
5657
if ($navigationBlock) {
5758
$navigationBlock->setActive('sales/order/history');

lib/internal/Magento/Framework/View/Element/Html/Link/Current.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,19 @@ protected function _toHtml()
110110
$html .= $this->getTitle()
111111
? ' title="' . $this->escapeHtml((string)new \Magento\Framework\Phrase($this->getTitle())) . '"'
112112
: '';
113-
$html .= '>' . $this->escapeHtml((string)new \Magento\Framework\Phrase($this->getLabel())) . '</a></li>';
113+
$html .= '>';
114+
115+
if ($this->getIsHighlighted()) {
116+
$html .= '<strong>';
117+
}
118+
119+
$html .= $this->escapeHtml((string)new \Magento\Framework\Phrase($this->getLabel()));
120+
121+
if ($this->getIsHighlighted()) {
122+
$html .= '</strong>';
123+
}
124+
125+
$html .= '</a></li>';
114126
}
115127

116128
return $html;

lib/internal/Magento/Framework/View/Element/Html/Links.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,35 @@ public function getLinks()
2020
return $this->_layout->getChildBlocks($this->getNameInLayout());
2121
}
2222

23+
/**
24+
* Find link by path
25+
*
26+
* @param string $path
27+
* @return \Magento\Framework\View\Element\Html\Link
28+
*/
29+
protected function getLinkByPath($path)
30+
{
31+
foreach ($this->getLinks() as $link) {
32+
if ($link->getPath() == $path) {
33+
return $link;
34+
}
35+
}
36+
}
37+
38+
/**
39+
* Set active link
40+
*
41+
* @param string $path
42+
* @return void
43+
*/
44+
public function setActive($path)
45+
{
46+
$link = $this->getLinkByPath($path);
47+
if ($link) {
48+
$link->setIsHighlighted(true);
49+
}
50+
}
51+
2352
/**
2453
* Render Block
2554
*

lib/internal/Magento/Framework/View/Test/Unit/Element/Html/LinksTest.php

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,70 +5,88 @@
55
*/
66
namespace Magento\Framework\View\Test\Unit\Element\Html;
77

8+
use Magento\Framework\View\Element\Html\Links;
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Framework\View\Element\Template\Context;
11+
812
class LinksTest extends \PHPUnit_Framework_TestCase
913
{
1014
/**
11-
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
15+
* @var ObjectManager|\PHPUnit_Framework_MockObject_MockObject
1216
*/
13-
protected $_objectManagerHelper;
17+
protected $objectManagerHelper;
1418

15-
/** @var \Magento\Framework\View\Element\Html\Links */
16-
protected $_block;
19+
/** @var Links|\PHPUnit_Framework_MockObject_MockObject */
20+
protected $block;
1721

18-
/** @var \Magento\Framework\View\Element\Template\Context */
19-
protected $_context;
22+
/** @var Context|\PHPUnit_Framework_MockObject_MockObject */
23+
protected $context;
2024

2125
protected function setUp()
2226
{
23-
$this->_objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
24-
25-
/** @var \Magento\Framework\View\Element\Template\Context $context */
26-
$this->_context = $this->_objectManagerHelper->getObject('Magento\Framework\View\Element\Template\Context');
27+
$this->objectManagerHelper = new ObjectManager($this);
2728

28-
/** @var \Magento\Framework\View\Element\Html\Links $block */
29-
$this->_block = $this->_objectManagerHelper->getObject(
30-
'Magento\Framework\View\Element\Html\Links',
31-
['context' => $this->_context]
32-
);
29+
/** @var Context $context */
30+
$this->context = $this->objectManagerHelper->getObject('Magento\Framework\View\Element\Template\Context');
31+
$this->block = new Links($this->context);
3332
}
3433

3534
public function testGetLinks()
3635
{
3736
$blocks = [0 => 'blocks'];
3837
$name = 'test_name';
39-
$this->_context->getLayout()->expects(
40-
$this->once()
41-
)->method(
42-
'getChildBlocks'
43-
)->with(
44-
$name
45-
)->will(
46-
$this->returnValue($blocks)
47-
);
48-
$this->_block->setNameInLayout($name);
49-
$this->assertEquals($blocks, $this->_block->getLinks());
38+
$this->context->getLayout()
39+
->expects($this->once())
40+
->method('getChildBlocks')
41+
->with($name)
42+
->willReturn($blocks);
43+
$this->block->setNameInLayout($name);
44+
$this->assertEquals($blocks, $this->block->getLinks());
45+
}
46+
47+
public function testSetActive()
48+
{
49+
$link = $this->getMock('Magento\Framework\View\Element\Html\Link', [], [], '', false);
50+
$link
51+
->expects($this->at(1))
52+
->method('__call')
53+
->with('setIsHighlighted', [true]);
54+
$link
55+
->expects($this->at(0))
56+
->method('__call')
57+
->with('getPath', [])
58+
->willReturn('test/path');
59+
60+
$name = 'test_name';
61+
$this->context->getLayout()
62+
->expects($this->once())
63+
->method('getChildBlocks')
64+
->with($name)
65+
->willReturn([$link]);
66+
67+
$this->block->setNameInLayout($name);
68+
$this->block->setActive('test/path');
5069
}
5170

5271
public function testRenderLink()
5372
{
5473
$blockHtml = 'test';
5574
$name = 'test_name';
56-
$this->_context->getLayout()->expects(
57-
$this->once()
58-
)->method(
59-
'renderElement'
60-
)->with(
61-
$name
62-
)->will(
63-
$this->returnValue($blockHtml)
64-
);
75+
$this->context->getLayout()
76+
->expects($this->once())
77+
->method('renderElement')
78+
->with($name)
79+
->willReturn($blockHtml);
6580

6681
/** @var \Magento\Framework\View\Element\AbstractBlock $link */
6782
$link = $this->getMockBuilder('Magento\Framework\View\Element\AbstractBlock')
6883
->disableOriginalConstructor()
6984
->getMock();
70-
$link->expects($this->once())->method('getNameInLayout')->will($this->returnValue($name));
85+
$link
86+
->expects($this->once())
87+
->method('getNameInLayout')
88+
->willReturn($name);
7189

72-
$this->assertEquals($blockHtml, $this->_block->renderLink($link));
90+
$this->assertEquals($blockHtml, $this->block->renderLink($link));
7391
}
7492
}

0 commit comments

Comments
 (0)