Skip to content

Commit ecd3a1c

Browse files
MC-18561: After changing store view the cms page is not redirecting correctly
1 parent 8375d08 commit ecd3a1c

File tree

1 file changed

+30
-73
lines changed
  • dev/tests/integration/testsuite/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store

1 file changed

+30
-73
lines changed

dev/tests/integration/testsuite/Magento/CmsUrlRewrite/Plugin/Cms/Model/Store/ViewTest.php

Lines changed: 30 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
namespace Magento\CmsUrlRewrite\Plugin\Cms\Model\Store;
99

1010
use Magento\Framework\ObjectManagerInterface;
11-
use Magento\Framework\Registry;
1211
use Magento\Store\Model\Store;
1312
use Magento\Store\Model\StoreFactory;
14-
use Magento\Store\Api\WebsiteRepositoryInterface;
1513
use Magento\TestFramework\Helper\Bootstrap;
1614
use Magento\UrlRewrite\Model\UrlFinderInterface;
1715
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
@@ -34,20 +32,10 @@ class ViewTest extends \PHPUnit\Framework\TestCase
3432
private $objectManager;
3533

3634
/**
37-
* @var StoreFactory
35+
* @var Store
3836
*/
3937
private $storeFactory;
4038

41-
/**
42-
* @var string
43-
*/
44-
private $storeCode;
45-
46-
/**
47-
* @var WebsiteRepositoryInterface
48-
*/
49-
private $websiteRepository;
50-
5139
/**
5240
* @inheritdoc
5341
*/
@@ -56,8 +44,6 @@ protected function setUp()
5644
$this->objectManager = Bootstrap::getObjectManager();
5745
$this->urlFinder = $this->objectManager->create(UrlFinderInterface::class);
5846
$this->storeFactory = $this->objectManager->create(StoreFactory::class);
59-
$this->websiteRepository = $this->objectManager->get(WebsiteRepositoryInterface::class);
60-
$this->storeCode = 'test_' . random_int(0, 999);
6147
}
6248

6349
/**
@@ -66,86 +52,57 @@ protected function setUp()
6652
* @magentoDataFixture Magento/Cms/_files/pages.php
6753
*/
6854
public function testUrlRewritesChangesAfterStoreSave()
55+
{
56+
$storeId = $this->createStore();
57+
$this->assertUrlRewritesCount($storeId, 1);
58+
$this->deleteStore($storeId);
59+
$this->assertUrlRewritesCount($storeId, 0);
60+
}
61+
62+
/**
63+
* Assert url rewrites count by store id
64+
*
65+
* @param int $storeId
66+
* @param int $expectedCount
67+
*/
68+
private function assertUrlRewritesCount(int $storeId, int $expectedCount): void
6969
{
7070
$data = [
7171
UrlRewrite::REQUEST_PATH => 'page100',
72+
UrlRewrite::STORE_ID => $storeId
7273
];
7374
$urlRewrites = $this->urlFinder->findAllByData($data);
74-
$this->assertCount(1, $urlRewrites);
75-
$this->createStore();
76-
$urlRewrites = $this->urlFinder->findAllByData($data);
77-
$this->assertCount(2, $urlRewrites);
78-
$this->deleteStore();
79-
$urlRewrites = $this->urlFinder->findAllByData($data);
80-
$this->assertCount(1, $urlRewrites);
75+
$this->assertCount($expectedCount, $urlRewrites);
8176
}
8277

8378
/**
8479
* Create test store
8580
*
86-
* @return void
81+
* @return int
8782
*/
88-
private function createStore(): void
83+
private function createStore(): int
8984
{
90-
/** @var $store Store */
9185
$store = $this->storeFactory->create();
92-
if (!$store->load($this->storeCode, 'code')->getId()) {
93-
$store->setData(
94-
[
95-
'code' => $this->storeCode,
96-
'website_id' => $this->websiteRepository->getDefault()->getId(),
97-
'group_id' => $this->websiteRepository->getDefault()->getDefaultGroupId(),
98-
'name' => 'Test Store',
99-
'sort_order' => '0',
100-
'is_active' => '1',
101-
]
102-
);
103-
$store->save();
104-
} else {
105-
if ($store->getId()) {
106-
/** @var \Magento\TestFramework\Helper\Bootstrap $registry */
107-
$registry = $this->objectManager->get(
108-
Registry::class
109-
);
110-
$registry->unregister('isSecureArea');
111-
$registry->register('isSecureArea', true);
112-
$store->delete();
113-
$registry->unregister('isSecureArea');
114-
$registry->register('isSecureArea', false);
115-
$store = $this->objectManager->create(Store::class);
116-
$store->setData(
117-
[
118-
'code' => $this->storeCode,
119-
'website_id' => $this->websiteRepository->getDefault()->getId(),
120-
'group_id' => $this->websiteRepository->getDefault()->getDefaultGroupId(),
121-
'name' => 'Test Store',
122-
'sort_order' => '0',
123-
'is_active' => '1',
124-
]
125-
);
126-
$store->save();
127-
}
128-
}
86+
$store->setCode('test_' . random_int(0, 999))
87+
->setName('Test Store')
88+
->unsId()
89+
->save();
90+
91+
return (int)$store->getId();
12992
}
13093

13194
/**
13295
* Delete test store
13396
*
97+
* @param int $storeId
13498
* @return void
13599
*/
136-
private function deleteStore(): void
100+
private function deleteStore(int $storeId): void
137101
{
138-
/** @var Registry $registry */
139-
$registry = $this->objectManager->get(Registry::class);
140-
$registry->unregister('isSecureArea');
141-
$registry->register('isSecureArea', true);
142-
/** @var Store $store */
143-
$store = $this->objectManager->get(Store::class);
144-
$store->load($this->storeCode, 'code');
145-
if ($store->getId()) {
102+
$store = $this->storeFactory->create();
103+
$store->load($storeId);
104+
if ($store !== null) {
146105
$store->delete();
147106
}
148-
$registry->unregister('isSecureArea');
149-
$registry->register('isSecureArea', false);
150107
}
151108
}

0 commit comments

Comments
 (0)