@@ -22,6 +22,11 @@ class RouteParamsResolverTest extends \PHPUnit\Framework\TestCase
2222 */
2323 protected $ queryParamsResolverMock ;
2424
25+ /**
26+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\Store
27+ */
28+ protected $ storeMock ;
29+
2530 /**
2631 * @var \Magento\Store\Url\Plugin\RouteParamsResolver
2732 */
@@ -30,7 +35,19 @@ class RouteParamsResolverTest extends \PHPUnit\Framework\TestCase
3035 protected function setUp ()
3136 {
3237 $ this ->scopeConfigMock = $ this ->createMock (\Magento \Framework \App \Config \ScopeConfigInterface::class);
38+
39+ $ this ->storeMock = $ this ->getMockBuilder (\Magento \Store \Model \Store::class)
40+ ->setMethods (['getCode ' ])
41+ ->disableOriginalConstructor ()
42+ ->getMock ();
43+ $ this ->storeMock ->expects ($ this ->any ())->method ('getCode ' )->willReturn ('custom_store ' );
44+
3345 $ this ->storeManagerMock = $ this ->createMock (\Magento \Store \Model \StoreManagerInterface::class);
46+ $ this ->storeManagerMock
47+ ->expects ($ this ->once ())
48+ ->method ('getStore ' )
49+ ->willReturn ($ this ->storeMock );
50+
3451 $ this ->queryParamsResolverMock = $ this ->createMock (\Magento \Framework \Url \QueryParamsResolverInterface::class);
3552 $ this ->model = new \Magento \Store \Url \Plugin \RouteParamsResolver (
3653 $ this ->scopeConfigMock ,
@@ -42,6 +59,8 @@ protected function setUp()
4259 public function testBeforeSetRouteParamsScopeInParams ()
4360 {
4461 $ storeCode = 'custom_store ' ;
62+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
63+
4564 $ this ->scopeConfigMock
4665 ->expects ($ this ->once ())
4766 ->method ('getValue ' )
@@ -52,7 +71,7 @@ public function testBeforeSetRouteParamsScopeInParams()
5271 )
5372 ->will ($ this ->returnValue (false ));
5473 $ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (false );
55- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
74+
5675 /** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
5776 $ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
5877 ->setMethods (['setScope ' , 'getScope ' ])
@@ -61,7 +80,8 @@ public function testBeforeSetRouteParamsScopeInParams()
6180 $ routeParamsResolverMock ->expects ($ this ->once ())->method ('setScope ' )->with ($ storeCode );
6281 $ routeParamsResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn ($ storeCode );
6382
64- $ this ->queryParamsResolverMock ->expects ($ this ->once ())->method ('setQueryParam ' )->with ('___store ' , $ storeCode );
83+ $ this ->queryParamsResolverMock ->expects ($ this ->never ())->method ('setQueryParam ' );
84+
6585
6686 $ this ->model ->beforeSetRouteParams (
6787 $ routeParamsResolverMock ,
@@ -72,6 +92,8 @@ public function testBeforeSetRouteParamsScopeInParams()
7292 public function testBeforeSetRouteParamsScopeUseStoreInUrl ()
7393 {
7494 $ storeCode = 'custom_store ' ;
95+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
96+
7597 $ this ->scopeConfigMock
7698 ->expects ($ this ->once ())
7799 ->method ('getValue ' )
@@ -81,8 +103,9 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
81103 $ storeCode
82104 )
83105 ->will ($ this ->returnValue (true ));
106+
84107 $ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (false );
85- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
108+
86109 /** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
87110 $ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
88111 ->setMethods (['setScope ' , 'getScope ' ])
@@ -91,7 +114,7 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
91114 $ routeParamsResolverMock ->expects ($ this ->once ())->method ('setScope ' )->with ($ storeCode );
92115 $ routeParamsResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn ($ storeCode );
93116
94- $ this ->queryParamsResolverMock ->expects ($ this ->never ())->method ('setQueryParam ' );
117+ $ this ->queryParamsResolverMock ->expects ($ this ->once ())->method ('setQueryParam ' )-> with ( ' ___store ' , $ storeCode );
95118
96119 $ this ->model ->beforeSetRouteParams (
97120 $ routeParamsResolverMock ,
@@ -102,6 +125,8 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
102125 public function testBeforeSetRouteParamsSingleStore ()
103126 {
104127 $ storeCode = 'custom_store ' ;
128+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
129+
105130 $ this ->scopeConfigMock
106131 ->expects ($ this ->once ())
107132 ->method ('getValue ' )
@@ -112,7 +137,7 @@ public function testBeforeSetRouteParamsSingleStore()
112137 )
113138 ->will ($ this ->returnValue (false ));
114139 $ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (true );
115- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
140+
116141 /** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
117142 $ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
118143 ->setMethods (['setScope ' , 'getScope ' ])
@@ -132,6 +157,8 @@ public function testBeforeSetRouteParamsSingleStore()
132157 public function testBeforeSetRouteParamsNoScopeInParams ()
133158 {
134159 $ storeCode = 'custom_store ' ;
160+ $ data = ['_scope_to_url ' => true ];
161+
135162 $ this ->scopeConfigMock
136163 ->expects ($ this ->once ())
137164 ->method ('getValue ' )
@@ -140,17 +167,10 @@ public function testBeforeSetRouteParamsNoScopeInParams()
140167 \Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
141168 $ storeCode
142169 )
143- ->will ($ this ->returnValue (false ));
170+ ->will ($ this ->returnValue (true ));
171+
144172 $ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (false );
145- /** @var \PHPUnit_Framework_MockObject_MockObject| $routeParamsResolverMock */
146- $ storeMock = $ this ->getMockBuilder (\Magento \Store \Model \Store::class)
147- ->setMethods (['getCode ' ])
148- ->disableOriginalConstructor ()
149- ->getMock ();
150- $ storeMock ->expects ($ this ->any ())->method ('getCode ' )->willReturn ($ storeCode );
151- $ this ->storeManagerMock ->expects ($ this ->any ())->method ('getStore ' )->willReturn ($ storeMock );
152173
153- $ data = ['_scope_to_url ' => true ];
154174 /** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
155175 $ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
156176 ->setMethods (['setScope ' , 'getScope ' ])
0 commit comments