Skip to content

Commit 053ae32

Browse files
Keerthana81187Keerthana
authored andcommitted
[ACQE-4664] Integration test to check Db updation of Invisible product
1 parent 647b34e commit 053ae32

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
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;
1617
use Magento\CatalogImportExport\Model\Import\Product;
1718
use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteDatabaseMap;
1819
use Magento\Framework\App\Filesystem\DirectoryList;
1920
use Magento\Framework\Filesystem;
2021
use Magento\ImportExport\Model\Import;
2122
use Magento\ImportExport\Model\Import\Source\Csv;
2223
use Magento\Store\Model\ScopeInterface;
24+
use Magento\TestFramework\Fixture\DataFixture;
2325
use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
2426
use Magento\UrlRewrite\Model\OptionProvider;
2527
use Psr\Log\LoggerInterface;
@@ -140,6 +142,57 @@ public function productDataProvider(): array
140142
];
141143
}
142144

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','visibility' => Visibility::VISIBILITY_NOT_VISIBLE], 'p1'),
153+
]
154+
public function testUrlRewriteOnInvisibleProductEdit(array $expectedData): void
155+
{
156+
$product = $this->productRepository->get('simple', true, 0, true);
157+
$productUrlRewriteItems = $this->getEntityRewriteCollection($product->getId())->getItems();
158+
$this->assertEmpty($productUrlRewriteItems,'URL key should not be present for "Not visible individually" product');
159+
160+
//Update visibility and check the database entry
161+
$product->setVisibility(Visibility::VISIBILITY_BOTH);
162+
$product = $this->productRepository->save($product);
163+
164+
$productUrlRewriteCollection = $this->getEntityRewriteCollection($product->getId());
165+
$this->assertRewrites(
166+
$productUrlRewriteCollection,
167+
$this->prepareData($expectedData, (int)$product->getId())
168+
);
169+
170+
//Update visibility and check if the entry is removed from the database
171+
$product = $this->productRepository->get('simple', true, 0, true);
172+
$product->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE);
173+
$product = $this->productRepository->save($product);
174+
175+
$productUrlRewriteItems = $this->getEntityRewriteCollection($product->getId())->getItems();
176+
$this->assertEmpty($productUrlRewriteItems,'URL key should not be present for "Not visible individually" product');
177+
}
178+
179+
/**
180+
* @return array
181+
*/
182+
public function invisibleProductDataProvider(): array
183+
{
184+
return [
185+
[
186+
'expected_data' => [
187+
[
188+
'request_path' => 'simple-url-test-product%suffix%',
189+
'target_path' => 'catalog/product/view/id/%id%',
190+
],
191+
],
192+
],
193+
];
194+
}
195+
143196
/**
144197
* @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 1
145198
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_simple.php

0 commit comments

Comments
 (0)