Skip to content

Commit

Permalink
#25603 Fix removing query string from url after redirect
Browse files Browse the repository at this point in the history
Cover with integration tests cases with external URLs as target path
  • Loading branch information
ihor-sviziev committed Dec 4, 2019
1 parent f63475c commit b1a2a29
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public function testMatchUrlRewrite(
$location = $response->getHeader('Location')->getFieldValue();
$this->assertStringEndsWith(
$redirect,
$location,
'Invalid location header'
$location
);
}
}
Expand Down Expand Up @@ -110,6 +109,30 @@ public function requestDataProvider(): array
'request' => '/page-similar-query-param/?param2=1',
'redirect' => '/page-e?param1=1&param2=1',
],
'Use Case #13: Rewrite: page-external1 --(301)--> http://example.com/external;'
. 'Request: page-external1?param1=1 --(301)--> http://example.com/external (not fills get params)' => [
'request' => '/page-external1?param1=1',
'redirect' => 'http://example.com/external',
],
'Use Case #14: Rewrite: page-external2/ --(301)--> https://example.com/external2/;'
. 'Request: page-external2?param2=1 --(301)--> https://example.com/external2/ (not fills get params)' => [
'request' => '/page-external2?param2=1',
'redirect' => 'https://example.com/external2/',
],
'Use Case #15: Rewrite: page-external3 --(301)--> http://example.com/external?param1=value1;'
. 'Request: page-external3?param1=custom1&param2=custom2 --(301)--> '
. 'http://example.com/external?param1=value1'
. ' (fills get param from target path)' => [
'request' => '/page-external3?param1=custom1&param2=custom2',
'redirect' => 'http://example.com/external?param1=value1',
],
'Use Case #16: Rewrite: page-external4/ --(301)--> https://example.com/external2/?param2=value2;'
. 'Request: page-external4?param1=custom1&param2=custom2 --(301)--> '
. 'https://example.com/external2/?param2=value2 '
. ' (fills get param from target path)' => [
'request' => '/page-external4?param1=custom1&param2=custom2',
'redirect' => 'https://example.com/external2/?param2=value2',
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,39 @@
->setStoreId($storeID)
->setDescription('From page-similar-query-param with trailing slash to page-e with query param');
$rewriteResource->save($rewrite);

$rewrite = $objectManager->create(UrlRewrite::class);
$rewrite->setEntityType('custom')
->setRequestPath('page-external1')
->setTargetPath('http://example.com/external')
->setRedirectType(OptionProvider::PERMANENT)
->setStoreId($storeID)
->setDescription('From page-external to external URL');
$rewriteResource->save($rewrite);

$rewrite = $objectManager->create(UrlRewrite::class);
$rewrite->setEntityType('custom')
->setRequestPath('page-external2/')
->setTargetPath('https://example.com/external2/')
->setRedirectType(OptionProvider::PERMANENT)
->setStoreId($storeID)
->setDescription('From page-external with trailing slash to external URL');
$rewriteResource->save($rewrite);

$rewrite = $objectManager->create(UrlRewrite::class);
$rewrite->setEntityType('custom')
->setRequestPath('page-external3')
->setTargetPath('http://example.com/external?param1=value1')
->setRedirectType(OptionProvider::PERMANENT)
->setStoreId($storeID)
->setDescription('From page-external to external URL');
$rewriteResource->save($rewrite);

$rewrite = $objectManager->create(UrlRewrite::class);
$rewrite->setEntityType('custom')
->setRequestPath('page-external4/')
->setTargetPath('https://example.com/external2/?param2=value2')
->setRedirectType(OptionProvider::PERMANENT)
->setStoreId($storeID)
->setDescription('From page-external with trailing slash to external URL');
$rewriteResource->save($rewrite);
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@
->create(\Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection::class);
$collection = $urlRewriteCollection
->addFieldToFilter('entity_type', 'custom')
->addFieldToFilter('target_path', ['page-a/', 'page-a', 'page-b', 'page-c', 'page-d?param1=1', 'page-e?param1=1'])
->addFieldToFilter(
'target_path',
[
'page-a/',
'page-a',
'page-b',
'page-c',
'page-d?param1=1',
'page-e?param1=1',
'http://example.com/external',
'https://example.com/external2/',
'http://example.com/external?param1=value1',
'https://example.com/external2/?param2=value2'
]
)
->load()
->walk('delete');

Expand Down

0 comments on commit b1a2a29

Please sign in to comment.