feat: rejected-cookie cache exclusions for WooCommerce cart
Add wp_recache_rejected_cookies option (defaults: woocommerce_items_in_cart, wp_woocommerce_session_*, wp-postpass, comment_author_*, wordpress_*) that bypasses page cache when any listed cookie is present. Both the WP-level check (wp_recache_should_exclude) and the standalone drop-in apply the same exact/prefix matching logic. Editing the option regenerates the drop-in and purges all cache.
This commit is contained in:
@@ -88,6 +88,48 @@ class WP_Recache_Helpers_Test extends WP_UnitTestCase {
|
||||
$this->assertTrue(wp_recache_should_exclude());
|
||||
}
|
||||
|
||||
public function test_wp_recache_has_rejected_cookie_returns_true_for_exact_match() {
|
||||
wp_set_current_user(0);
|
||||
update_option('wp_recache_rejected_cookies', ['wp-postpass']);
|
||||
$_COOKIE = ['wp-postpass' => 'abc123'];
|
||||
$this->assertTrue(wp_recache_has_rejected_cookie());
|
||||
$_COOKIE = [];
|
||||
}
|
||||
|
||||
public function test_wp_recache_has_rejected_cookie_returns_true_for_prefix_match() {
|
||||
wp_set_current_user(0);
|
||||
update_option('wp_recache_rejected_cookies', ['comment_author_*']);
|
||||
$_COOKIE = ['comment_author_12345' => 'test'];
|
||||
$this->assertTrue(wp_recache_has_rejected_cookie());
|
||||
$_COOKIE = [];
|
||||
}
|
||||
|
||||
public function test_wp_recache_has_rejected_cookie_returns_false_when_no_match() {
|
||||
wp_set_current_user(0);
|
||||
update_option('wp_recache_rejected_cookies', ['wp-postpass']);
|
||||
$_COOKIE = ['unrelated_cookie' => 'value'];
|
||||
$this->assertFalse(wp_recache_has_rejected_cookie());
|
||||
$_COOKIE = [];
|
||||
}
|
||||
|
||||
public function test_wp_recache_has_rejected_cookie_returns_false_when_empty_cookies() {
|
||||
wp_set_current_user(0);
|
||||
update_option('wp_recache_rejected_cookies', ['wp-postpass']);
|
||||
$_COOKIE = [];
|
||||
$this->assertFalse(wp_recache_has_rejected_cookie());
|
||||
}
|
||||
|
||||
public function test_wp_recache_should_exclude_returns_true_for_rejected_cookie() {
|
||||
wp_set_current_user(0);
|
||||
update_option('wp_recache_rejected_cookies', ['woocommerce_items_in_cart']);
|
||||
$_COOKIE = ['woocommerce_items_in_cart' => 'yes'];
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
$_SERVER['REQUEST_URI'] = '/test-page/';
|
||||
unset($_SERVER['HTTP_USER_AGENT']);
|
||||
$this->assertTrue(wp_recache_should_exclude());
|
||||
$_COOKIE = [];
|
||||
}
|
||||
|
||||
public function test_wp_recache_delete_cache_removes_file() {
|
||||
$url = 'https://example.com/test-page/';
|
||||
$path = wp_recache_get_cache_path($url);
|
||||
|
||||
Reference in New Issue
Block a user