WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/29/2014 09:57:07 PM (6 years ago)
Author:
boonebgorges
Message:

Use WP_Comment_Query to query comments in get_approved_comments().

Props dancameron.
See #12668.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment.php

    r25002 r30098  
    1515        $this->assertEquals( 0, $result );
    1616    }
     17
     18    public function test_get_approved_comments() {
     19        $p = $this->factory->post->create();
     20        $ca1 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1' ) );
     21        $ca2 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1' ) );
     22        $ca3 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '0' ) );
     23        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1', 'comment_type' => 'pingback' ) );
     24        $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1', 'comment_type' => 'trackback' ) );
     25        $c4 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1', 'comment_type' => 'mario' ) );
     26        $c5 = $this->factory->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => '1', 'comment_type' => 'luigi' ) );
     27
     28        $found = get_approved_comments( $p );
     29
     30        // all comments types will be returned
     31        $this->assertEquals( array( $ca1, $ca2, $c2, $c3, $c4, $c5 ), wp_list_pluck( $found, 'comment_ID' ) );
     32    }
    1733}
Note: See TracChangeset for help on using the changeset viewer.