48 $this->actionFactory = $this->createMock(\
Magento\Framework\
App\ActionFactory::class);
49 $this->url = $this->createMock(\
Magento\Framework\UrlInterface::class);
50 $this->storeManager = $this->createMock(\
Magento\
Store\Model\StoreManagerInterface::class);
51 $this->response = $this->createPartialMock(
52 \
Magento\Framework\
App\ResponseInterface::class,
53 [
'setRedirect',
'sendResponse']
55 $this->request = $this->getMockBuilder(\
Magento\Framework\
App\Request\Http::class)
56 ->disableOriginalConstructor()->getMock();
57 $this->urlFinder = $this->createMock(\
Magento\
UrlRewrite\Model\UrlFinderInterface::class);
58 $this->store = $this->getMockBuilder(
60 )->disableOriginalConstructor()->getMock();
65 'actionFactory' => $this->actionFactory,
67 'storeManager' => $this->storeManager,
68 'response' => $this->response,
69 'urlFinder' => $this->urlFinder
79 $this->urlFinder->expects($this->any())->method(
'findOneByData')->will($this->returnValue(
null));
80 $this->storeManager->expects($this->any())->method(
'getStore')->will($this->returnValue($this->store));
81 $this->store->expects($this->any())->method(
'getId')->will($this->returnValue(
'current-store-id'));
83 $this->assertNull($this->router->match($this->request));
91 $initialRequestPath =
'request-path';
92 $newRequestPath =
'new-request-path';
93 $oldStoreAlias =
'old-store';
94 $oldStoreId =
'old-store-id';
96 $rewriteEntityType =
'entity-type';
97 $rewriteEntityId = 42;
99 ->expects($this->any())
101 ->with(
'___from_store')
102 ->willReturn($oldStoreAlias);
104 ->expects($this->any())
105 ->method(
'getPathInfo')
106 ->willReturn($initialRequestPath);
107 $oldStore = $this->getMockBuilder(Store::class)
108 ->disableOriginalConstructor()
110 $oldStore->expects($this->any())
112 ->willReturn($oldStoreId);
114 ->expects($this->any())
118 ->expects($this->any())
120 ->willReturnMap([[$oldStoreAlias, $oldStore], [
null, $this->store]]);
121 $oldUrlRewrite = $this->getMockBuilder(UrlRewrite::class)
122 ->disableOriginalConstructor()
124 $oldUrlRewrite->expects($this->any())
125 ->method(
'getEntityType')
126 ->willReturn($rewriteEntityType);
127 $oldUrlRewrite->expects($this->any())
128 ->method(
'getEntityId')
129 ->willReturn($rewriteEntityId);
130 $oldUrlRewrite->expects($this->any())
131 ->method(
'getRedirectType')
133 $urlRewrite = $this->getMockBuilder(UrlRewrite::class)
134 ->disableOriginalConstructor()
136 $urlRewrite->expects($this->any())
137 ->method(
'getRequestPath')
138 ->willReturn($newRequestPath);
140 ->expects($this->any())
141 ->method(
'findOneByData')
152 ->expects($this->once())
154 ->with(Forward::class);
155 $this->router->match($this->request);
163 $this->request->expects($this->any())->method(
'getPathInfo')->will($this->returnValue(
'request-path'));
164 $this->request->expects($this->any())->method(
'getParam')->with(
'___from_store')
165 ->will($this->returnValue(
'old-store'));
166 $oldStore = $this->getMockBuilder(\
Magento\
Store\Model\Store::class)->disableOriginalConstructor()->getMock();
167 $this->storeManager->expects($this->any())->method(
'getStore')
168 ->will($this->returnValueMap([[
'old-store', $oldStore], [
null, $this->store]]));
169 $oldStore->expects($this->any())->method(
'getId')->will($this->returnValue(
'old-store-id'));
170 $this->store->expects($this->any())->method(
'getId')->will($this->returnValue(
'current-store-id'));
171 $oldUrlRewrite = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewrite::class)
172 ->disableOriginalConstructor()->getMock();
173 $oldUrlRewrite->expects($this->any())->method(
'getEntityType')->will($this->returnValue(
'entity-type'));
174 $oldUrlRewrite->expects($this->any())->method(
'getEntityId')->will($this->returnValue(
'entity-id'));
175 $oldUrlRewrite->expects($this->any())->method(
'getRequestPath')->will($this->returnValue(
'request-path'));
176 $urlRewrite = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewrite::class)
177 ->disableOriginalConstructor()->getMock();
178 $urlRewrite->expects($this->any())->method(
'getRequestPath')->will($this->returnValue(
'request-path'));
180 $this->assertNull($this->router->match($this->request));
188 $this->request->expects($this->any())->method(
'getPathInfo')->will($this->returnValue(
'request-path'));
189 $this->request->expects($this->any())->method(
'getParam')->with(
'___from_store')
190 ->will($this->returnValue(
'old-store'));
191 $oldStore = $this->getMockBuilder(\
Magento\
Store\Model\Store::class)->disableOriginalConstructor()->getMock();
192 $this->storeManager->expects($this->any())->method(
'getStore')
193 ->will($this->returnValueMap([[
'old-store', $oldStore], [
null, $this->store]]));
194 $oldStore->expects($this->any())->method(
'getId')->will($this->returnValue(
'old-store-id'));
195 $this->store->expects($this->any())->method(
'getId')->will($this->returnValue(
'current-store-id'));
196 $oldUrlRewrite = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewrite::class)
197 ->disableOriginalConstructor()->getMock();
198 $oldUrlRewrite->expects($this->any())->method(
'getEntityType')->will($this->returnValue(
'entity-type'));
199 $oldUrlRewrite->expects($this->any())->method(
'getEntityId')->will($this->returnValue(
'entity-id'));
200 $oldUrlRewrite->expects($this->any())->method(
'getRequestPath')->will($this->returnValue(
'old-request-path'));
201 $urlRewrite = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewrite::class)
202 ->disableOriginalConstructor()->getMock();
203 $urlRewrite->expects($this->any())->method(
'getRequestPath')->will($this->returnValue(
'old-request-path'));
205 $this->urlFinder->expects($this->any())->method(
'findOneByData')->will(
206 $this->returnValueMap([
223 $this->assertNull($this->router->match($this->request));
231 $this->storeManager->expects($this->any())->method(
'getStore')->will($this->returnValue($this->store));
232 $urlRewrite = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewrite::class)
233 ->disableOriginalConstructor()->getMock();
234 $urlRewrite->expects($this->any())->method(
'getRedirectType')->will($this->returnValue(
'redirect-code'));
235 $urlRewrite->expects($this->any())->method(
'getTargetPath')->will($this->returnValue(
'target-path'));
236 $this->urlFinder->expects($this->any())->method(
'findOneByData')->will($this->returnValue($urlRewrite));
237 $this->response->expects($this->once())->method(
'setRedirect')
238 ->with(
'new-target-path',
'redirect-code');
239 $this->url->expects($this->once())->method(
'getUrl')->with(
'', [
'_direct' =>
'target-path'])
240 ->will($this->returnValue(
'new-target-path'));
241 $this->request->expects($this->once())->method(
'setDispatched')->with(
true);
242 $this->actionFactory->expects($this->once())->method(
'create')
243 ->with(\
Magento\Framework\
App\Action\Redirect::class);
245 $this->router->match($this->request);
253 $this->storeManager->expects($this->any())->method(
'getStore')->will($this->returnValue($this->store));
254 $urlRewrite = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewrite::class)
255 ->disableOriginalConstructor()->getMock();
256 $urlRewrite->expects($this->any())->method(
'getEntityType')->will($this->returnValue(
'custom'));
257 $urlRewrite->expects($this->any())->method(
'getRedirectType')->will($this->returnValue(
'redirect-code'));
258 $urlRewrite->expects($this->any())->method(
'getTargetPath')->will($this->returnValue(
'target-path'));
259 $this->urlFinder->expects($this->any())->method(
'findOneByData')->will($this->returnValue($urlRewrite));
260 $this->response->expects($this->once())->method(
'setRedirect')->with(
'a',
'redirect-code');
261 $this->url->expects($this->once())->method(
'getUrl')->with(
'', [
'_direct' =>
'target-path'])->willReturn(
'a');
262 $this->request->expects($this->once())->method(
'setDispatched')->with(
true);
263 $this->actionFactory->expects($this->once())->method(
'create')
264 ->with(\
Magento\Framework\
App\Action\Redirect::class);
266 $this->router->match($this->request);
275 $this->storeManager->expects($this->any())->method(
'getStore')->will($this->returnValue($this->store));
276 $urlRewrite = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewrite::class)
277 ->disableOriginalConstructor()->getMock();
278 $urlRewrite->expects($this->any())->method(
'getEntityType')->will($this->returnValue(
'custom'));
279 $urlRewrite->expects($this->any())->method(
'getRedirectType')->will($this->returnValue(
'redirect-code'));
280 $urlRewrite->expects($this->any())->method(
'getTargetPath')->will($this->returnValue($targetPath));
281 $this->urlFinder->expects($this->any())->method(
'findOneByData')->will($this->returnValue($urlRewrite));
282 $this->response->expects($this->once())->method(
'setRedirect')->with($targetPath,
'redirect-code');
283 $this->url->expects($this->never())->method(
'getUrl');
284 $this->request->expects($this->once())->method(
'setDispatched')->with(
true);
285 $this->actionFactory->expects($this->once())->method(
'create')
286 ->with(\
Magento\Framework\
App\Action\Redirect::class);
288 $this->router->match($this->request);
297 [
'http://example.com'],
298 [
'https://example.com'],
307 $this->storeManager->expects($this->any())->method(
'getStore')->will($this->returnValue($this->store));
308 $urlRewrite = $this->getMockBuilder(\
Magento\
UrlRewrite\Service\V1\Data\UrlRewrite::class)
309 ->disableOriginalConstructor()->getMock();
310 $urlRewrite->expects($this->any())->method(
'getRedirectType')->will($this->returnValue(0));
311 $urlRewrite->expects($this->any())->method(
'getTargetPath')->will($this->returnValue(
'target-path'));
312 $urlRewrite->expects($this->any())->method(
'getRequestPath')->will($this->returnValue(
'request-path'));
313 $this->urlFinder->expects($this->any())->method(
'findOneByData')->will($this->returnValue($urlRewrite));
314 $this->request->expects($this->once())->method(
'setPathInfo')->with(
'/target-path');
315 $this->request->expects($this->once())->method(
'setAlias')
316 ->with(\
Magento\Framework\UrlInterface::REWRITE_REQUEST_PATH_ALIAS,
'request-path');
317 $this->actionFactory->expects($this->once())->method(
'create')
318 ->with(\
Magento\Framework\
App\Action\Forward::class);
320 $this->router->match($this->request);
testMatchWithCustomExternalRedirect($targetPath)
testMatchWithCustomInternalRedirect()
testNoRewriteAfterStoreSwitcherWhenOldRewriteEqualsToNewOne()
testNoRewriteAfterStoreSwitcherWhenNoOldRewrite()
externalRedirectTargetPathDataProvider()
testRewriteAfterStoreSwitcher()