@@ -17,11 +17,6 @@ class CurrentTest extends \PHPUnit\Framework\TestCase
1717 */
1818 protected $ _requestMock ;
1919
20- /**
21- * @var \PHPUnit_Framework_MockObject_MockObject
22- */
23- protected $ _defaultPathMock ;
24-
2520 /**
2621 * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
2722 */
@@ -32,7 +27,6 @@ protected function setUp()
3227 $ this ->_objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
3328 $ this ->_urlBuilderMock = $ this ->createMock (\Magento \Framework \UrlInterface::class);
3429 $ this ->_requestMock = $ this ->createMock (\Magento \Framework \App \Request \Http::class);
35- $ this ->_defaultPathMock = $ this ->createMock (\Magento \Framework \App \DefaultPathInterface::class);
3630 }
3731
3832 public function testGetUrl ()
@@ -60,29 +54,46 @@ public function testIsCurrentIfIsset()
6054 $ this ->assertTrue ($ link ->isCurrent ());
6155 }
6256
57+ /**
58+ * Test if the current url is the same as link path
59+ *
60+ * @return void
61+ */
6362 public function testIsCurrent ()
6463 {
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 ('getPathInfo ' )
69+ ->will ($ this ->returnValue ('/test/index/ ' ));
70+ $ this ->_requestMock ->expects ($ this ->once ())
71+ ->method ('getModuleName ' )
72+ ->will ($ this ->returnValue ('test ' ));
73+ $ this ->_requestMock ->expects ($ this ->once ())
74+ ->method ('getControllerName ' )
75+ ->will ($ this ->returnValue ('index ' ));
76+ $ this ->_requestMock ->expects ($ this ->once ())
77+ ->method ('getActionName ' )
78+ ->will ($ this ->returnValue ('index ' ));
79+ $ this ->_urlBuilderMock ->expects ($ this ->at (0 ))
80+ ->method ('getUrl ' )
81+ ->with ($ path )
82+ ->will ($ this ->returnValue ($ url ));
83+ $ this ->_urlBuilderMock ->expects ($ this ->at (1 ))
84+ ->method ('getUrl ' )
85+ ->with ('test/index ' )
86+ ->will ($ this ->returnValue ($ url ));
7287
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 ' ));
7788 /** @var \Magento\Framework\View\Element\Html\Link\Current $link */
7889 $ link = $ this ->_objectManager ->getObject (
7990 \Magento \Framework \View \Element \Html \Link \Current::class,
8091 [
8192 'urlBuilder ' => $ this ->_urlBuilderMock ,
82- 'request ' => $ this ->_requestMock ,
83- 'defaultPath ' => $ this ->_defaultPathMock
93+ 'request ' => $ this ->_requestMock
8494 ]
8595 );
96+
8697 $ link ->setPath ($ path );
8798 $ this ->assertTrue ($ link ->isCurrent ());
8899 }
0 commit comments