@@ -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,7 @@ 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 ' );
6584
6685 $ this ->model ->beforeSetRouteParams (
6786 $ routeParamsResolverMock ,
@@ -72,6 +91,8 @@ public function testBeforeSetRouteParamsScopeInParams()
7291 public function testBeforeSetRouteParamsScopeUseStoreInUrl ()
7392 {
7493 $ storeCode = 'custom_store ' ;
94+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
95+
7596 $ this ->scopeConfigMock
7697 ->expects ($ this ->once ())
7798 ->method ('getValue ' )
@@ -81,8 +102,9 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
81102 $ storeCode
82103 )
83104 ->will ($ this ->returnValue (true ));
105+
84106 $ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (false );
85- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
107+
86108 /** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
87109 $ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
88110 ->setMethods (['setScope ' , 'getScope ' ])
@@ -91,7 +113,7 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
91113 $ routeParamsResolverMock ->expects ($ this ->once ())->method ('setScope ' )->with ($ storeCode );
92114 $ routeParamsResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn ($ storeCode );
93115
94- $ this ->queryParamsResolverMock ->expects ($ this ->never ())->method ('setQueryParam ' );
116+ $ this ->queryParamsResolverMock ->expects ($ this ->once ())->method ('setQueryParam ' )-> with ( ' ___store ' , $ storeCode );
95117
96118 $ this ->model ->beforeSetRouteParams (
97119 $ routeParamsResolverMock ,
@@ -102,6 +124,8 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
102124 public function testBeforeSetRouteParamsSingleStore ()
103125 {
104126 $ storeCode = 'custom_store ' ;
127+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
128+
105129 $ this ->scopeConfigMock
106130 ->expects ($ this ->once ())
107131 ->method ('getValue ' )
@@ -112,7 +136,7 @@ public function testBeforeSetRouteParamsSingleStore()
112136 )
113137 ->will ($ this ->returnValue (false ));
114138 $ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (true );
115- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
139+
116140 /** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
117141 $ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
118142 ->setMethods (['setScope ' , 'getScope ' ])
@@ -132,6 +156,8 @@ public function testBeforeSetRouteParamsSingleStore()
132156 public function testBeforeSetRouteParamsNoScopeInParams ()
133157 {
134158 $ storeCode = 'custom_store ' ;
159+ $ data = ['_scope_to_url ' => true ];
160+
135161 $ this ->scopeConfigMock
136162 ->expects ($ this ->once ())
137163 ->method ('getValue ' )
@@ -140,17 +166,10 @@ public function testBeforeSetRouteParamsNoScopeInParams()
140166 \Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
141167 $ storeCode
142168 )
143- ->will ($ this ->returnValue (false ));
169+ ->will ($ this ->returnValue (true ));
170+
144171 $ 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 );
152172
153- $ data = ['_scope_to_url ' => true ];
154173 /** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
155174 $ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
156175 ->setMethods (['setScope ' , 'getScope ' ])
0 commit comments