WordPress.org

Make WordPress Core

Changeset 29980


Ignore:
Timestamp:
10/21/2014 01:40:33 PM (6 years ago)
Author:
boonebgorges
Message:

Improve unit tests for 'status' param in WP_Comment_Query.

See #29612.

File:
1 edited

Legend:

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

    r29965 r29980  
    1919     * @ticket 21101
    2020     */
    21     function test_get_comment_comment_approved_0() {
    22         $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) );
    23         $comments_approved_0 = get_comments( array( 'status' => 'hold' ) );
    24         $this->assertEquals( 0, count( $comments_approved_0 ) );
     21    public function test_status_hold() {
     22        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     23        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '0' ) );
     24
     25        $q = new WP_Comment_Query();
     26        $found = $q->query( array(
     27            'status' => 'hold',
     28            'fields' => 'ids',
     29        ) );
     30
     31        $this->assertEquals( array( $c2 ), $found );
    2532    }
    2633
     
    2835     * @ticket 21101
    2936     */
    30     function test_get_comment_comment_approved_1() {
    31         $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) );
    32         $comments_approved_1 = get_comments( array( 'status' => 'approve' ) );
    33 
    34         $this->assertEquals( 1, count( $comments_approved_1 ) );
    35         $result = $comments_approved_1[0];
    36 
    37         $this->assertEquals( $comment_id, $result->comment_ID );
     37    public function test_status_approve() {
     38        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     39        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '0' ) );
     40
     41        $q = new WP_Comment_Query();
     42        $found = $q->query( array(
     43            'status' => 'approve',
     44            'fields' => 'ids',
     45        ) );
     46
     47        $this->assertEquals( array( $c1 ), $found );
     48    }
     49
     50    public function test_status_custom() {
     51        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     52        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => 'foo' ) );
     53        $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => 'foo1' ) );
     54
     55        $q = new WP_Comment_Query();
     56        $found = $q->query( array(
     57            'status' => 'foo',
     58            'fields' => 'ids',
     59        ) );
     60
     61        $this->assertEquals( array( $c2 ), $found );
     62    }
     63
     64    public function test_status_all() {
     65        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     66        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => 'foo' ) );
     67        $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '0' ) );
     68
     69        $q = new WP_Comment_Query();
     70        $found = $q->query( array(
     71            'status' => 'all',
     72            'fields' => 'ids',
     73        ) );
     74
     75        $this->assertEqualSets( array( $c1, $c3 ), $found );
    3876    }
    3977
Note: See TracChangeset for help on using the changeset viewer.