Skip to content

Commit 1174636

Browse files
committed
ACP2E-2629: add integration test
1 parent 2f0db6f commit 1174636

File tree

2 files changed

+103
-11
lines changed

2 files changed

+103
-11
lines changed

app/code/Magento/CatalogUrlRewrite/Model/ProductScopeRewriteGenerator.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,18 @@ public function generateForGlobalScope($productCategories, Product $product, $ro
182182
);
183183
}
184184
} else {
185-
$scopedProduct = $this->productRepository->getById($productId, false, $id);
186-
$mergeDataProvider->merge(
187-
$this->generateForSpecificStoreView(
188-
$id,
189-
$productCategories,
190-
$scopedProduct,
191-
$rootCategoryId,
192-
true
193-
)
194-
);
185+
if (count($visibleForStores) == 0 || in_array((int)$id, $visibleForStores)) {
186+
$scopedProduct = $this->productRepository->getById($productId, false, $id);
187+
$mergeDataProvider->merge(
188+
$this->generateForSpecificStoreView(
189+
$id,
190+
$productCategories,
191+
$scopedProduct,
192+
$rootCategoryId,
193+
true
194+
)
195+
);
196+
}
195197
}
196198
}
197199
}

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserverTest.php

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ public function testNotVisibleOnDefaultStoreVisibleOnDefaultScope()
739739
$this->productRepository->save($product);
740740

741741
$actualResults = $this->getActualResults($productFilter);
742-
$this->assertGreaterThanOrEqual(2, $actualResults);
742+
$this->assertCount(2, $actualResults);
743743

744744
$expected = [
745745
[
@@ -761,4 +761,94 @@ public function testNotVisibleOnDefaultStoreVisibleOnDefaultScope()
761761
$this->assertContains($row, $actualResults);
762762
}
763763
}
764+
765+
#[
766+
DataFixture(StoreFixture::class, ['group_id' => 1, 'website_id' => 1], as: 'store2'),
767+
DataFixture(CategoryFixture::class, as: 'category'),
768+
DataFixture(ProductFixture::class, ['category_ids' => ['$category.id$']], as: 'product')
769+
]
770+
public function testUrlRewriteGenerationBasedOnScopeVisibility() {
771+
$secondStore = $this->fixtures->get('store2');
772+
$category = $this->fixtures->get('category');
773+
$product = $this->fixtures->get('product');
774+
775+
$productFilter = [
776+
UrlRewrite::ENTITY_TYPE => 'product',
777+
'entity_id' => $product->getId(),
778+
'store_id' => [1, $secondStore->getId()]
779+
];
780+
781+
$actualResults = $this->getActualResults($productFilter);
782+
$this->assertCount(4, $actualResults);
783+
784+
$productScopeStore1 = $this->productRepository->get($product->getSku(), true, 1);
785+
$productScopeStore1->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE);
786+
$this->productRepository->save($productScopeStore1);
787+
788+
$actualResults = $this->getActualResults($productFilter);
789+
$this->assertCount(2, $actualResults);
790+
791+
$productGlobal = $this->productRepository->get($product->getSku(), true, Store::DEFAULT_STORE_ID);
792+
$productGlobal->setVisibility(Visibility::VISIBILITY_IN_CATALOG);
793+
$this->productRepository->save($productGlobal);
794+
795+
$actualResults = $this->getActualResults($productFilter);
796+
$this->assertCount(2, $actualResults);
797+
798+
$expected = [
799+
[
800+
'request_path' => $product->getUrlKey() . '.html',
801+
'target_path' => 'catalog/product/view/id/' . $product->getId(),
802+
'is_auto_generated' => 1,
803+
'redirect_type' => 0,
804+
'store_id' => $secondStore->getId(),
805+
],
806+
[
807+
'request_path' => $category->getUrlKey() . '/' . $product->getUrlKey() . '.html',
808+
'target_path' => 'catalog/product/view/id/' . $product->getId() . '/category/' . $category->getId(),
809+
'is_auto_generated' => 1,
810+
'redirect_type' => 0,
811+
'store_id' => $secondStore->getId(),
812+
]
813+
];
814+
815+
$unexpected = [
816+
[
817+
'request_path' => $product->getUrlKey() . '.html',
818+
'target_path' => 'catalog/product/view/id/' . $product->getId(),
819+
'is_auto_generated' => 1,
820+
'redirect_type' => 0,
821+
'store_id' => 1 //not expected url rewrite for store 1
822+
],
823+
[
824+
'request_path' => $category->getUrlKey() . '/' . $product->getUrlKey() . '.html',
825+
'target_path' => 'catalog/product/view/id/' . $product->getId() . '/category/' . $category->getId(),
826+
'is_auto_generated' => 1,
827+
'redirect_type' => 0,
828+
'store_id' => 1,
829+
],
830+
[
831+
'request_path' => '/'.$product->getUrlKey() . '.html',// not expected anchor root category url rewrite
832+
'target_path' => 'catalog/product/view/id/' . $product->getId(),
833+
'is_auto_generated' => 1,
834+
'redirect_type' => 0,
835+
'store_id' => $secondStore->getId(),
836+
],
837+
[
838+
'request_path' => '/'.$product->getUrlKey() . '.html',// not expected anchor root category url rewrite
839+
'target_path' => 'catalog/product/view/id/' . $product->getId(),
840+
'is_auto_generated' => 1,
841+
'redirect_type' => 0,
842+
'store_id' => 1,
843+
]
844+
];
845+
846+
foreach ($expected as $row) {
847+
$this->assertContains($row, $actualResults);
848+
}
849+
850+
foreach ($unexpected as $row) {
851+
$this->assertNotContains($row, $actualResults);
852+
}
853+
}
764854
}

0 commit comments

Comments
 (0)