@@ -159,34 +159,41 @@ public function setUp()
159
159
->will ($ this ->returnValue ($ this ->websiteMock ));
160
160
$ this ->storeManager ->method ('getDefaultStoreView ' )
161
161
->willReturn ($ this ->storeMock );
162
- $ this ->storeManager ->method ('getStore ' )
163
- ->willReturn ($ this ->currentStoreMock );
162
+
164
163
$ this ->websiteMock ->expects ($ this ->once ())
165
164
->method ('getDefaultStore ' )
166
165
->will ($ this ->returnValue ($ this ->storeMock ));
166
+
167
+ $ this ->storeCookieManager ->expects ($ this ->once ())
168
+ ->method ('getStoreCodeFromCookie ' )
169
+ ->will ($ this ->returnValue ('storeCookie ' ));
170
+ $ this ->currentStoreMock ->expects ($ this ->any ())
171
+ ->method ('getDefaultCurrencyCode ' )
172
+ ->will ($ this ->returnValue (self ::CURRENCY_CURRENT_STORE ));
173
+ }
174
+
175
+ public function testAroundDispatchCurrencyFromSession ()
176
+ {
167
177
$ this ->storeMock ->expects ($ this ->once ())
168
178
->method ('getDefaultCurrencyCode ' )
169
179
->will ($ this ->returnValue (self ::CURRENCY_DEFAULT ));
180
+
170
181
$ this ->storeMock ->expects ($ this ->once ())
171
182
->method ('getCode ' )
172
183
->willReturn ('default ' );
173
184
$ this ->currentStoreMock ->expects ($ this ->once ())
174
185
->method ('getCode ' )
175
186
->willReturn ('custom_store ' );
176
- $ this ->storeCookieManager ->expects ($ this ->once ())
177
- ->method ('getStoreCodeFromCookie ' )
178
- ->will ($ this ->returnValue ('storeCookie ' ));
187
+
179
188
$ this ->httpRequestMock ->expects ($ this ->once ())
180
189
->method ('getParam ' )
181
190
->with ($ this ->equalTo ('___store ' ))
182
191
->will ($ this ->returnValue ('default ' ));
183
- $ this ->currentStoreMock ->expects ($ this ->any ())
184
- ->method ('getDefaultCurrencyCode ' )
185
- ->will ($ this ->returnValue (self ::CURRENCY_CURRENT_STORE ));
186
- }
187
192
188
- public function testAroundDispatchCurrencyFromSession ()
189
- {
193
+ $ this ->storeManager ->method ('getStore ' )
194
+ ->with ('default ' )
195
+ ->willReturn ($ this ->currentStoreMock );
196
+
190
197
$ this ->sessionMock ->expects ($ this ->any ())
191
198
->method ('getCurrencyCode ' )
192
199
->will ($ this ->returnValue (self ::CURRENCY_SESSION ));
@@ -207,6 +214,26 @@ public function testAroundDispatchCurrencyFromSession()
207
214
208
215
public function testDispatchCurrentStoreCurrency ()
209
216
{
217
+ $ this ->storeMock ->expects ($ this ->once ())
218
+ ->method ('getDefaultCurrencyCode ' )
219
+ ->will ($ this ->returnValue (self ::CURRENCY_DEFAULT ));
220
+
221
+ $ this ->storeMock ->expects ($ this ->once ())
222
+ ->method ('getCode ' )
223
+ ->willReturn ('default ' );
224
+ $ this ->currentStoreMock ->expects ($ this ->once ())
225
+ ->method ('getCode ' )
226
+ ->willReturn ('custom_store ' );
227
+
228
+ $ this ->httpRequestMock ->expects ($ this ->once ())
229
+ ->method ('getParam ' )
230
+ ->with ($ this ->equalTo ('___store ' ))
231
+ ->will ($ this ->returnValue ('default ' ));
232
+
233
+ $ this ->storeManager ->method ('getStore ' )
234
+ ->with ('default ' )
235
+ ->willReturn ($ this ->currentStoreMock );
236
+
210
237
$ this ->httpContextMock ->expects ($ this ->at (0 ))
211
238
->method ('setValue ' )
212
239
->with (StoreManagerInterface::CONTEXT_STORE , 'custom_store ' , 'default ' );
@@ -220,4 +247,78 @@ public function testDispatchCurrentStoreCurrency()
220
247
$ this ->plugin ->aroundDispatch ($ this ->subjectMock , $ this ->closureMock , $ this ->requestMock )
221
248
);
222
249
}
250
+
251
+ public function testDispatchStoreParameterIsArray ()
252
+ {
253
+ $ this ->storeMock ->expects ($ this ->once ())
254
+ ->method ('getDefaultCurrencyCode ' )
255
+ ->will ($ this ->returnValue (self ::CURRENCY_DEFAULT ));
256
+
257
+ $ this ->storeMock ->expects ($ this ->once ())
258
+ ->method ('getCode ' )
259
+ ->willReturn ('default ' );
260
+ $ this ->currentStoreMock ->expects ($ this ->once ())
261
+ ->method ('getCode ' )
262
+ ->willReturn ('custom_store ' );
263
+
264
+ $ store = [
265
+ '_data ' => [
266
+ 'code ' => 500 ,
267
+ ]
268
+ ];
269
+
270
+ $ this ->httpRequestMock ->expects ($ this ->once ())
271
+ ->method ('getParam ' )
272
+ ->with ($ this ->equalTo ('___store ' ))
273
+ ->will ($ this ->returnValue ($ store ));
274
+
275
+ $ this ->storeManager ->expects ($ this ->once ())
276
+ ->method ('getStore ' )
277
+ ->with ('500 ' )
278
+ ->willReturn ($ this ->currentStoreMock );
279
+
280
+ $ this ->httpContextMock ->expects ($ this ->at (0 ))
281
+ ->method ('setValue ' )
282
+ ->with (StoreManagerInterface::CONTEXT_STORE , 'custom_store ' , 'default ' );
283
+ /** Make sure that current currency is taken from current store if no value is provided in session */
284
+ $ this ->httpContextMock ->expects ($ this ->at (1 ))
285
+ ->method ('setValue ' )
286
+ ->with (Context::CONTEXT_CURRENCY , self ::CURRENCY_CURRENT_STORE , self ::CURRENCY_DEFAULT );
287
+
288
+ $ result = $ this ->plugin ->aroundDispatch ($ this ->subjectMock , $ this ->closureMock , $ this ->requestMock );
289
+ $ this ->assertEquals (
290
+ 'ExpectedValue ' ,
291
+ $ result
292
+ );
293
+ }
294
+
295
+ /**
296
+ * @expectedException \InvalidArgumentException
297
+ * @expectedExceptionMessage Invalid store parameter.
298
+ */
299
+ public function testDispatchStoreParameterIsInvalidArray ()
300
+ {
301
+ $ this ->storeMock ->expects ($ this ->never ())
302
+ ->method ('getDefaultCurrencyCode ' )
303
+ ->will ($ this ->returnValue (self ::CURRENCY_DEFAULT ));
304
+
305
+ $ this ->storeMock ->expects ($ this ->never ())
306
+ ->method ('getCode ' )
307
+ ->willReturn ('default ' );
308
+ $ this ->currentStoreMock ->expects ($ this ->never ())
309
+ ->method ('getCode ' )
310
+ ->willReturn ('custom_store ' );
311
+
312
+ $ store = [
313
+ 'some ' => [
314
+ 'code ' => 500 ,
315
+ ]
316
+ ];
317
+
318
+ $ this ->httpRequestMock ->expects ($ this ->once ())
319
+ ->method ('getParam ' )
320
+ ->with ($ this ->equalTo ('___store ' ))
321
+ ->will ($ this ->returnValue ($ store ));
322
+ $ this ->plugin ->aroundDispatch ($ this ->subjectMock , $ this ->closureMock , $ this ->requestMock );
323
+ }
223
324
}
0 commit comments