Make WordPress Core


Ignore:
Timestamp:
05/21/2015 06:42:49 PM (10 years ago)
Author:
boonebgorges
Message:

Support multiple post types in count_user_posts() and other functions that use get_posts_by_author_sql().

Props nikonratm.
Fixes #32243.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/getPostsByAuthorSql.php

    r31653 r32523  
    1919        $maybe_string = get_posts_by_author_sql( 'non_existent_post_type' );
    2020        $this->assertContains( '1 = 0', $maybe_string );
     21    }
     22
     23    public function test_multiple_post_types(){
     24        register_post_type( 'foo' );
     25        register_post_type( 'bar' );
     26
     27        $maybe_string = get_posts_by_author_sql( 'foo,bar' );
     28        $this->assertContains( "post_type = 'foo'", $maybe_string );
     29        $this->assertContains( "post_type = 'bar'", $maybe_string );
     30
     31        _unregister_post_type( 'foo' );
     32        _unregister_post_type( 'bar' );
    2133    }
    2234
     
    113125        wp_set_current_user( $current_user );
    114126    }
     127
     128    public function test_user_has_access_only_to_private_posts_for_certain_post_types(){
     129        register_post_type( 'foo', array( 'capabilities' => array( 'read_private_posts' => 'read_private_foo' ) )  );
     130        register_post_type( 'bar', array( 'capabilities' => array( 'read_private_posts' => 'read_private_bar' ) ) );
     131        register_post_type( 'baz', array( 'capabilities' => array( 'read_private_posts' => 'read_private_baz' ) ) );
     132        $current_user = get_current_user_id();
     133        $u = $this->factory->user->create( array( 'role' => 'editor' ) );
     134        $editor_role = get_role('editor');
     135        $editor_role->add_cap( 'read_private_baz' );
     136        wp_set_current_user( $u );
     137
     138        $maybe_string = get_posts_by_author_sql( 'foo,bar,baz' );
     139        $this->assertNotContains( "post_type = 'foo' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
     140        $this->assertNotContains( "post_type = 'bar' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
     141        $this->assertContains( "post_type = 'baz' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
     142
     143        _unregister_post_type( 'foo' );
     144        _unregister_post_type( 'bar' );
     145        _unregister_post_type( 'baz' );
     146        wp_set_current_user( $current_user );
     147    }
    115148}
Note: See TracChangeset for help on using the changeset viewer.