Make WordPress Core

Changeset 65101


Ignore:
Timestamp:
10/30/2026 09:44:08 PM (8 days ago)
Author:
lancewillett
Message:

Tests: Cover filter suppression in post queries.

Verify that get_posts() suppresses posts_where filters by default and honors an explicit suppress_filters value of false.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14015

Props irozum, huzaifaalmesbah.
See #65819, #7326.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/getPosts.php

    r63924 r65101  
    66 */
    77class Tests_Post_GetPosts extends WP_UnitTestCase {
     8        private $posts_where_filter_fired = false;
     9
    810        public function test_offset_should_be_null_by_default() {
    911                $p1 = self::factory()->post->create(
    … …  
    216218                $this->assertSame( $expected, get_posts( $args ), 'The cached call is not of the expected form.' );
    217219        }
     220
     221        /**
     222         * @ticket 7326
     223         */
     224        public function test_should_suppress_posts_where_filter_by_default() {
     225                self::factory()->post->create();
     226
     227                add_filter( 'posts_where', array( $this, 'filter_posts_where_set_flag' ) );
     228                get_posts();
     229                remove_filter( 'posts_where', array( $this, 'filter_posts_where_set_flag' ) );
     230
     231                $this->assertFalse( $this->posts_where_filter_fired );
     232        }
     233
     234        /**
     235         * @ticket 7326
     236         */
     237        public function test_suppress_filters_false_should_apply_posts_where_filter() {
     238                self::factory()->post->create();
     239
     240                add_filter( 'posts_where', array( $this, 'filter_posts_where_set_flag' ) );
     241                get_posts( array( 'suppress_filters' => false ) );
     242                remove_filter( 'posts_where', array( $this, 'filter_posts_where_set_flag' ) );
     243
     244                $this->assertTrue( $this->posts_where_filter_fired );
     245        }
     246
     247        public function filter_posts_where_set_flag( $where ) {
     248                $this->posts_where_filter_fired = true;
     249                return $where;
     250        }
    218251}
Note: See TracChangeset for help on using the changeset viewer.