55
66use Automattic \WooCommerce \StoreApi \Utilities \ProductQuery ;
77use Automattic \WooCommerce \Tests \Blocks \Helpers \FixtureData ;
8- use Yoast \PHPUnitPolyfills \TestCases \TestCase ;
98
109/**
1110 * Unit tests for the ProductQuery::get_last_modified() caching behavior.
1211 */
13- class ProductQueryTest extends TestCase {
12+ class ProductQueryTest extends \WC_Unit_Test_Case {
1413
1514 /**
1615 * @var ProductQuery
@@ -20,7 +19,7 @@ class ProductQueryTest extends TestCase {
2019 /**
2120 * Setup test data. Called before every test.
2221 */
23- protected function setUp (): void {
22+ public function setUp (): void {
2423 parent ::setUp ();
2524 $ this ->product_query = new ProductQuery ();
2625 wp_cache_delete ( 'last_modified ' , 'wc_products ' );
@@ -29,7 +28,7 @@ protected function setUp(): void {
2928 /**
3029 * @testdox get_last_modified returns null when no products exist.
3130 */
32- public function test_get_last_modified_returns_null_when_no_products () {
31+ public function test_get_last_modified_returns_null_when_no_products (): void {
3332 global $ wpdb ;
3433
3534 // Temporarily remove all product posts to test the null case.
@@ -58,9 +57,14 @@ public function test_get_last_modified_returns_null_when_no_products() {
5857 /**
5958 * @testdox get_last_modified returns an HTTP-date formatted string.
6059 */
61- public function test_get_last_modified_returns_http_date_format () {
60+ public function test_get_last_modified_returns_http_date_format (): void {
6261 $ fixtures = new FixtureData ();
63- $ fixtures ->get_simple_product ( array ( 'name ' => 'Test Product ' , 'regular_price ' => 10 ) );
62+ $ fixtures ->get_simple_product (
63+ array (
64+ 'name ' => 'Test Product ' ,
65+ 'regular_price ' => 10 ,
66+ )
67+ );
6468
6569 $ result = $ this ->product_query ->get_last_modified ();
6670
@@ -73,9 +77,14 @@ public function test_get_last_modified_returns_http_date_format() {
7377 /**
7478 * @testdox get_last_modified caches the result in the object cache.
7579 */
76- public function test_get_last_modified_caches_result () {
80+ public function test_get_last_modified_caches_result (): void {
7781 $ fixtures = new FixtureData ();
78- $ fixtures ->get_simple_product ( array ( 'name ' => 'Test Product ' , 'regular_price ' => 10 ) );
82+ $ fixtures ->get_simple_product (
83+ array (
84+ 'name ' => 'Test Product ' ,
85+ 'regular_price ' => 10 ,
86+ )
87+ );
7988
8089 // First call seeds the cache.
8190 $ result = $ this ->product_query ->get_last_modified ();
@@ -89,7 +98,7 @@ public function test_get_last_modified_caches_result() {
8998 /**
9099 * @testdox get_last_modified returns cached value without querying the database.
91100 */
92- public function test_get_last_modified_uses_cached_value () {
101+ public function test_get_last_modified_uses_cached_value (): void {
93102 $ sentinel = 'Thu, 01 Jan 2099 00:00:00 GMT ' ;
94103 wp_cache_set ( 'last_modified ' , $ sentinel , 'wc_products ' );
95104
@@ -101,9 +110,14 @@ public function test_get_last_modified_uses_cached_value() {
101110 /**
102111 * @testdox Cache is invalidated when a product post cache is cleaned.
103112 */
104- public function test_cache_invalidated_on_product_change () {
113+ public function test_cache_invalidated_on_product_change (): void {
105114 $ fixtures = new FixtureData ();
106- $ product = $ fixtures ->get_simple_product ( array ( 'name ' => 'Test Product ' , 'regular_price ' => 10 ) );
115+ $ product = $ fixtures ->get_simple_product (
116+ array (
117+ 'name ' => 'Test Product ' ,
118+ 'regular_price ' => 10 ,
119+ )
120+ );
107121
108122 // Seed the cache.
109123 $ this ->product_query ->get_last_modified ();
@@ -118,9 +132,14 @@ public function test_cache_invalidated_on_product_change() {
118132 /**
119133 * @testdox Cache is invalidated when a product variation post cache is cleaned.
120134 */
121- public function test_cache_invalidated_on_variation_change () {
135+ public function test_cache_invalidated_on_variation_change (): void {
122136 $ fixtures = new FixtureData ();
123- $ product = $ fixtures ->get_simple_product ( array ( 'name ' => 'Test Product ' , 'regular_price ' => 10 ) );
137+ $ product = $ fixtures ->get_simple_product (
138+ array (
139+ 'name ' => 'Test Product ' ,
140+ 'regular_price ' => 10 ,
141+ )
142+ );
124143
125144 // Create a variation post directly to avoid complex variable product setup.
126145 $ variation_id = wp_insert_post (
@@ -144,17 +163,28 @@ public function test_cache_invalidated_on_variation_change() {
144163 /**
145164 * @testdox Cache is NOT invalidated when a non-product post cache is cleaned.
146165 */
147- public function test_cache_not_invalidated_on_non_product_change () {
166+ public function test_cache_not_invalidated_on_non_product_change (): void {
148167 $ fixtures = new FixtureData ();
149- $ fixtures ->get_simple_product ( array ( 'name ' => 'Test Product ' , 'regular_price ' => 10 ) );
168+ $ fixtures ->get_simple_product (
169+ array (
170+ 'name ' => 'Test Product ' ,
171+ 'regular_price ' => 10 ,
172+ )
173+ );
150174
151175 // Seed the cache.
152176 $ this ->product_query ->get_last_modified ();
153177 $ cached_value = wp_cache_get ( 'last_modified ' , 'wc_products ' );
154178 $ this ->assertNotFalse ( $ cached_value );
155179
156180 // Create and clean a regular post.
157- $ post_id = wp_insert_post ( array ( 'post_title ' => 'Regular Post ' , 'post_type ' => 'post ' , 'post_status ' => 'publish ' ) );
181+ $ post_id = wp_insert_post (
182+ array (
183+ 'post_title ' => 'Regular Post ' ,
184+ 'post_type ' => 'post ' ,
185+ 'post_status ' => 'publish ' ,
186+ )
187+ );
158188 clean_post_cache ( $ post_id );
159189
160190 $ this ->assertSame ( $ cached_value , wp_cache_get ( 'last_modified ' , 'wc_products ' ) );
@@ -163,9 +193,14 @@ public function test_cache_not_invalidated_on_non_product_change() {
163193 /**
164194 * @testdox get_last_modified re-seeds cache from DB after invalidation.
165195 */
166- public function test_get_last_modified_reseeds_after_invalidation () {
196+ public function test_get_last_modified_reseeds_after_invalidation (): void {
167197 $ fixtures = new FixtureData ();
168- $ product = $ fixtures ->get_simple_product ( array ( 'name ' => 'Test Product ' , 'regular_price ' => 10 ) );
198+ $ product = $ fixtures ->get_simple_product (
199+ array (
200+ 'name ' => 'Test Product ' ,
201+ 'regular_price ' => 10 ,
202+ )
203+ );
169204
170205 // Seed the cache.
171206 $ first_result = $ this ->product_query ->get_last_modified ();
@@ -179,4 +214,4 @@ public function test_get_last_modified_reseeds_after_invalidation() {
179214 $ this ->assertNotNull ( $ second_result );
180215 $ this ->assertNotFalse ( wp_cache_get ( 'last_modified ' , 'wc_products ' ) );
181216 }
182- }
217+ }
0 commit comments