|
5 | 5 | */
|
6 | 6 | namespace Magento\Framework\View\Test\Unit\Element\Html;
|
7 | 7 |
|
| 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 | + |
8 | 12 | class LinksTest extends \PHPUnit_Framework_TestCase
|
9 | 13 | {
|
10 | 14 | /**
|
11 |
| - * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager |
| 15 | + * @var ObjectManager|\PHPUnit_Framework_MockObject_MockObject |
12 | 16 | */
|
13 |
| - protected $_objectManagerHelper; |
| 17 | + protected $objectManagerHelper; |
14 | 18 |
|
15 |
| - /** @var \Magento\Framework\View\Element\Html\Links */ |
16 |
| - protected $_block; |
| 19 | + /** @var Links|\PHPUnit_Framework_MockObject_MockObject */ |
| 20 | + protected $block; |
17 | 21 |
|
18 |
| - /** @var \Magento\Framework\View\Element\Template\Context */ |
19 |
| - protected $_context; |
| 22 | + /** @var Context|\PHPUnit_Framework_MockObject_MockObject */ |
| 23 | + protected $context; |
20 | 24 |
|
21 | 25 | protected function setUp()
|
22 | 26 | {
|
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); |
27 | 28 |
|
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); |
33 | 32 | }
|
34 | 33 |
|
35 | 34 | public function testGetLinks()
|
36 | 35 | {
|
37 | 36 | $blocks = [0 => 'blocks'];
|
38 | 37 | $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'); |
50 | 69 | }
|
51 | 70 |
|
52 | 71 | public function testRenderLink()
|
53 | 72 | {
|
54 | 73 | $blockHtml = 'test';
|
55 | 74 | $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); |
65 | 80 |
|
66 | 81 | /** @var \Magento\Framework\View\Element\AbstractBlock $link */
|
67 | 82 | $link = $this->getMockBuilder('Magento\Framework\View\Element\AbstractBlock')
|
68 | 83 | ->disableOriginalConstructor()
|
69 | 84 | ->getMock();
|
70 |
| - $link->expects($this->once())->method('getNameInLayout')->will($this->returnValue($name)); |
| 85 | + $link |
| 86 | + ->expects($this->once()) |
| 87 | + ->method('getNameInLayout') |
| 88 | + ->willReturn($name); |
71 | 89 |
|
72 |
| - $this->assertEquals($blockHtml, $this->_block->renderLink($link)); |
| 90 | + $this->assertEquals($blockHtml, $this->block->renderLink($link)); |
73 | 91 | }
|
74 | 92 | }
|
0 commit comments