Skip to content

Commit 49854fe

Browse files
committed
MC-22032: Storefront: Product URL Management
1 parent 81815e7 commit 49854fe

File tree

3 files changed

+14
-32
lines changed

3 files changed

+14
-32
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/ProductUrlRewriteTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Catalog\Api\CategoryRepositoryInterface;
1111
use Magento\Catalog\Api\Data\ProductInterface;
1212
use Magento\Catalog\Api\ProductRepositoryInterface;
13-
use Magento\Catalog\Model\AbstractModel;
1413
use Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator;
1514
use Magento\Framework\App\Config\ScopeConfigInterface;
1615
use Magento\Framework\Registry;
@@ -71,7 +70,7 @@ protected function setUp()
7170
public function testProductUrlRewrite(): void
7271
{
7372
$product = $this->productRepository->get('simple2');
74-
$url = $this->prepareUrl($product);
73+
$url = $this->prepareUrl($product->getUrlKey());
7574
$this->dispatch($url);
7675

7776
$this->assertProductIsVisible($product);
@@ -85,7 +84,7 @@ public function testCategoryProductUrlRewrite(): void
8584
{
8685
$category = $this->categoryRepository->get(333);
8786
$product = $this->productRepository->get('simple333');
88-
$url = $this->prepareUrl($category, false) . $this->prepareUrl($product);
87+
$url = $this->prepareUrl($category->getUrlKey(), false) . $this->prepareUrl($product->getUrlKey());
8988
$this->dispatch($url);
9089

9190
$this->assertProductIsVisible($product);
@@ -98,35 +97,36 @@ public function testCategoryProductUrlRewrite(): void
9897
public function testProductRedirect(): void
9998
{
10099
$product = $this->productRepository->get('simple2');
101-
$oldUrl = $this->prepareUrl($product);
100+
$oldUrl = $this->prepareUrl($product->getUrlKey());
102101
$data = [
103102
'url_key' => 'new-url-key',
104103
'url_key_create_redirect' => $product->getUrlKey(),
105104
'save_rewrites_history' => true,
106105
];
107-
$this->updateProduct($product, $data);
106+
$this->saveProductWithAdditionalData($product, $data);
108107
$this->dispatch($oldUrl);
109108

110109
$this->assertRedirect($this->stringContains('new-url-key' . $this->urlSuffix));
111110
}
112111

113112
/**
114113
* @magentoDbIsolation disabled
115-
* @magentoDataFixture Magento/Catalog/_files/product_with_two_stores.php
114+
* @magentoDataFixture Magento/Store/_files/core_fixturestore.php
115+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
116116
* @return void
117117
*/
118118
public function testMultistoreProductUrlRewrite(): void
119119
{
120120
$currentStore = $this->storeManager->getStore();
121121
$product = $this->productRepository->get('simple2');
122-
$firstStoreUrl = $this->prepareUrl($product);
122+
$firstStoreUrl = $this->prepareUrl($product->getUrlKey());
123123
$secondStoreId = $this->storeManager->getStore('fixturestore')->getId();
124124
$this->storeManager->setCurrentStore($secondStoreId);
125125

126126
try {
127-
$product = $this->updateProduct($product, ['url_key' => 'second-store-url-key']);
127+
$product = $this->saveProductWithAdditionalData($product, ['url_key' => 'second-store-url-key']);
128128
$this->assertEquals('second-store-url-key', $product->getUrlKey());
129-
$secondStoreUrl = $this->prepareUrl($product);
129+
$secondStoreUrl = $this->prepareUrl($product->getUrlKey());
130130

131131
$this->dispatch($secondStoreUrl);
132132
$this->assertProductIsVisible($product);
@@ -146,15 +146,15 @@ public function testMultistoreProductUrlRewrite(): void
146146
* @param array $data
147147
* @return ProductInterface
148148
*/
149-
private function updateProduct(ProductInterface $product, array $data): ProductInterface
149+
private function saveProductWithAdditionalData(ProductInterface $product, array $data): ProductInterface
150150
{
151151
$product->addData($data);
152152

153153
return $this->productRepository->save($product);
154154
}
155155

156156
/**
157-
* Clear request object.
157+
* Clean up cached objects
158158
*
159159
* @return void
160160
*/
@@ -171,13 +171,13 @@ private function cleanUpCachedObjects(): void
171171
/**
172172
* Prepare url to dispatch
173173
*
174-
* @param AbstractModel $object
174+
* @param string $urlKey
175175
* @param bool $addSuffix
176176
* @return string
177177
*/
178-
private function prepareUrl(AbstractModel $object, bool $addSuffix = true): string
178+
private function prepareUrl(string $urlKey, bool $addSuffix = true): string
179179
{
180-
$url = $addSuffix ? '/' . $object->getUrlKey() . $this->urlSuffix : '/' . $object->getUrlKey();
180+
$url = $addSuffix ? '/' . $urlKey . $this->urlSuffix : '/' . $urlKey;
181181

182182
return $url;
183183
}

dev/tests/integration/testsuite/Magento/Catalog/_files/product_with_two_stores.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

dev/tests/integration/testsuite/Magento/Catalog/_files/product_with_two_stores_rollback.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)