From 8035b6eb85e0687fc3471818c420028658b4f6ac Mon Sep 17 00:00:00 2001 From: Igor Rozum Date: Mon, 5 Oct 2026 11:20:59 -0400 Subject: [PATCH] Posts, Post Types: Add unit tests for get_posts() filter suppression --- tests/phpunit/tests/post/getPosts.php | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/phpunit/tests/post/getPosts.php b/tests/phpunit/tests/post/getPosts.php index 927e874f2f612..953e3ec3f5733 100644 --- a/tests/phpunit/tests/post/getPosts.php +++ b/tests/phpunit/tests/post/getPosts.php @@ -5,6 +5,8 @@ * @group query */ class Tests_Post_GetPosts extends WP_UnitTestCase { + private $posts_where_filter_fired = false; + public function test_offset_should_be_null_by_default() { $p1 = self::factory()->post->create( array( @@ -215,4 +217,35 @@ public function test_should_return_parent_ids_keyed_by_post_id_when_cached(): vo $this->assertSame( $expected, get_posts( $args ), 'The uncached call is not of the expected form.' ); $this->assertSame( $expected, get_posts( $args ), 'The cached call is not of the expected form.' ); } + + /** + * @ticket 7326 + */ + public function test_should_suppress_posts_where_filter_by_default() { + self::factory()->post->create(); + + add_filter( 'posts_where', array( $this, 'filter_posts_where_set_flag' ) ); + get_posts(); + remove_filter( 'posts_where', array( $this, 'filter_posts_where_set_flag' ) ); + + $this->assertFalse( $this->posts_where_filter_fired ); + } + + /** + * @ticket 7326 + */ + public function test_suppress_filters_false_should_apply_posts_where_filter() { + self::factory()->post->create(); + + add_filter( 'posts_where', array( $this, 'filter_posts_where_set_flag' ) ); + get_posts( array( 'suppress_filters' => false ) ); + remove_filter( 'posts_where', array( $this, 'filter_posts_where_set_flag' ) ); + + $this->assertTrue( $this->posts_where_filter_fired ); + } + + public function filter_posts_where_set_flag( $where ) { + $this->posts_where_filter_fired = true; + return $where; + } }