| 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 | } |