WordPress.org

Make WordPress Core

Changeset 1097 in tests


Ignore:
Timestamp:
10/28/12 19:53:33 (18 months ago)
Author:
westi
Message:

Posts/Users: Add tests for a proposed enhancement to count_many_users_posts() to make the return data more cachable.

When the new argument is passed and set to true then we will only count publicly viewable posts and so the returned data can be cached.
See #WP21431

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/user.php

    r1084 r1097  
    565565        $this->assertEquals( $reassign, $post->post_author ); 
    566566    } 
     567 
     568    /** 
     569     * @ticket 21431 
     570     */ 
     571    function test_count_many_users_posts() { 
     572        $user_id_a = $this->factory->user->create( array( 'role' => 'author' ) ); 
     573        $user_id_b = $this->factory->user->create( array( 'role' => 'author' ) ); 
     574        $post_id_a = $this->factory->post->create( array( 'post_author' => $user_id_a ) ); 
     575        $post_id_b = $this->factory->post->create( array( 'post_author' => $user_id_b ) ); 
     576        $post_id_c = $this->factory->post->create( array( 'post_author' => $user_id_b, 'post_status' => 'private' ) ); 
     577 
     578        wp_set_current_user( $user_id_a ); 
     579        $counts = count_many_users_posts( array( $user_id_a, $user_id_b), 'post', false ); 
     580        $this->assertEquals( 1, $counts[$user_id_a] ); 
     581        $this->assertEquals( 1, $counts[$user_id_b] ); 
     582 
     583        $counts = count_many_users_posts( array( $user_id_a, $user_id_b), 'post', true ); 
     584        $this->assertEquals( 1, $counts[$user_id_a] ); 
     585        $this->assertEquals( 1, $counts[$user_id_b] ); 
     586 
     587        wp_set_current_user( $user_id_b ); 
     588        $counts = count_many_users_posts( array( $user_id_a, $user_id_b), 'post', false ); 
     589        $this->assertEquals( 1, $counts[$user_id_a] ); 
     590        $this->assertEquals( 2, $counts[$user_id_b] ); 
     591 
     592        $counts = count_many_users_posts( array( $user_id_a, $user_id_b), 'post', true ); 
     593        $this->assertEquals( 1, $counts[$user_id_a] ); 
     594        $this->assertEquals( 1, $counts[$user_id_b] ); 
     595    } 
    567596} 
Note: See TracChangeset for help on using the changeset viewer.