Skip to content

Commit cd53e8c

Browse files
committed
MAGETWO-69107: [Backport] - [Magento Cloud] Switching stores not working properly - for 2.1
- Fix unit tests
1 parent 38feef1 commit cd53e8c

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

app/code/Magento/Store/Test/Unit/Block/SwitcherTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ class SwitcherTest extends \PHPUnit_Framework_TestCase
2828
protected function setUp()
2929
{
3030
$this->storeManager = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')->getMock();
31-
$this->urlBuilder = $this->getMock('Magento\Framework\UrlInterface');
32-
$this->context = $this->getMock('Magento\Framework\View\Element\Template\Context', [], [], '', false);
31+
$this->urlBuilder = $this->getMockBuilder('Magento\Framework\UrlInterface')->getMock();
32+
$this->context = $this->getMockBuilder('Magento\Framework\View\Element\Template\Context')
33+
->disableOriginalConstructor()
34+
->getMock();
3335
$this->context->expects($this->any())->method('getStoreManager')->will($this->returnValue($this->storeManager));
3436
$this->context->expects($this->any())->method('getUrlBuilder')->will($this->returnValue($this->urlBuilder));
3537
$this->corePostDataHelper = $this->getMock('Magento\Framework\Data\Helper\PostHelper', [], [], '', false);
@@ -51,7 +53,7 @@ public function testGetTargetStorePostData()
5153
->method('getCode')
5254
->willReturn('new-store');
5355
$storeSwitchUrl = 'http://domain.com/stores/store/switch';
54-
$store->expects($this->atLeastOnce())
56+
$store->expects($this->once())
5557
->method('getCurrentUrl')
5658
->with(false)
5759
->willReturn($storeSwitchUrl);

app/code/Magento/Store/Test/Unit/Model/Plugin/StoreCookieTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function testBeforeDispatchNoSuchEntity()
116116
$this->storeManagerMock->expects($this->once())
117117
->method('getDefaultStoreView')
118118
->willReturn($this->storeMock);
119-
$this->storeCookieManagerMock->expects($this->atLeastOnce())
119+
$this->storeCookieManagerMock->expects($this->exactly(2))
120120
->method('getStoreCodeFromCookie')
121121
->willReturn($storeCode);
122122
$this->storeRepositoryMock->expects($this->once())
@@ -125,7 +125,7 @@ public function testBeforeDispatchNoSuchEntity()
125125
$this->storeCookieManagerMock->expects($this->once())
126126
->method('deleteStoreCookie')
127127
->with($this->storeMock);
128-
$this->requestMock->expects($this->atLeastOnce())
128+
$this->requestMock->expects($this->once())
129129
->method('getParam')
130130
->with(StoreResolverInterface::PARAM_NAME)
131131
->willReturn(null);
@@ -139,7 +139,7 @@ public function testBeforeDispatchStoreIsInactive()
139139
$this->storeManagerMock->expects($this->once())
140140
->method('getDefaultStoreView')
141141
->willReturn($this->storeMock);
142-
$this->storeCookieManagerMock->expects($this->atLeastOnce())
142+
$this->storeCookieManagerMock->expects($this->exactly(2))
143143
->method('getStoreCodeFromCookie')
144144
->willReturn($storeCode);
145145
$this->storeRepositoryMock->expects($this->once())
@@ -148,7 +148,7 @@ public function testBeforeDispatchStoreIsInactive()
148148
$this->storeCookieManagerMock->expects($this->once())
149149
->method('deleteStoreCookie')
150150
->with($this->storeMock);
151-
$this->requestMock->expects($this->atLeastOnce())
151+
$this->requestMock->expects($this->once())
152152
->method('getParam')
153153
->with(StoreResolverInterface::PARAM_NAME)
154154
->willReturn(null);
@@ -162,7 +162,7 @@ public function testBeforeDispatchInvalidArgument()
162162
$this->storeManagerMock->expects($this->once())
163163
->method('getDefaultStoreView')
164164
->willReturn($this->storeMock);
165-
$this->storeCookieManagerMock->expects($this->atLeastOnce())
165+
$this->storeCookieManagerMock->expects($this->exactly(2))
166166
->method('getStoreCodeFromCookie')
167167
->willReturn($storeCode);
168168
$this->storeRepositoryMock->expects($this->once())
@@ -171,7 +171,7 @@ public function testBeforeDispatchInvalidArgument()
171171
$this->storeCookieManagerMock->expects($this->once())
172172
->method('deleteStoreCookie')
173173
->with($this->storeMock);
174-
$this->requestMock->expects($this->atLeastOnce())
174+
$this->requestMock->expects($this->once())
175175
->method('getParam')
176176
->with(StoreResolverInterface::PARAM_NAME)
177177
->willReturn(null);
@@ -182,7 +182,7 @@ public function testBeforeDispatchInvalidArgument()
182182
public function testBeforeDispatchNoStoreCookie()
183183
{
184184
$storeCode = null;
185-
$this->storeCookieManagerMock->expects($this->atLeastOnce())
185+
$this->storeCookieManagerMock->expects($this->exactly(2))
186186
->method('getStoreCodeFromCookie')
187187
->willReturn($storeCode);
188188
$this->storeManagerMock->expects($this->never())
@@ -194,15 +194,15 @@ public function testBeforeDispatchNoStoreCookie()
194194
->method('deleteStoreCookie')
195195
->with($this->storeMock);
196196

197-
$this->storeResolverMock->expects($this->atLeastOnce())
197+
$this->storeResolverMock->expects($this->once())
198198
->method('getCurrentStoreId')
199199
->willReturn(1);
200200

201-
$this->storeRepositoryMock->expects($this->atLeastOnce())
201+
$this->storeRepositoryMock->expects($this->once())
202202
->method('getActiveStoreById')
203203
->willReturn($this->storeMock);
204204

205-
$this->storeCookieManagerMock->expects($this->atLeastOnce())
205+
$this->storeCookieManagerMock->expects($this->once())
206206
->method('setStoreCookie')
207207
->with($this->storeMock);
208208

@@ -212,30 +212,30 @@ public function testBeforeDispatchNoStoreCookie()
212212
public function testBeforeDispatchWithStoreRequestParam()
213213
{
214214
$storeCode = 'store';
215-
$this->storeCookieManagerMock->expects($this->atLeastOnce())
215+
$this->storeCookieManagerMock->expects($this->exactly(2))
216216
->method('getStoreCodeFromCookie')
217217
->willReturn($storeCode);
218-
$this->storeRepositoryMock->expects($this->atLeastOnce())
218+
$this->storeRepositoryMock->expects($this->once())
219219
->method('getActiveStoreByCode')
220220
->willReturn($this->storeMock);
221221
$this->storeCookieManagerMock->expects($this->never())
222222
->method('deleteStoreCookie')
223223
->with($this->storeMock);
224224

225-
$this->requestMock->expects($this->atLeastOnce())
225+
$this->requestMock->expects($this->once())
226226
->method('getParam')
227227
->with(StoreResolverInterface::PARAM_NAME)
228228
->willReturn($storeCode);
229229

230-
$this->storeResolverMock->expects($this->atLeastOnce())
230+
$this->storeResolverMock->expects($this->once())
231231
->method('getCurrentStoreId')
232232
->willReturn(1);
233233

234-
$this->storeRepositoryMock->expects($this->atLeastOnce())
234+
$this->storeRepositoryMock->expects($this->once())
235235
->method('getActiveStoreById')
236236
->willReturn($this->storeMock);
237237

238-
$this->storeCookieManagerMock->expects($this->atLeastOnce())
238+
$this->storeCookieManagerMock->expects($this->once())
239239
->method('setStoreCookie')
240240
->with($this->storeMock);
241241

0 commit comments

Comments
 (0)