Skip to content

Commit

Permalink
UrlRewrite module fixes
Browse files Browse the repository at this point in the history
update fixture
update integration test
  • Loading branch information
arendarenko committed Nov 15, 2019
1 parent 19b7bda commit f63475c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,36 @@ public function requestDataProvider(): array
'request' => '/page-similar/',
'redirect' => '/page-b',
],
'Use Case #7: Rewrite: page-similar --(301)--> page-a; '
. 'Request: page-similar?param=1 --(301)--> page-a?param=1' => [
'request' => '/page-similar?param=1',
'redirect' => '/page-a?param=1',
],
'Use Case #8: Rewrite: page-similar/ --(301)--> page-b; '
. 'Request: page-similar/?param=1 --(301)--> page-b?param=1' => [
'request' => '/page-similar/?param=1',
'redirect' => '/page-b?param=1',
],
'Use Case #9: Rewrite: page-similar-query-param --(301)--> page-d?param1=1;'
. 'Request: page-similar-query-param --(301)--> page-d?param1=1' => [
'request' => '/page-similar-query-param',
'redirect' => '/page-d?param1=1',
],
'Use Case #10: Rewrite: page-similar-query-param --(301)--> page-d?param1=1; '
. 'Request: page-similar-query-param?param2=1 --(301)--> page-d?param1=1&param2=1' => [
'request' => '/page-similar-query-param?param2=1',
'redirect' => '/page-d?param1=1&param2=1',
],
'Use Case #11: Rewrite: page-similar-query-param/ --(301)--> page-e?param1=1; '
. 'Request: page-similar-query-param/ --(301)--> page-e?param1=1' => [
'request' => '/page-similar-query-param/',
'redirect' => '/page-e?param1=1',
],
'Use Case #12: Rewrite: page-similar-query-param/ --(301)--> page-e?param1=1;'
. 'Request: page-similar-query-param/?param2=1 --(301)--> page-e?param1=1&param2=1' => [
'request' => '/page-similar-query-param/?param2=1',
'redirect' => '/page-e?param1=1&param2=1',
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@
->setStores([$storeID, $secondStoreId]);
$pageResource->save($page);

$page = $objectManager->create(Page::class);
$page->setTitle('Cms D')
->setIdentifier('page-d')
->setIsActive(1)
->setContent('<h1>Cms Page D</h1>')
->setPageLayout('1column')
->setCustomTheme('Magento/blank')
->setStores([$storeID, $secondStoreId]);
$pageResource->save($page);

$page = $objectManager->create(Page::class);
$page->setTitle('Cms E')
->setIdentifier('page-e')
->setIsActive(1)
->setContent('<h1>Cms Page E</h1>')
->setPageLayout('1column')
->setCustomTheme('Magento/blank')
->setStores([$storeID, $secondStoreId]);
$pageResource->save($page);

$rewrite = $objectManager->create(UrlRewrite::class);
$rewrite->setEntityType('custom')
->setRequestPath('page-one/')
Expand All @@ -88,7 +108,7 @@
->setTargetPath('page-a')
->setRedirectType(OptionProvider::PERMANENT)
->setStoreId($storeID)
->setDescription('From age-similar without trailing slash to page-a');
->setDescription('From page-similar without trailing slash to page-a');
$rewriteResource->save($rewrite);

$rewrite = $objectManager->create(UrlRewrite::class);
Expand All @@ -97,7 +117,7 @@
->setTargetPath('page-b')
->setRedirectType(OptionProvider::PERMANENT)
->setStoreId($storeID)
->setDescription('From age-similar with trailing slash to page-b');
->setDescription('From page-similar with trailing slash to page-b');
$rewriteResource->save($rewrite);

//Emulating auto-generated aliases (like the ones used for categories).
Expand All @@ -117,3 +137,21 @@
->setRedirectType(0)
->setStoreId($secondStoreId);
$rewriteResource->save($rewrite);

$rewrite = $objectManager->create(UrlRewrite::class);
$rewrite->setEntityType('custom')
->setRequestPath('page-similar-query-param')
->setTargetPath('page-d?param1=1')
->setRedirectType(OptionProvider::PERMANENT)
->setStoreId($storeID)
->setDescription('From page-similar-query-param to page-d with query param');
$rewriteResource->save($rewrite);

$rewrite = $objectManager->create(UrlRewrite::class);
$rewrite->setEntityType('custom')
->setRequestPath('page-similar-query-param/')
->setTargetPath('page-e?param1=1')
->setRedirectType(OptionProvider::PERMANENT)
->setStoreId($storeID)
->setDescription('From page-similar-query-param with trailing slash to page-e with query param');
$rewriteResource->save($rewrite);
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
$pageRepository->deleteById('page-a');
$pageRepository->deleteById('page-b');
$pageRepository->deleteById('page-c');
$pageRepository->deleteById('page-d');
$pageRepository->deleteById('page-e');

/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
Expand All @@ -29,7 +31,7 @@
->create(\Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection::class);
$collection = $urlRewriteCollection
->addFieldToFilter('entity_type', 'custom')
->addFieldToFilter('target_path', ['page-a/', 'page-a', 'page-b', 'page-c'])
->addFieldToFilter('target_path', ['page-a/', 'page-a', 'page-b', 'page-c', 'page-d?param1=1', 'page-e?param1=1'])
->load()
->walk('delete');

Expand Down

0 comments on commit f63475c

Please sign in to comment.