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 ());
50
45
}
51
46
52
47
public function testSetActive ()
@@ -63,37 +58,35 @@ public function testSetActive()
63
58
->willReturn ('test/path ' );
64
59
65
60
$ name = 'test_name ' ;
66
- $ this ->_context ->getLayout ()
61
+ $ this ->context ->getLayout ()
67
62
->expects ($ this ->once ())
68
63
->method ('getChildBlocks ' )
69
64
->with ($ name )
70
65
->willReturn ([$ link ]);
71
66
72
- $ this ->_block ->setNameInLayout ($ name );
73
-
74
- $ this ->_block ->setActive ('test/path ' );
67
+ $ this ->block ->setNameInLayout ($ name );
68
+ $ this ->block ->setActive ('test/path ' );
75
69
}
76
70
77
71
public function testRenderLink ()
78
72
{
79
73
$ blockHtml = 'test ' ;
80
74
$ name = 'test_name ' ;
81
- $ this ->_context ->getLayout ()->expects (
82
- $ this ->once ()
83
- )->method (
84
- 'renderElement '
85
- )->with (
86
- $ name
87
- )->will (
88
- $ this ->returnValue ($ blockHtml )
89
- );
75
+ $ this ->context ->getLayout ()
76
+ ->expects ($ this ->once ())
77
+ ->method ('renderElement ' )
78
+ ->with ($ name )
79
+ ->willReturn ($ blockHtml );
90
80
91
81
/** @var \Magento\Framework\View\Element\AbstractBlock $link */
92
82
$ link = $ this ->getMockBuilder ('Magento\Framework\View\Element\AbstractBlock ' )
93
83
->disableOriginalConstructor ()
94
84
->getMock ();
95
- $ link ->expects ($ this ->once ())->method ('getNameInLayout ' )->will ($ this ->returnValue ($ name ));
85
+ $ link
86
+ ->expects ($ this ->once ())
87
+ ->method ('getNameInLayout ' )
88
+ ->willReturn ($ name );
96
89
97
- $ this ->assertEquals ($ blockHtml , $ this ->_block ->renderLink ($ link ));
90
+ $ this ->assertEquals ($ blockHtml , $ this ->block ->renderLink ($ link ));
98
91
}
99
92
}
0 commit comments