@@ -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,7 @@ 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 ' );
65
84
66
85
$ this ->model ->beforeSetRouteParams (
67
86
$ routeParamsResolverMock ,
@@ -72,6 +91,8 @@ public function testBeforeSetRouteParamsScopeInParams()
72
91
public function testBeforeSetRouteParamsScopeUseStoreInUrl ()
73
92
{
74
93
$ storeCode = 'custom_store ' ;
94
+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
95
+
75
96
$ this ->scopeConfigMock
76
97
->expects ($ this ->once ())
77
98
->method ('getValue ' )
@@ -81,8 +102,9 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
81
102
$ storeCode
82
103
)
83
104
->will ($ this ->returnValue (true ));
105
+
84
106
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (false );
85
- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
107
+
86
108
/** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
87
109
$ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
88
110
->setMethods (['setScope ' , 'getScope ' ])
@@ -91,7 +113,7 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
91
113
$ routeParamsResolverMock ->expects ($ this ->once ())->method ('setScope ' )->with ($ storeCode );
92
114
$ routeParamsResolverMock ->expects ($ this ->once ())->method ('getScope ' )->willReturn ($ storeCode );
93
115
94
- $ this ->queryParamsResolverMock ->expects ($ this ->never ())->method ('setQueryParam ' );
116
+ $ this ->queryParamsResolverMock ->expects ($ this ->once ())->method ('setQueryParam ' )-> with ( ' ___store ' , $ storeCode );
95
117
96
118
$ this ->model ->beforeSetRouteParams (
97
119
$ routeParamsResolverMock ,
@@ -102,6 +124,8 @@ public function testBeforeSetRouteParamsScopeUseStoreInUrl()
102
124
public function testBeforeSetRouteParamsSingleStore ()
103
125
{
104
126
$ storeCode = 'custom_store ' ;
127
+ $ data = ['_scope ' => $ storeCode , '_scope_to_url ' => true ];
128
+
105
129
$ this ->scopeConfigMock
106
130
->expects ($ this ->once ())
107
131
->method ('getValue ' )
@@ -112,7 +136,7 @@ public function testBeforeSetRouteParamsSingleStore()
112
136
)
113
137
->will ($ this ->returnValue (false ));
114
138
$ this ->storeManagerMock ->expects ($ this ->any ())->method ('hasSingleStore ' )->willReturn (true );
115
- $ data = [ ' _scope ' => $ storeCode , ' _scope_to_url ' => true ];
139
+
116
140
/** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
117
141
$ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
118
142
->setMethods (['setScope ' , 'getScope ' ])
@@ -132,6 +156,8 @@ public function testBeforeSetRouteParamsSingleStore()
132
156
public function testBeforeSetRouteParamsNoScopeInParams ()
133
157
{
134
158
$ storeCode = 'custom_store ' ;
159
+ $ data = ['_scope_to_url ' => true ];
160
+
135
161
$ this ->scopeConfigMock
136
162
->expects ($ this ->once ())
137
163
->method ('getValue ' )
@@ -140,17 +166,10 @@ public function testBeforeSetRouteParamsNoScopeInParams()
140
166
\Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
141
167
$ storeCode
142
168
)
143
- ->will ($ this ->returnValue (false ));
169
+ ->will ($ this ->returnValue (true ));
170
+
144
171
$ 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
172
153
- $ data = ['_scope_to_url ' => true ];
154
173
/** @var \PHPUnit_Framework_MockObject_MockObject $routeParamsResolverMock */
155
174
$ routeParamsResolverMock = $ this ->getMockBuilder (\Magento \Framework \Url \RouteParamsResolver::class)
156
175
->setMethods (['setScope ' , 'getScope ' ])
0 commit comments