Make WordPress Core


Ignore:
Timestamp:
10/26/2014 04:45:37 PM (10 years ago)
Author:
boonebgorges
Message:

Fix 'count' in WP_Comment_Query when using 'meta_query'.

Props heshiming, desaiuditd.
Fixes #23369.

File:
1 edited

Legend:

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

    r30004 r30026  
    614614        $this->assertNotContains( 'ORDER BY', $q->request );
    615615    }
     616
     617    public function test_count() {
     618        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7 ) );
     619        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7 ) );
     620
     621        $q = new WP_Comment_Query();
     622        $found = $q->query( array(
     623            'count' => true,
     624        ) );
     625
     626        $this->assertEquals( 2, $found );
     627    }
     628
     629    /**
     630     * @ticket 23369
     631     */
     632    public function test_count_with_meta_query() {
     633        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7 ) );
     634        $c2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7 ) );
     635        $c3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'user_id' => 7 ) );
     636        add_comment_meta( $c1, 'foo', 'bar' );
     637        add_comment_meta( $c3, 'foo', 'bar' );
     638
     639        $q = new WP_Comment_Query();
     640        $found = $q->query( array(
     641            'count' => true,
     642            'meta_query' => array(
     643                array(
     644                    'key' => 'foo',
     645                    'value' => 'bar',
     646                ),
     647            ),
     648        ) );
     649
     650        $this->assertEquals( 2, $found );
     651    }
    616652}
Note: See TracChangeset for help on using the changeset viewer.