@@ -739,7 +739,7 @@ public function testNotVisibleOnDefaultStoreVisibleOnDefaultScope()
739
739
$ this ->productRepository ->save ($ product );
740
740
741
741
$ actualResults = $ this ->getActualResults ($ productFilter );
742
- $ this ->assertGreaterThanOrEqual (2 , $ actualResults );
742
+ $ this ->assertCount (2 , $ actualResults );
743
743
744
744
$ expected = [
745
745
[
@@ -761,4 +761,94 @@ public function testNotVisibleOnDefaultStoreVisibleOnDefaultScope()
761
761
$ this ->assertContains ($ row , $ actualResults );
762
762
}
763
763
}
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
+ }
764
854
}
0 commit comments