From 0801ca9a2b25257fbfdc36a3461fd9158f63bfc8 Mon Sep 17 00:00:00 2001 From: Rolly Bueno Date: Tue, 23 Sep 2025 21:58:25 +0800 Subject: [PATCH 1/2] Add test for post meta cache persistence after post update --- tests/phpunit/tests/post/updatePostCache.php | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/phpunit/tests/post/updatePostCache.php b/tests/phpunit/tests/post/updatePostCache.php index 9427ec6fbda58..03e29e543bf15 100644 --- a/tests/phpunit/tests/post/updatePostCache.php +++ b/tests/phpunit/tests/post/updatePostCache.php @@ -138,4 +138,41 @@ public function test_get_posts_caches_post_filter_is_always_raw() { 'The filter is not set to "raw"' ); } + + /** + * Test that post meta cache persists when post is updated. + * + * @ticket 63167 + */ + public function test_post_meta_cache_is_invalidated_after_post_update() { + // Create a post and assign meta. + $post_id = self::factory()->post->create(); + update_post_meta( $post_id, 'foo', 'bar' ); + + // Prime the cache by fetching meta. + $meta = get_post_meta( $post_id, 'foo', true ); + $this->assertSame( 'bar', $meta, 'Meta should return the stored value.' ); + + // Confirm that meta is cached. + $cache_key = (string) $post_id; + $cache = wp_cache_get( $cache_key, 'post_meta' ); + $this->assertNotEmpty( $cache, 'Meta cache should be primed.' ); + $this->assertSame( 'bar', $cache['foo'][0], 'Cached value should match.' ); + + // Update the post (this should trigger clean_post_cache()). + wp_update_post( + array( + 'ID' => $post_id, + 'post_title' => 'Updated title', + ) + ); + + // After update, the post_meta cache should persist. + $cache_after = wp_cache_get( $cache_key, 'post_meta' ); + $this->assertNotEmpty( $cache_after, 'Meta cache should persist after post update.' ); + + // Meta should still be accessible after post update. + $meta_after = get_post_meta( $post_id, 'foo', true ); + $this->assertSame( 'bar', $meta_after, 'Meta value should still persist after post update.' ); + } } From effa81ee6a2af29c471e3b05d025a941b4ed10e8 Mon Sep 17 00:00:00 2001 From: Rolly Bueno Date: Tue, 23 Sep 2025 22:58:09 +0800 Subject: [PATCH 2/2] Fix: Assert value --- tests/phpunit/tests/post/updatePostCache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/post/updatePostCache.php b/tests/phpunit/tests/post/updatePostCache.php index 03e29e543bf15..286bd3a74b54d 100644 --- a/tests/phpunit/tests/post/updatePostCache.php +++ b/tests/phpunit/tests/post/updatePostCache.php @@ -173,6 +173,6 @@ public function test_post_meta_cache_is_invalidated_after_post_update() { // Meta should still be accessible after post update. $meta_after = get_post_meta( $post_id, 'foo', true ); - $this->assertSame( 'bar', $meta_after, 'Meta value should still persist after post update.' ); + $this->assertSame( 'bar', $meta_after, 'Meta value should still persist after cache invalidation.' ); } }