@@ -22,6 +22,11 @@ class RouteParamsResolverTest extends \PHPUnit\Framework\TestCase
22
22
*/
23
23
protected $ queryParamsResolverMock ;
24
24
25
+ /**
26
+ * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\Store
27
+ */
28
+ protected $ storeMock ;
29
+
25
30
/**
26
31
* @var \Magento\Store\Url\Plugin\RouteParamsResolver
27
32
*/
@@ -30,7 +35,19 @@ class RouteParamsResolverTest extends \PHPUnit\Framework\TestCase
30
35
protected function setUp ()
31
36
{
32
37
$ 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
+
33
45
$ this ->storeManagerMock = $ this ->createMock (\Magento \Store \Model \StoreManagerInterface::class);
46
+ $ this ->storeManagerMock
47
+ ->expects ($ this ->once ())
48
+ ->method ('getStore ' )
49
+ ->willReturn ($ this ->storeMock );
50
+
34
51
$ this ->queryParamsResolverMock = $ this ->createMock (\Magento \Framework \Url \QueryParamsResolverInterface::class);
35
52
$ this ->model = new \Magento \Store \Url \Plugin \RouteParamsResolver (
36
53
$ this ->scopeConfigMock ,
@@ -42,6 +59,8 @@ protected function setUp()
42
59
public function testBeforeSetRouteParamsScopeInParams ()
43
60
{
44
61
$ storeCode = 'custom_store ' ;
62
+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
63
+
45
64
$ this ->scopeConfigMock
46
65
->expects ($ this ->once ())
47
66
->method ('getValue ' )
@@ -52,7 +71,7 @@ public function testBeforeSetRouteParamsScopeInParams()
52
71
)
53
72
->will ($ this ->returnValue (false ));
54
73
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (false );
55
- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
74
+
56
75
/** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
57
76
$ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
58
77
->setMethods (['setScope ' , 'getScope ' ])
@@ -61,7 +80,8 @@ public function testBeforeSetRouteParamsScopeInParams()
61
80
$ routeParamsResolverMock ->expects ($ this ->once ())->method ('setScope ' )->with ($ storeCode );
62
81
$ routeParamsResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn ($ storeCode );
63
82
64
- $ this ->queryParamsResolverMock ->expects ($ this ->once ())->method ('setQueryParam ' )->with ('___store ' , $ storeCode );
83
+ $ this ->queryParamsResolverMock ->expects ($ this ->never ())->method ('setQueryParam ' );
84
+
65
85
66
86
$ this ->model ->beforeSetRouteParams (
67
87
$ routeParamsResolverMock ,
@@ -72,6 +92,8 @@ public function testBeforeSetRouteParamsScopeInParams()
72
92
public function testBeforeSetRouteParamsScopeUseStoreInUrl ()
73
93
{
74
94
$ storeCode = 'custom_store ' ;
95
+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
96
+
75
97
$ this ->scopeConfigMock
76
98
->expects ($ this ->once ())
77
99
->method ('getValue ' )
@@ -81,8 +103,9 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
81
103
$ storeCode
82
104
)
83
105
->will ($ this ->returnValue (true ));
106
+
84
107
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (false );
85
- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
108
+
86
109
/** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
87
110
$ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
88
111
->setMethods (['setScope ' , 'getScope ' ])
@@ -91,7 +114,7 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
91
114
$ routeParamsResolverMock ->expects ($ this ->once ())->method ('setScope ' )->with ($ storeCode );
92
115
$ routeParamsResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn ($ storeCode );
93
116
94
- $ this ->queryParamsResolverMock ->expects ($ this ->never ())->method ('setQueryParam ' );
117
+ $ this ->queryParamsResolverMock ->expects ($ this ->once ())->method ('setQueryParam ' )-> with ( ' ___store ' , $ storeCode );
95
118
96
119
$ this ->model ->beforeSetRouteParams (
97
120
$ routeParamsResolverMock ,
@@ -102,6 +125,8 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
102
125
public function testBeforeSetRouteParamsSingleStore ()
103
126
{
104
127
$ storeCode = 'custom_store ' ;
128
+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
129
+
105
130
$ this ->scopeConfigMock
106
131
->expects ($ this ->once ())
107
132
->method ('getValue ' )
@@ -112,7 +137,7 @@ public function testBeforeSetRouteParamsSingleStore()
112
137
)
113
138
->will ($ this ->returnValue (false ));
114
139
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (true );
115
- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
140
+
116
141
/** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
117
142
$ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
118
143
->setMethods (['setScope ' , 'getScope ' ])
@@ -132,6 +157,8 @@ public function testBeforeSetRouteParamsSingleStore()
132
157
public function testBeforeSetRouteParamsNoScopeInParams ()
133
158
{
134
159
$ storeCode = 'custom_store ' ;
160
+ $ data = ['_scope_to_url ' => true ];
161
+
135
162
$ this ->scopeConfigMock
136
163
->expects ($ this ->once ())
137
164
->method ('getValue ' )
@@ -140,17 +167,10 @@ public function testBeforeSetRouteParamsNoScopeInParams()
140
167
\Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
141
168
$ storeCode
142
169
)
143
- ->will ($ this ->returnValue (false ));
170
+ ->will ($ this ->returnValue (true ));
171
+
144
172
$ 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 );
152
173
153
- $ data = ['_scope_to_url ' => true ];
154
174
/** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
155
175
$ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
156
176
->setMethods (['setScope ' , 'getScope ' ])
0 commit comments