Make WordPress Core

Ticket #25386: 25386-tests.diff

File 25386-tests.diff, 5.6 KB (added by mordauk, 11 years ago)
  • src/wp-includes/author-template.php

     
    336336                'orderby' => 'name', 'order' => 'ASC', 'number' => '',
    337337                'optioncount' => false, 'exclude_admin' => true,
    338338                'show_fullname' => false, 'hide_empty' => true,
    339                 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
     339                'feed' => '', 'feed_image' => '', 'feed_type' => '', 'post_type' => '', 'echo' => true,
    340340                'style' => 'list', 'html' => true, 'exclude' => '', 'include' => ''
    341341        );
    342342
     
    348348        $query_args['fields'] = 'ids';
    349349        $authors = get_users( $query_args );
    350350
     351        if( is_array( $post_type ) ) {
     352
     353                $post_type = 'post_type IN ( ' . implode( ',', array_map( 'sanitize_key', $args['post_type'] ) ) . ' )';
     354
     355        } else {
     356
     357                $post_type = 'post_type = ' . sanitize_key( $args['post_type'] );
     358
     359        }
     360
    351361        $author_count = array();
    352         foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author" ) as $row ) {
     362        foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE $post_type " . get_private_posts_cap_sql( 'any' ) . " GROUP BY post_author" ) as $row ) {
    353363                $author_count[$row->post_author] = $row->count;
    354364        }
    355365        foreach ( $authors as $author_id ) {
     
    440450        global $wpdb;
    441451
    442452        if ( false === ( $is_multi_author = get_transient( 'is_multi_author' ) ) ) {
    443                 $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2");
     453                $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status = 'publish' LIMIT 2");
    444454                $is_multi_author = 1 < count( $rows ) ? 1 : 0;
    445455                set_transient( 'is_multi_author', $is_multi_author );
    446456        }
  • src/wp-includes/post.php

     
    50465046 * @param bool $public_only Optional. Only return public posts. Skips cap checks for $current_user.  Default is false.
    50475047 * @return string SQL WHERE code that can be added to a query.
    50485048 */
    5049 function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) {
     5049function get_posts_by_author_sql( $post_type = 'post', $full = true, $post_author = null, $public_only = false ) {
    50505050        global $wpdb;
    50515051
    50525052        // Private posts
     
    50675067                $cap = $post_type_obj->cap->read_private_posts;
    50685068        }
    50695069
     5070        if( is_array( $post_type ) ) {
     5071
     5072                $post_type_where = 'post_type IN ( ' . implode( ',', array_map( 'sanitize_key', $post_type ) ) . ' )';
     5073
     5074        } else {
     5075
     5076                $post_type_where = 'post_type = ' . sanitize_key( $post_type );
     5077
     5078        }
     5079
    50705080        if ( $full ) {
    50715081                if ( null === $post_author ) {
    5072                         $sql = $wpdb->prepare( 'WHERE post_type = %s AND ', $post_type );
     5082                        $sql = $wpdb->prepare( 'WHERE %s AND ', $post_type_where );
    50735083                } else {
    5074                         $sql = $wpdb->prepare( 'WHERE post_author = %d AND post_type = %s AND ', $post_author, $post_type );
     5084                        $sql = $wpdb->prepare( 'WHERE post_author = %d AND %s AND ', $post_author, $post_type_where );
    50755085                }
    50765086        } else {
    50775087                $sql = '';
  • src/wp-includes/user.php

     
    256256 * @param int $userid User ID.
    257257 * @return int Amount of posts user has written.
    258258 */
    259 function count_user_posts($userid) {
     259function count_user_posts( $userid, $post_type = false ) {
    260260        global $wpdb;
    261261
    262         $where = get_posts_by_author_sql('post', true, $userid);
     262        $where = get_posts_by_author_sql( $post_type, true, $userid );
    263263
    264264        $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    265265
  • tests/phpunit/tests/comment/query.php

     
    180180                $this->assertEquals( $users[1], $comments[2]->user_id );
    181181
    182182        }
     183
     184        /**
     185         * @ticket 25386
     186         */
     187        function test_get_comments_in() {
     188               
     189                $comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) );
     190                $comment_id2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) );
     191                $comment_id3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) );
     192
     193                $comments = get_comments( array( 'comment__in' => array( $comment_id, $comment_id2 ) );
     194
     195                $this->assertCount( 2, $comments );
     196
     197                $this->assertEquals( $comment_id, $comments[0]->comment_ID );
     198                $this->assertEquals( $comment_id2, $comments[1]->comment_ID );
     199
     200                $comments = get_comments( array( 'comment__in' => array( $comment_id3 ) );
     201
     202                $this->assertCount( 1, $comments );
     203                $this->assertEquals( $comment_id3, $comments[0]->comment_ID );
     204
     205        }
     206
     207        /**
     208         * @ticket 25386
     209         */
     210        function test_get_comments_not_in() {
     211               
     212                $comment_id  = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) );
     213                $comment_id2 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) );
     214                $comment_id3 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) );
     215
     216                $comments = get_comments( array( 'comment__not_in' => array( $comment_id, $comment_id2 ) );
     217
     218                $this->assertCount( 1, $comments );
     219                $this->assertEquals( $comment_id3, $comments[0]->comment_ID );
     220
     221        }
    183222}