Skip to content

Commit 19b7bda

Browse files
committed
UrlRewrite module fixes
update unit test
1 parent 0693cc2 commit 19b7bda

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

app/code/Magento/UrlRewrite/Test/Unit/Controller/RouterTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ public function testNoRewriteAfterStoreSwitcherWhenOldRewriteEqualsToNewOne()
260260
*/
261261
public function testMatchWithRedirect()
262262
{
263+
$queryParams = [];
263264
$this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store));
264265
$urlRewrite = $this->getMockBuilder(UrlRewrite::class)
265266
->disableOriginalConstructor()->getMock();
@@ -268,7 +269,11 @@ public function testMatchWithRedirect()
268269
$this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue($urlRewrite));
269270
$this->response->expects($this->once())->method('setRedirect')
270271
->with('new-target-path', 'redirect-code');
271-
$this->url->expects($this->once())->method('getUrl')->with('', ['_direct' => 'target-path'])
272+
$this->request->expects($this->once())->method('getParams')->willReturn($queryParams);
273+
$this->url->expects($this->once())->method('getUrl')->with(
274+
'',
275+
['_direct' => 'target-path', '_query' => $queryParams]
276+
)
272277
->will($this->returnValue('new-target-path'));
273278
$this->request->expects($this->once())->method('setDispatched')->with(true);
274279
$this->actionFactory->expects($this->once())->method('create')
@@ -282,15 +287,20 @@ public function testMatchWithRedirect()
282287
*/
283288
public function testMatchWithCustomInternalRedirect()
284289
{
290+
$queryParams = [];
285291
$this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($this->store));
286292
$urlRewrite = $this->getMockBuilder(UrlRewrite::class)
287293
->disableOriginalConstructor()->getMock();
288294
$urlRewrite->expects($this->any())->method('getEntityType')->will($this->returnValue('custom'));
289295
$urlRewrite->expects($this->any())->method('getRedirectType')->will($this->returnValue('redirect-code'));
290296
$urlRewrite->expects($this->any())->method('getTargetPath')->will($this->returnValue('target-path'));
291297
$this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue($urlRewrite));
298+
$this->request->expects($this->any())->method('getParams')->willReturn($queryParams);
292299
$this->response->expects($this->once())->method('setRedirect')->with('a', 'redirect-code');
293-
$this->url->expects($this->once())->method('getUrl')->with('', ['_direct' => 'target-path'])->willReturn('a');
300+
$this->url->expects($this->once())->method('getUrl')->with(
301+
'',
302+
['_direct' => 'target-path', '_query' => $queryParams]
303+
)->willReturn('a');
294304
$this->request->expects($this->once())->method('setDispatched')->with(true);
295305
$this->actionFactory->expects($this->once())->method('create')
296306
->with(\Magento\Framework\App\Action\Redirect::class);
@@ -312,6 +322,7 @@ public function testMatchWithCustomExternalRedirect($targetPath)
312322
$urlRewrite->expects($this->any())->method('getTargetPath')->will($this->returnValue($targetPath));
313323
$this->urlFinder->expects($this->any())->method('findOneByData')->will($this->returnValue($urlRewrite));
314324
$this->response->expects($this->once())->method('setRedirect')->with($targetPath, 'redirect-code');
325+
$this->request->expects($this->never())->method('getParams');
315326
$this->url->expects($this->never())->method('getUrl');
316327
$this->request->expects($this->once())->method('setDispatched')->with(true);
317328
$this->actionFactory->expects($this->once())->method('create')

0 commit comments

Comments
 (0)