@@ -166,6 +166,47 @@ public function testClearCacheOnProductVariationUpdate()
166166 $ this ->createSubscriber ('https://foo.com ' , '' , false , ['invalidation_enabled ' => true ], $ pageCacheClient )->clearCacheOnProductVariationUpdate (456 , $ variation );
167167 }
168168
169+ public function testClearCacheOnProductVariationUpdateFallsBackToVariationPostParentId ()
170+ {
171+ $ function_exists = $ this ->getFunctionMock ($ this ->getNamespace (WooCommerceSubscriber::class), 'function_exists ' );
172+ $ function_exists ->expects ($ this ->once ())
173+ ->with ('wc_get_page_permalink ' )
174+ ->willReturn (true );
175+
176+ $ wp_get_post_parent_id = $ this ->getFunctionMock ($ this ->getNamespace (WooCommerceSubscriber::class), 'wp_get_post_parent_id ' );
177+ $ wp_get_post_parent_id ->expects ($ this ->once ())
178+ ->with (456 )
179+ ->willReturn (123 );
180+
181+ $ get_permalink = $ this ->getFunctionMock ($ this ->getNamespace (WooCommerceSubscriber::class), 'get_permalink ' );
182+ $ get_permalink ->expects ($ this ->once ())
183+ ->with (123 )
184+ ->willReturn ('https://foo.com/product/bar/ ' );
185+
186+ $ wc_get_page_permalink = $ this ->getFunctionMock ($ this ->getNamespace (WooCommerceSubscriber::class), 'wc_get_page_permalink ' );
187+ $ wc_get_page_permalink ->expects ($ this ->once ())
188+ ->with ('shop ' )
189+ ->willReturn ('https://foo.com/shop/ ' );
190+
191+ $ get_the_terms = $ this ->getFunctionMock ($ this ->getNamespace (WooCommerceSubscriber::class), 'get_the_terms ' );
192+ $ get_the_terms ->expects ($ this ->exactly (2 ))
193+ ->willReturn ([]);
194+
195+ $ pageCacheClient = $ this ->getContentDeliveryNetworkPageCacheClientInterfaceMock ();
196+ $ pageCacheClient ->expects ($ this ->once ())
197+ ->method ('clearUrls ' )
198+ ->with ($ this ->callback (function ($ urls ) {
199+ $ this ->assertSame ([
200+ 'https://foo.com/product/bar/ ' ,
201+ 'https://foo.com/shop/* ' ,
202+ ], $ urls ->all ());
203+
204+ return true ;
205+ }));
206+
207+ $ this ->createSubscriber ('https://foo.com ' , '' , false , ['invalidation_enabled ' => true ], $ pageCacheClient )->clearCacheOnProductVariationUpdate (456 , new \stdClass ());
208+ }
209+
169210 public function testDisableCheckImportFilePath ()
170211 {
171212 $ this ->assertFalse ($ this ->createSubscriber ()->disableCheckImportFilePath ());
0 commit comments