@@ -89,14 +89,15 @@ protected function setUp(): void
89
89
* Test category process rewrite url by changing the parent
90
90
*
91
91
* @return void
92
+ * @dataProvider getCategoryRewritesConfigProvider
92
93
*/
93
- public function testCategoryProcessUrlRewriteAfterMovingWithChangedParentId ()
94
+ public function testCategoryProcessUrlRewriteAfterMovingWithChangedParentId (bool $ isCatRewritesEnabled )
94
95
{
95
96
/** @var Observer|MockObject $observerMock */
96
97
$ observerMock = $ this ->createMock (Observer::class);
97
98
$ eventMock = $ this ->getMockBuilder (Event::class)
98
99
->disableOriginalConstructor ()
99
- ->setMethods (['getCategory ' ])
100
+ ->addMethods (['getCategory ' ])
100
101
->getMock ();
101
102
$ categoryMock = $ this ->createPartialMock (
102
103
Category::class,
@@ -108,17 +109,32 @@ public function testCategoryProcessUrlRewriteAfterMovingWithChangedParentId()
108
109
]
109
110
);
110
111
112
+ $ observerMock ->expects ($ this ->once ())->method ('getEvent ' )->willReturn ($ eventMock );
113
+ $ eventMock ->expects ($ this ->once ())->method ('getCategory ' )->willReturn ($ categoryMock );
111
114
$ categoryMock ->expects ($ this ->once ())->method ('dataHasChangedFor ' )->with ('parent_id ' )
112
115
->willReturn (true );
113
- $ eventMock ->expects ($ this ->once ())->method ('getCategory ' )->willReturn ($ categoryMock );
114
- $ observerMock ->expects ($ this ->once ())->method ('getEvent ' )->willReturn ($ eventMock );
115
116
$ this ->scopeConfigMock ->expects ($ this ->once ())->method ('isSetFlag ' )
116
117
->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
+
118
123
$ this ->categoryUrlRewriteGeneratorMock ->expects ($ this ->once ())->method ('generate ' )
119
124
->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
+ }
122
138
$ this ->databaseMapPoolMock ->expects ($ this ->exactly (2 ))->method ('resetMap ' )->willReturnSelf ();
123
139
124
140
$ this ->observer ->execute ($ observerMock );
@@ -135,7 +151,7 @@ public function testCategoryProcessUrlRewriteAfterMovingWithinNotChangedParent()
135
151
$ observerMock = $ this ->createMock (Observer::class);
136
152
$ eventMock = $ this ->getMockBuilder (Event::class)
137
153
->disableOriginalConstructor ()
138
- ->setMethods (['getCategory ' ])
154
+ ->addMethods (['getCategory ' ])
139
155
->getMock ();
140
156
$ categoryMock = $ this ->createPartialMock (Category::class, ['dataHasChangedFor ' ]);
141
157
$ observerMock ->expects ($ this ->once ())->method ('getEvent ' )->willReturn ($ eventMock );
@@ -145,4 +161,15 @@ public function testCategoryProcessUrlRewriteAfterMovingWithinNotChangedParent()
145
161
146
162
$ this ->observer ->execute ($ observerMock );
147
163
}
164
+
165
+ /**
166
+ * @return array
167
+ */
168
+ public function getCategoryRewritesConfigProvider (): array
169
+ {
170
+ return [
171
+ [true ],
172
+ [false ]
173
+ ];
174
+ }
148
175
}
0 commit comments