Make WordPress Core

Ticket #50521: 50521.test.diff

File 50521.test.diff, 1.2 KB (added by imath, 5 years ago)
  • tests/phpunit/tests/comment/query.php

    diff --git tests/phpunit/tests/comment/query.php tests/phpunit/tests/comment/query.php
    index a8b856d5d8..04ccecb9eb 100644
    class Tests_Comment_Query extends WP_UnitTestCase { 
    49164916
    49174917                return array( 555 );
    49184918        }
     4919
     4920        /**
     4921         * @ticket 50521
     4922         */
     4923        public function test_comments_pre_query_filter_should_bypass_database_query_and_set_comments() {
     4924                global $wpdb;
     4925
     4926                add_filter( 'comments_pre_query', array( __CLASS__, 'filter_comments_pre_query_and_set_comments' ), 10, 2 );
     4927
     4928                $q       = new WP_Comment_Query();
     4929                $results = $q->query( array() );
     4930
     4931                remove_filter( 'comments_pre_query', array( __CLASS__, 'filter_comments_pre_query_and_set_comments' ), 10, 2 );
     4932
     4933                // Check the comments property of the query is the same than results.
     4934                $this->assertSame( $results, $q->comments );
     4935
     4936                // Check the comment type is `foobar`.
     4937                $this->assertEquals( 'foobar', $q->comments[0]->comment_type );
     4938        }
     4939
     4940        public static function filter_comments_pre_query_and_set_comments( $comments, $query ) {
     4941                $c = self::factory()->comment->create(
     4942                        array(
     4943                                'comment_type'     => 'foobar',
     4944                                'comment_approved' => '1',
     4945                        )
     4946                );
     4947
     4948                return array( get_comment( $c ) );
     4949        }
    49194950}