Skip to content

Commit 2f27a36

Browse files
author
Mariana Lashch
committed
Merge branch 'MAGETWO-92757' into mpi-PR-1607
2 parents cc4b174 + 68a7eef commit 2f27a36

File tree

2 files changed

+47
-51
lines changed

2 files changed

+47
-51
lines changed

app/code/Magento/Store/App/Action/Plugin/Context.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ private function processInvalidStoreRequested(
131131
*/
132132
private function updateContext(StoreInterface $store)
133133
{
134+
/** @var StoreInterface $defaultStore */
135+
$defaultStore = $this->storeManager->getWebsite()->getDefaultStore();
134136
$this->httpContext->setValue(
135137
StoreManagerInterface::CONTEXT_STORE,
136138
$store->getCode(),
137-
$this->storeManager->getDefaultStoreView()->getCode()
139+
$defaultStore->getCode()
138140
);
139141

140-
/** @var StoreInterface $defaultStore */
141-
$defaultStore = $this->storeManager->getWebsite()->getDefaultStore();
142142
$this->httpContext->setValue(
143143
HttpContext::CONTEXT_CURRENCY,
144144
$this->session->getCurrencyCode()

app/code/Magento/Store/Test/Unit/App/Action/Plugin/ContextTest.php

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ContextTest extends \PHPUnit\Framework\TestCase
5252
/**
5353
* @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
5454
*/
55-
protected $storeMock;
55+
protected $store;
5656

5757
/**
5858
* @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
@@ -62,7 +62,7 @@ class ContextTest extends \PHPUnit\Framework\TestCase
6262
/**
6363
* @var \Magento\Store\Model\Website|\PHPUnit_Framework_MockObject_MockObject
6464
*/
65-
protected $websiteMock;
65+
protected $website;
6666

6767
/**
6868
* @var AbstractAction|\PHPUnit_Framework_MockObject_MockObject
@@ -87,9 +87,9 @@ protected function setUp()
8787
->willReturn(null);
8888
$this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
8989
$this->storeCookieManager = $this->createMock(\Magento\Store\Api\StoreCookieManagerInterface::class);
90-
$this->storeMock = $this->createMock(\Magento\Store\Model\Store::class);
90+
$this->store = $this->createMock(\Magento\Store\Model\Store::class);
9191
$this->currentStoreMock = $this->createMock(\Magento\Store\Model\Store::class);
92-
$this->websiteMock = $this->createPartialMock(
92+
$this->website = $this->createPartialMock(
9393
\Magento\Store\Model\Website::class,
9494
['getDefaultStore', '__wakeup']
9595
);
@@ -108,8 +108,6 @@ protected function setUp()
108108
]
109109
);
110110

111-
$this->storeManager->method('getDefaultStoreView')
112-
->willReturn($this->storeMock);
113111
$this->storeCookieManager->expects($this->once())
114112
->method('getStoreCodeFromCookie')
115113
->will($this->returnValue('storeCookie'));
@@ -122,16 +120,16 @@ public function testBeforeDispatchCurrencyFromSession()
122120
{
123121
$this->storeManager->expects($this->once())
124122
->method('getWebsite')
125-
->will($this->returnValue($this->websiteMock));
126-
$this->websiteMock->expects($this->once())
123+
->will($this->returnValue($this->website));
124+
$this->website->expects($this->once())
127125
->method('getDefaultStore')
128-
->will($this->returnValue($this->storeMock));
126+
->will($this->returnValue($this->store));
129127

130-
$this->storeMock->expects($this->once())
128+
$this->store->expects($this->once())
131129
->method('getDefaultCurrencyCode')
132130
->will($this->returnValue(self::CURRENCY_DEFAULT));
133131

134-
$this->storeMock->expects($this->once())
132+
$this->store->expects($this->once())
135133
->method('getCode')
136134
->willReturn('default');
137135
$this->currentStoreMock->expects($this->once())
@@ -173,41 +171,39 @@ public function testBeforeDispatchCurrencyFromSession()
173171
);
174172
}
175173

176-
public function testDispatchCurrentStoreCurrency()
174+
public function testDispatchCurrentStoreAndCurrency()
177175
{
178-
$this->storeManager->expects($this->once())
179-
->method('getWebsite')
180-
->will($this->returnValue($this->websiteMock));
181-
$this->websiteMock->expects($this->once())
182-
->method('getDefaultStore')
183-
->will($this->returnValue($this->storeMock));
176+
$defaultStoreCode = 'default_store';
177+
$customStoreCode = 'custom_store';
184178

185-
$this->storeMock->expects($this->once())
186-
->method('getDefaultCurrencyCode')
187-
->will($this->returnValue(self::CURRENCY_DEFAULT));
179+
$this->storeManager->method('getWebsite')
180+
->willReturn($this->website);
181+
$this->website->method('getDefaultStore')
182+
->willReturn($this->store);
188183

189-
$this->storeMock->expects($this->once())
190-
->method('getCode')
191-
->willReturn('default');
192-
$this->currentStoreMock->expects($this->once())
193-
->method('getCode')
194-
->willReturn('custom_store');
184+
$this->store->method('getDefaultCurrencyCode')
185+
->willReturn(self::CURRENCY_DEFAULT);
186+
187+
$this->store->method('getCode')
188+
->willReturn($defaultStoreCode);
189+
$this->currentStoreMock->method('getCode')
190+
->willReturn($customStoreCode);
195191

196192
$this->requestMock->expects($this->once())
197193
->method('getParam')
198194
->with($this->equalTo('___store'))
199-
->will($this->returnValue('default'));
195+
->willReturn($defaultStoreCode);
200196

201197
$this->storeManager->method('getStore')
202-
->with('default')
198+
->with($defaultStoreCode)
203199
->willReturn($this->currentStoreMock);
204200

205201
$this->httpContextMock->expects($this->at(1))
206202
->method('setValue')
207203
->with(
208204
StoreManagerInterface::CONTEXT_STORE,
209-
'custom_store',
210-
'default'
205+
$customStoreCode,
206+
$defaultStoreCode
211207
);
212208
// Make sure that current currency is taken from current store
213209
//if no value is provided in session.
@@ -229,16 +225,16 @@ public function testDispatchStoreParameterIsArray()
229225
{
230226
$this->storeManager->expects($this->once())
231227
->method('getWebsite')
232-
->will($this->returnValue($this->websiteMock));
233-
$this->websiteMock->expects($this->once())
228+
->will($this->returnValue($this->website));
229+
$this->website->expects($this->once())
234230
->method('getDefaultStore')
235-
->will($this->returnValue($this->storeMock));
231+
->will($this->returnValue($this->store));
236232

237-
$this->storeMock->expects($this->once())
233+
$this->store->expects($this->once())
238234
->method('getDefaultCurrencyCode')
239235
->will($this->returnValue(self::CURRENCY_DEFAULT));
240236

241-
$this->storeMock->expects($this->once())
237+
$this->store->expects($this->once())
242238
->method('getCode')
243239
->willReturn('default');
244240
$this->currentStoreMock->expects($this->once())
@@ -291,15 +287,15 @@ public function testDispatchStoreParameterIsInvalidArray()
291287
{
292288
$this->storeManager->expects($this->once())
293289
->method('getWebsite')
294-
->will($this->returnValue($this->websiteMock));
295-
$this->websiteMock->expects($this->once())
290+
->will($this->returnValue($this->website));
291+
$this->website->expects($this->once())
296292
->method('getDefaultStore')
297-
->will($this->returnValue($this->storeMock));
298-
$this->storeMock->expects($this->exactly(2))
293+
->will($this->returnValue($this->store));
294+
$this->store->expects($this->exactly(2))
299295
->method('getDefaultCurrencyCode')
300296
->will($this->returnValue(self::CURRENCY_DEFAULT));
301297

302-
$this->storeMock->expects($this->exactly(2))
298+
$this->store->expects($this->exactly(2))
303299
->method('getCode')
304300
->willReturn('default');
305301
$this->currentStoreMock->expects($this->never())
@@ -319,7 +315,7 @@ public function testDispatchStoreParameterIsInvalidArray()
319315
$this->storeManager->expects($this->once())
320316
->method('getStore')
321317
->with()
322-
->willReturn($this->storeMock);
318+
->willReturn($this->store);
323319
$this->plugin->beforeDispatch(
324320
$this->subjectMock,
325321
$this->requestMock
@@ -343,18 +339,18 @@ public function testDispatchNonExistingStore()
343339
$this->storeManager->expects($this->at(1))
344340
->method('getStore')
345341
->with()
346-
->willReturn($this->storeMock);
342+
->willReturn($this->store);
347343
$this->storeManager->expects($this->once())
348344
->method('getWebsite')
349-
->will($this->returnValue($this->websiteMock));
350-
$this->websiteMock->expects($this->once())
345+
->will($this->returnValue($this->website));
346+
$this->website->expects($this->once())
351347
->method('getDefaultStore')
352-
->will($this->returnValue($this->storeMock));
353-
$this->storeMock->expects($this->exactly(2))
348+
->will($this->returnValue($this->store));
349+
$this->store->expects($this->exactly(2))
354350
->method('getDefaultCurrencyCode')
355351
->will($this->returnValue(self::CURRENCY_DEFAULT));
356352

357-
$this->storeMock->expects($this->exactly(2))
353+
$this->store->expects($this->exactly(2))
358354
->method('getCode')
359355
->willReturn('default');
360356
$this->currentStoreMock->expects($this->never())

0 commit comments

Comments
 (0)