|
13 | 13 | use Magento\Catalog\Model\Product\Visibility;
|
14 | 14 | use Magento\Catalog\Model\ProductFactory;
|
15 | 15 | use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
|
| 16 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
16 | 17 | use Magento\CatalogImportExport\Model\Import\Product;
|
17 | 18 | use Magento\CatalogUrlRewrite\Model\Map\DataProductUrlRewriteDatabaseMap;
|
18 | 19 | use Magento\Framework\App\Filesystem\DirectoryList;
|
19 | 20 | use Magento\Framework\Filesystem;
|
20 | 21 | use Magento\ImportExport\Model\Import;
|
21 | 22 | use Magento\ImportExport\Model\Import\Source\Csv;
|
22 | 23 | use Magento\Store\Model\ScopeInterface;
|
| 24 | +use Magento\TestFramework\Fixture\DataFixture; |
23 | 25 | use Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException;
|
24 | 26 | use Magento\UrlRewrite\Model\OptionProvider;
|
25 | 27 | use Psr\Log\LoggerInterface;
|
@@ -140,6 +142,57 @@ public function productDataProvider(): array
|
140 | 142 | ];
|
141 | 143 | }
|
142 | 144 |
|
| 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 | + |
143 | 196 | /**
|
144 | 197 | * @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 1
|
145 | 198 | * @magentoDataFixture Magento/CatalogUrlRewrite/_files/product_simple.php
|
|
0 commit comments