Skip to content

Commit a1318e1

Browse files
[ACQE-4664] Integration testing to check url rewrite table for invisible product update
1 parent a3a8256 commit a1318e1

File tree

2 files changed

+124
-60
lines changed

2 files changed

+124
-60
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\CatalogUrlRewrite\Model\AbstractUrlRewriteTest;
10+
use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteDatabaseMap;
11+
use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator;
12+
use Magento\Store\Model\ScopeInterface;
13+
use Magento\TestFramework\Fixture\DataFixture;
14+
use Magento\Catalog\Model\Product\Visibility;
15+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
16+
17+
/**
18+
* Class for product url rewrites tests
19+
*
20+
*/
21+
class ProductUrlRewriteDataTest extends AbstractUrlRewriteTest
22+
{
23+
24+
/** @var string */
25+
private $suffix;
26+
27+
/** @var ProductRepositoryInterface */
28+
private $productRepository;
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
protected function setUp(): void
34+
{
35+
parent::setUp();
36+
37+
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
38+
$this->suffix = $this->config->getValue(
39+
ProductUrlPathGenerator::XML_PATH_PRODUCT_URL_SUFFIX,
40+
ScopeInterface::SCOPE_STORE
41+
);
42+
}
43+
44+
/**
45+
* @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 1
46+
* @dataProvider invisibleProductDataProvider
47+
* @param array $expectedData
48+
* @return void
49+
*/
50+
#[
51+
DataFixture(ProductFixture::class, ['sku' => 'simple', 'name' => 'Simple Url Test Product',
52+
'visibility' => Visibility::VISIBILITY_NOT_VISIBLE]),
53+
]
54+
public function testUrlRewriteOnInvisibleProductEdit(array $expectedData): void
55+
{
56+
$product = $this->productRepository->get('simple', true, 0, true);
57+
$this->assertUrlKeyEmpty($product);
58+
59+
//Update visibility and check the database entry
60+
$product->setVisibility(Visibility::VISIBILITY_BOTH);
61+
$product = $this->productRepository->save($product);
62+
63+
$productUrlRewriteCollection = $this->getEntityRewriteCollection($product->getId());
64+
$this->assertRewrites(
65+
$productUrlRewriteCollection,
66+
$this->prepareData($expectedData, (int)$product->getId())
67+
);
68+
69+
//Update visibility and check if the entry is removed from the database
70+
$product = $this->productRepository->get('simple', true, 0, true);
71+
$product->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE);
72+
$product = $this->productRepository->save($product);
73+
74+
$this->assertUrlKeyEmpty($product);
75+
}
76+
77+
/**
78+
* @return array
79+
*/
80+
public function invisibleProductDataProvider(): array
81+
{
82+
return [
83+
[
84+
'expected_data' => [
85+
[
86+
'request_path' => 'simple-url-test-product%suffix%',
87+
'target_path' => 'catalog/product/view/id/%id%',
88+
],
89+
],
90+
],
91+
];
92+
}
93+
94+
/**
95+
* Assert URL key is empty in database for the given product
96+
*
97+
* @param $product
98+
* @return void
99+
*/
100+
public function assertUrlKeyEmpty($product): void
101+
{
102+
$productUrlRewriteItems = $this->getEntityRewriteCollection($product->getId())->getItems();
103+
$this->assertEmpty(
104+
$productUrlRewriteItems,
105+
'Failed asserting URL key is empty for the given product'
106+
);
107+
}
108+
109+
/**
110+
* @inheritdoc
111+
*/
112+
protected function getUrlSuffix(): string
113+
{
114+
return $this->suffix;
115+
}
116+
117+
/**
118+
* @inheritdoc
119+
*/
120+
protected function getEntityType(): string
121+
{
122+
return DataProductUrlRewriteDatabaseMap::ENTITY_TYPE;
123+
}
124+
}

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/ProductUrlRewriteTest.php

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
use Magento\Catalog\Model\Product\Visibility;
1414
use Magento\Catalog\Model\ProductFactory;
1515
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
16-
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
1716
use Magento\CatalogImportExport\Model\Import\Product;
1817
use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteDatabaseMap;
1918
use Magento\Framework\App\Filesystem\DirectoryList;
2019
use Magento\Framework\Filesystem;
2120
use Magento\ImportExport\Model\Import;
2221
use Magento\ImportExport\Model\Import\Source\Csv;
2322
use Magento\Store\Model\ScopeInterface;
24-
use Magento\TestFramework\Fixture\DataFixture;
2523
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
2624
use Magento\UrlRewrite\Model\OptionProvider;
2725
use Psr\Log\LoggerInterface;
@@ -142,64 +140,6 @@ public function productDataProvider(): array
142140
];
143141
}
144142

145-
/**
146-
* @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 1
147-
* @dataProvider invisibleProductDataProvider
148-
* @param array $expectedData
149-
* @return void
150-
*/
151-
#[
152-
DataFixture(ProductFixture::class, ['sku' => 'simple','name'=>'Simple Url Test Product',
153-
'visibility' => Visibility::VISIBILITY_NOT_VISIBLE]),
154-
]
155-
public function testUrlRewriteOnInvisibleProductEdit(array $expectedData): void
156-
{
157-
$product = $this->productRepository->get('simple', true, 0, true);
158-
$productUrlRewriteItems = $this->getEntityRewriteCollection($product->getId())->getItems();
159-
$this->assertEmpty(
160-
$productUrlRewriteItems,
161-
'URL key should not be present for "Not visible individually" product'
162-
);
163-
164-
//Update visibility and check the database entry
165-
$product->setVisibility(Visibility::VISIBILITY_BOTH);
166-
$product = $this->productRepository->save($product);
167-
168-
$productUrlRewriteCollection = $this->getEntityRewriteCollection($product->getId());
169-
$this->assertRewrites(
170-
$productUrlRewriteCollection,
171-
$this->prepareData($expectedData, (int)$product->getId())
172-
);
173-
174-
//Update visibility and check if the entry is removed from the database
175-
$product = $this->productRepository->get('simple', true, 0, true);
176-
$product->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE);
177-
$product = $this->productRepository->save($product);
178-
179-
$productUrlRewriteItems = $this->getEntityRewriteCollection($product->getId())->getItems();
180-
$this->assertEmpty(
181-
$productUrlRewriteItems,
182-
'URL key should not be present for "Not visible individually" product'
183-
);
184-
}
185-
186-
/**
187-
* @return array
188-
*/
189-
public function invisibleProductDataProvider(): array
190-
{
191-
return [
192-
[
193-
'expected_data' => [
194-
[
195-
'request_path' => 'simple-url-test-product%suffix%',
196-
'target_path' => 'catalog/product/view/id/%id%',
197-
],
198-
],
199-
],
200-
];
201-
}
202-
203143
/**
204144
* @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 1
205145
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_simple.php

0 commit comments

Comments
 (0)