Skip to content

Commit fa468e7

Browse files
author
Roman Lytvynenko
committed
MC-22635: Roll back the changes introduced with MAGETWO-96663
1 parent 67f525d commit fa468e7

File tree

3 files changed

+8
-87
lines changed

3 files changed

+8
-87
lines changed

app/code/Magento/UrlRewrite/Controller/Router.php

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
*/
66
namespace Magento\UrlRewrite\Controller;
77

8+
use Magento\Framework\App\Action\Redirect;
9+
use Magento\Framework\App\ActionInterface;
10+
use Magento\Framework\App\Request\Http as HttpRequest;
811
use Magento\Framework\App\RequestInterface;
12+
use Magento\Framework\App\Response\Http as HttpResponse;
13+
use Magento\Framework\Exception\NoSuchEntityException;
14+
use Magento\Framework\UrlInterface;
915
use Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite;
1016
use Magento\UrlRewrite\Model\UrlFinderInterface;
1117
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
12-
use Magento\Framework\App\Request\Http as HttpRequest;
13-
use Magento\Framework\App\Response\Http as HttpResponse;
14-
use Magento\Framework\UrlInterface;
15-
use Magento\Framework\App\Action\Redirect;
16-
use Magento\Framework\App\ActionInterface;
1718

1819
/**
1920
* UrlRewrite Controller Router
@@ -73,11 +74,12 @@ public function __construct(
7374
*
7475
* @param RequestInterface|HttpRequest $request
7576
* @return ActionInterface|null
77+
* @throws NoSuchEntityException
7678
*/
7779
public function match(RequestInterface $request)
7880
{
7981
$rewrite = $this->getRewrite(
80-
$this->getNormalizedPathInfo($request),
82+
$request->getPathInfo(),
8183
$this->storeManager->getStore()->getId()
8284
);
8385

@@ -153,30 +155,4 @@ protected function getRewrite($requestPath, $storeId)
153155
]
154156
);
155157
}
156-
157-
/**
158-
* Get normalized request path
159-
*
160-
* @param RequestInterface|HttpRequest $request
161-
* @return string
162-
*/
163-
private function getNormalizedPathInfo(RequestInterface $request): string
164-
{
165-
$path = $request->getPathInfo();
166-
/**
167-
* If request contains query params then we need to trim a slash in end of the path.
168-
* For example:
169-
* the original request is: http://my-host.com/category-url-key.html/?color=black
170-
* where the original path is: category-url-key.html/
171-
* and the result path will be: category-url-key.html
172-
*
173-
* It need to except a redirect like this:
174-
* http://my-host.com/category-url-key.html/?color=black => http://my-host.com/category-url-key.html
175-
*/
176-
if (!empty($path) && $request->getQuery()->count()) {
177-
$path = rtrim($path, '/');
178-
}
179-
180-
return (string)$path;
181-
}
182158
}

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

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -351,54 +351,4 @@ public function testMatch()
351351

352352
$this->router->match($this->request);
353353
}
354-
355-
/**
356-
* Test to match corresponding URL Rewrite on request with query params
357-
*
358-
* @param string $originalRequestPath
359-
* @param string $requestPath
360-
* @param int $countOfQueryParams
361-
* @dataProvider matchWithQueryParamsDataProvider
362-
*/
363-
public function testMatchWithQueryParams(string $originalRequestPath, string $requestPath, int $countOfQueryParams)
364-
{
365-
$targetPath = 'target-path';
366-
367-
$this->storeManager->method('getStore')->willReturn($this->store);
368-
$urlRewrite = $this->createMock(UrlRewrite::class);
369-
$urlRewrite->method('getRedirectType')->willReturn(0);
370-
$urlRewrite->method('getTargetPath')->willReturn($targetPath);
371-
$urlRewrite->method('getRequestPath')->willReturn($requestPath);
372-
$this->urlFinder->method('findOneByData')
373-
->with([UrlRewrite::REQUEST_PATH => $requestPath, UrlRewrite::STORE_ID => $this->store->getId()])
374-
->willReturn($urlRewrite);
375-
376-
$this->requestQuery->method('count')->willReturn($countOfQueryParams);
377-
$this->request->method('getPathInfo')
378-
->willReturn($originalRequestPath);
379-
$this->request->expects($this->once())
380-
->method('setPathInfo')
381-
->with('/' . $targetPath);
382-
$this->request->expects($this->once())
383-
->method('setAlias')
384-
->with(UrlInterface::REWRITE_REQUEST_PATH_ALIAS, $requestPath);
385-
$this->actionFactory->expects($this->once())
386-
->method('create')
387-
->with(Forward::class);
388-
389-
$this->router->match($this->request);
390-
}
391-
392-
/**
393-
* Data provider for Test to match corresponding URL Rewrite on request with query params
394-
*
395-
* @return array
396-
*/
397-
public function matchWithQueryParamsDataProvider(): array
398-
{
399-
return [
400-
['/category.html/', 'category.html/', 0],
401-
['/category.html/', 'category.html', 1],
402-
];
403-
}
404354
}

dev/tests/integration/testsuite/Magento/UrlRewrite/Controller/UrlRewriteTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ public function requestDataProvider(): array
8080
'request' => '/page-similar/',
8181
'redirect' => '/page-b',
8282
],
83-
'Use Case #7: Request with query params' => [
84-
'request' => '/enable-cookies/?test-param',
85-
'redirect' => '',
86-
HttpResponse::STATUS_CODE_200,
87-
],
8883
];
8984
}
9085

0 commit comments

Comments
 (0)