diff --git a/app/code/Magento/Sales/Controller/AbstractController/View.php b/app/code/Magento/Sales/Controller/AbstractController/View.php index ebc5d087cdd833344c01d3b8a1e508835bf518b3..cd851bc94b9d9001a01552dfc047fa1d09453a9f 100644 --- a/app/code/Magento/Sales/Controller/AbstractController/View.php +++ b/app/code/Magento/Sales/Controller/AbstractController/View.php @@ -52,6 +52,7 @@ abstract class View extends Action\Action $resultPage = $this->resultPageFactory->create(); $resultPage->getLayout()->initMessages(); + /** @var \Magento\Framework\View\Element\Html\Links $navigationBlock */ $navigationBlock = $resultPage->getLayout()->getBlock('customer_account_navigation'); if ($navigationBlock) { $navigationBlock->setActive('sales/order/history'); diff --git a/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php b/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php index 811bea3e4eb33d05aba2d29227fe34e056b345b6..7c971eaf437f13a4b301b4b210affbea20ce35d8 100644 --- a/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php +++ b/lib/internal/Magento/Framework/View/Element/Html/Link/Current.php @@ -110,7 +110,19 @@ class Current extends \Magento\Framework\View\Element\Template $html .= $this->getTitle() ? ' title="' . $this->escapeHtml((string)new \Magento\Framework\Phrase($this->getTitle())) . '"' : ''; - $html .= '>' . $this->escapeHtml((string)new \Magento\Framework\Phrase($this->getLabel())) . '</a></li>'; + $html .= '>'; + + if ($this->getIsHighlighted()) { + $html .= '<strong>'; + } + + $html .= $this->escapeHtml((string)new \Magento\Framework\Phrase($this->getLabel())); + + if ($this->getIsHighlighted()) { + $html .= '</strong>'; + } + + $html .= '</a></li>'; } return $html; diff --git a/lib/internal/Magento/Framework/View/Element/Html/Links.php b/lib/internal/Magento/Framework/View/Element/Html/Links.php index d4dfc7b14942aa160bba7d9dda3dc1482cb5bd42..ffc9c297d8b219df6e1ec2ce5dc1102ac80ebe9c 100644 --- a/lib/internal/Magento/Framework/View/Element/Html/Links.php +++ b/lib/internal/Magento/Framework/View/Element/Html/Links.php @@ -20,6 +20,35 @@ class Links extends \Magento\Framework\View\Element\Template return $this->_layout->getChildBlocks($this->getNameInLayout()); } + /** + * Find link by path + * + * @param string $path + * @return \Magento\Framework\View\Element\Html\Link + */ + protected function getLinkByPath($path) + { + foreach ($this->getLinks() as $link) { + if ($link->getPath() == $path) { + return $link; + } + } + } + + /** + * Set active link + * + * @param string $path + * @return void + */ + public function setActive($path) + { + $link = $this->getLinkByPath($path); + if ($link) { + $link->setIsHighlighted(true); + } + } + /** * Render Block * diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/LinksTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/LinksTest.php index 2b90d037cbb0ba0f18e24dda153a55fc0c55d956..8e4d84db273cbef5aa7c0a06df07a1a99222e512 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/LinksTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/LinksTest.php @@ -5,70 +5,88 @@ */ namespace Magento\Framework\View\Test\Unit\Element\Html; +use Magento\Framework\View\Element\Html\Links; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Framework\View\Element\Template\Context; + class LinksTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager + * @var ObjectManager|\PHPUnit_Framework_MockObject_MockObject */ - protected $_objectManagerHelper; + protected $objectManagerHelper; - /** @var \Magento\Framework\View\Element\Html\Links */ - protected $_block; + /** @var Links|\PHPUnit_Framework_MockObject_MockObject */ + protected $block; - /** @var \Magento\Framework\View\Element\Template\Context */ - protected $_context; + /** @var Context|\PHPUnit_Framework_MockObject_MockObject */ + protected $context; protected function setUp() { - $this->_objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - - /** @var \Magento\Framework\View\Element\Template\Context $context */ - $this->_context = $this->_objectManagerHelper->getObject('Magento\Framework\View\Element\Template\Context'); + $this->objectManagerHelper = new ObjectManager($this); - /** @var \Magento\Framework\View\Element\Html\Links $block */ - $this->_block = $this->_objectManagerHelper->getObject( - 'Magento\Framework\View\Element\Html\Links', - ['context' => $this->_context] - ); + /** @var Context $context */ + $this->context = $this->objectManagerHelper->getObject('Magento\Framework\View\Element\Template\Context'); + $this->block = new Links($this->context); } public function testGetLinks() { $blocks = [0 => 'blocks']; $name = 'test_name'; - $this->_context->getLayout()->expects( - $this->once() - )->method( - 'getChildBlocks' - )->with( - $name - )->will( - $this->returnValue($blocks) - ); - $this->_block->setNameInLayout($name); - $this->assertEquals($blocks, $this->_block->getLinks()); + $this->context->getLayout() + ->expects($this->once()) + ->method('getChildBlocks') + ->with($name) + ->willReturn($blocks); + $this->block->setNameInLayout($name); + $this->assertEquals($blocks, $this->block->getLinks()); + } + + public function testSetActive() + { + $link = $this->getMock('Magento\Framework\View\Element\Html\Link', [], [], '', false); + $link + ->expects($this->at(1)) + ->method('__call') + ->with('setIsHighlighted', [true]); + $link + ->expects($this->at(0)) + ->method('__call') + ->with('getPath', []) + ->willReturn('test/path'); + + $name = 'test_name'; + $this->context->getLayout() + ->expects($this->once()) + ->method('getChildBlocks') + ->with($name) + ->willReturn([$link]); + + $this->block->setNameInLayout($name); + $this->block->setActive('test/path'); } public function testRenderLink() { $blockHtml = 'test'; $name = 'test_name'; - $this->_context->getLayout()->expects( - $this->once() - )->method( - 'renderElement' - )->with( - $name - )->will( - $this->returnValue($blockHtml) - ); + $this->context->getLayout() + ->expects($this->once()) + ->method('renderElement') + ->with($name) + ->willReturn($blockHtml); /** @var \Magento\Framework\View\Element\AbstractBlock $link */ $link = $this->getMockBuilder('Magento\Framework\View\Element\AbstractBlock') ->disableOriginalConstructor() ->getMock(); - $link->expects($this->once())->method('getNameInLayout')->will($this->returnValue($name)); + $link + ->expects($this->once()) + ->method('getNameInLayout') + ->willReturn($name); - $this->assertEquals($blockHtml, $this->_block->renderLink($link)); + $this->assertEquals($blockHtml, $this->block->renderLink($link)); } }