@@ -89,14 +89,15 @@ protected function setUp(): void
8989 * Test category process rewrite url by changing the parent
9090 *
9191 * @return void
92+ * @dataProvider getCategoryRewritesConfigProvider
9293 */
93- public function testCategoryProcessUrlRewriteAfterMovingWithChangedParentId ()
94+ public function testCategoryProcessUrlRewriteAfterMovingWithChangedParentId (bool $ isCatRewritesEnabled )
9495 {
9596 /** @var Observer|MockObject $observerMock */
9697 $ observerMock = $ this ->createMock (Observer::class);
9798 $ eventMock = $ this ->getMockBuilder (Event::class)
9899 ->disableOriginalConstructor ()
99- ->setMethods (['getCategory ' ])
100+ ->addMethods (['getCategory ' ])
100101 ->getMock ();
101102 $ categoryMock = $ this ->createPartialMock (
102103 Category::class,
@@ -108,17 +109,32 @@ public function testCategoryProcessUrlRewriteAfterMovingWithChangedParentId()
108109 ]
109110 );
110111
112+ $ observerMock ->expects ($ this ->once ())->method ('getEvent ' )->willReturn ($ eventMock );
113+ $ eventMock ->expects ($ this ->once ())->method ('getCategory ' )->willReturn ($ categoryMock );
111114 $ categoryMock ->expects ($ this ->once ())->method ('dataHasChangedFor ' )->with ('parent_id ' )
112115 ->willReturn (true );
113- $ eventMock ->expects ($ this ->once ())->method ('getCategory ' )->willReturn ($ categoryMock );
114- $ observerMock ->expects ($ this ->once ())->method ('getEvent ' )->willReturn ($ eventMock );
115116 $ this ->scopeConfigMock ->expects ($ this ->once ())->method ('isSetFlag ' )
116117 ->with (UrlKeyRenderer::XML_PATH_SEO_SAVE_HISTORY )->willReturn (true );
117- $ this ->scopeConfigMock ->method ('getValue ' )->willReturn (true );
118+ $ this ->scopeConfigMock ->expects ($ this ->once ())
119+ ->method ('getValue ' )
120+ ->with ('catalog/seo/generate_category_product_rewrites ' )
121+ ->willReturn ($ isCatRewritesEnabled );
122+
118123 $ this ->categoryUrlRewriteGeneratorMock ->expects ($ this ->once ())->method ('generate ' )
119124 ->with ($ categoryMock , true )->willReturn (['category-url-rewrite ' ]);
120- $ this ->urlRewriteHandlerMock ->expects ($ this ->once ())->method ('generateProductUrlRewrites ' )
121- ->with ($ categoryMock )->willReturn (['product-url-rewrite ' ]);
125+
126+ if ($ isCatRewritesEnabled ) {
127+ $ this ->urlRewriteHandlerMock ->expects ($ this ->once ())
128+ ->id ('generateProductUrlRewrites ' )
129+ ->method ('generateProductUrlRewrites ' )
130+ ->with ($ categoryMock )->willReturn (['product-url-rewrite ' ]);
131+ $ this ->urlRewriteHandlerMock ->expects ($ this ->once ())
132+ ->method ('deleteCategoryRewritesForChildren ' )
133+ ->after ('generateProductUrlRewrites ' );
134+ } else {
135+ $ this ->urlRewriteHandlerMock ->expects ($ this ->once ())
136+ ->method ('deleteCategoryRewritesForChildren ' );
137+ }
122138 $ this ->databaseMapPoolMock ->expects ($ this ->exactly (2 ))->method ('resetMap ' )->willReturnSelf ();
123139
124140 $ this ->observer ->execute ($ observerMock );
@@ -135,7 +151,7 @@ public function testCategoryProcessUrlRewriteAfterMovingWithinNotChangedParent()
135151 $ observerMock = $ this ->createMock (Observer::class);
136152 $ eventMock = $ this ->getMockBuilder (Event::class)
137153 ->disableOriginalConstructor ()
138- ->setMethods (['getCategory ' ])
154+ ->addMethods (['getCategory ' ])
139155 ->getMock ();
140156 $ categoryMock = $ this ->createPartialMock (Category::class, ['dataHasChangedFor ' ]);
141157 $ observerMock ->expects ($ this ->once ())->method ('getEvent ' )->willReturn ($ eventMock );
@@ -145,4 +161,15 @@ public function testCategoryProcessUrlRewriteAfterMovingWithinNotChangedParent()
145161
146162 $ this ->observer ->execute ($ observerMock );
147163 }
164+
165+ /**
166+ * @return array
167+ */
168+ public function getCategoryRewritesConfigProvider (): array
169+ {
170+ return [
171+ [true ],
172+ [false ]
173+ ];
174+ }
148175}
0 commit comments