@@ -17,11 +17,6 @@ class CurrentTest extends \PHPUnit\Framework\TestCase
17
17
*/
18
18
protected $ _requestMock ;
19
19
20
- /**
21
- * @var \PHPUnit_Framework_MockObject_MockObject
22
- */
23
- protected $ _defaultPathMock ;
24
-
25
20
/**
26
21
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
27
22
*/
@@ -32,7 +27,6 @@ protected function setUp()
32
27
$ this ->_objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
33
28
$ this ->_urlBuilderMock = $ this ->createMock (\Magento \Framework \UrlInterface::class);
34
29
$ this ->_requestMock = $ this ->createMock (\Magento \Framework \App \Request \Http::class);
35
- $ this ->_defaultPathMock = $ this ->createMock (\Magento \Framework \App \DefaultPathInterface::class);
36
30
}
37
31
38
32
public function testGetUrl ()
@@ -60,29 +54,43 @@ public function testIsCurrentIfIsset()
60
54
$ this ->assertTrue ($ link ->isCurrent ());
61
55
}
62
56
57
+ /**
58
+ * Test if the current url is the same as link path
59
+ *
60
+ * @return void
61
+ */
63
62
public function testIsCurrent ()
64
63
{
65
- $ path = 'test/path ' ;
66
- $ url = 'http://example.com/a/b ' ;
67
-
68
- $ this ->_requestMock ->expects ($ this ->once ())->method ('getModuleName ' )->will ($ this ->returnValue ('a ' ));
69
- $ this ->_requestMock ->expects ($ this ->once ())->method ('getControllerName ' )->will ($ this ->returnValue ('b ' ));
70
- $ this ->_requestMock ->expects ($ this ->once ())->method ('getActionName ' )->will ($ this ->returnValue ('d ' ));
71
- $ this ->_defaultPathMock ->expects ($ this ->atLeastOnce ())->method ('getPart ' )->will ($ this ->returnValue ('d ' ));
64
+ $ path = 'test/index ' ;
65
+ $ url = 'http://example.com/test/index ' ;
66
+
67
+ $ this ->_requestMock ->expects ($ this ->once ())
68
+ ->method ('getModuleName ' )
69
+ ->will ($ this ->returnValue ('test ' ));
70
+ $ this ->_requestMock ->expects ($ this ->once ())
71
+ ->method ('getControllerName ' )
72
+ ->will ($ this ->returnValue ('index ' ));
73
+ $ this ->_requestMock ->expects ($ this ->once ())
74
+ ->method ('getActionName ' )
75
+ ->will ($ this ->returnValue ('index ' ));
76
+ $ this ->_urlBuilderMock ->expects ($ this ->at (0 ))
77
+ ->method ('getUrl ' )
78
+ ->with ($ path )
79
+ ->will ($ this ->returnValue ($ url ));
80
+ $ this ->_urlBuilderMock ->expects ($ this ->at (1 ))
81
+ ->method ('getUrl ' )
82
+ ->with ('test/index ' )
83
+ ->will ($ this ->returnValue ($ url ));
72
84
73
- $ this ->_urlBuilderMock ->expects ($ this ->at (0 ))->method ('getUrl ' )->with ($ path )->will ($ this ->returnValue ($ url ));
74
- $ this ->_urlBuilderMock ->expects ($ this ->at (1 ))->method ('getUrl ' )->with ('a/b ' )->will ($ this ->returnValue ($ url ));
75
-
76
- $ this ->_requestMock ->expects ($ this ->once ())->method ('getControllerName ' )->will ($ this ->returnValue ('b ' ));
77
85
/** @var \Magento\Framework\View\Element\Html\Link\Current $link */
78
86
$ link = $ this ->_objectManager ->getObject (
79
87
\Magento \Framework \View \Element \Html \Link \Current::class,
80
88
[
81
89
'urlBuilder ' => $ this ->_urlBuilderMock ,
82
- 'request ' => $ this ->_requestMock ,
83
- 'defaultPath ' => $ this ->_defaultPathMock
90
+ 'request ' => $ this ->_requestMock
84
91
]
85
92
);
93
+
86
94
$ link ->setPath ($ path );
87
95
$ this ->assertTrue ($ link ->isCurrent ());
88
96
}
0 commit comments