mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-31 02:34:38 +00:00
Support multiple post types in count_user_posts() and other functions that use get_posts_by_author_sql().
Props nikonratm. Fixes #32243. git-svn-id: https://develop.svn.wordpress.org/trunk@32523 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -20,6 +20,18 @@ class Tests_Post_GetPostsByAuthorSql extends WP_UnitTestCase {
|
||||
$this->assertContains( '1 = 0', $maybe_string );
|
||||
}
|
||||
|
||||
public function test_multiple_post_types(){
|
||||
register_post_type( 'foo' );
|
||||
register_post_type( 'bar' );
|
||||
|
||||
$maybe_string = get_posts_by_author_sql( 'foo,bar' );
|
||||
$this->assertContains( "post_type = 'foo'", $maybe_string );
|
||||
$this->assertContains( "post_type = 'bar'", $maybe_string );
|
||||
|
||||
_unregister_post_type( 'foo' );
|
||||
_unregister_post_type( 'bar' );
|
||||
}
|
||||
|
||||
public function test_full_true(){
|
||||
$maybe_string = get_posts_by_author_sql( 'post', true );
|
||||
$this->assertRegExp( '/^WHERE /', $maybe_string );
|
||||
@@ -112,4 +124,25 @@ class Tests_Post_GetPostsByAuthorSql extends WP_UnitTestCase {
|
||||
|
||||
wp_set_current_user( $current_user );
|
||||
}
|
||||
|
||||
public function test_user_has_access_only_to_private_posts_for_certain_post_types(){
|
||||
register_post_type( 'foo', array( 'capabilities' => array( 'read_private_posts' => 'read_private_foo' ) ) );
|
||||
register_post_type( 'bar', array( 'capabilities' => array( 'read_private_posts' => 'read_private_bar' ) ) );
|
||||
register_post_type( 'baz', array( 'capabilities' => array( 'read_private_posts' => 'read_private_baz' ) ) );
|
||||
$current_user = get_current_user_id();
|
||||
$u = $this->factory->user->create( array( 'role' => 'editor' ) );
|
||||
$editor_role = get_role('editor');
|
||||
$editor_role->add_cap( 'read_private_baz' );
|
||||
wp_set_current_user( $u );
|
||||
|
||||
$maybe_string = get_posts_by_author_sql( 'foo,bar,baz' );
|
||||
$this->assertNotContains( "post_type = 'foo' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
|
||||
$this->assertNotContains( "post_type = 'bar' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
|
||||
$this->assertContains( "post_type = 'baz' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
|
||||
|
||||
_unregister_post_type( 'foo' );
|
||||
_unregister_post_type( 'bar' );
|
||||
_unregister_post_type( 'baz' );
|
||||
wp_set_current_user( $current_user );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,4 +78,18 @@ class Tests_User_CountUserPosts extends WP_UnitTestCase {
|
||||
public function test_count_user_posts_post_type_cpt() {
|
||||
$this->assertEquals( 3, count_user_posts( self::$user_id, 'wptests_pt' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 32243
|
||||
*/
|
||||
public function test_count_user_posts_with_multiple_post_types() {
|
||||
$this->assertEquals( 7, count_user_posts( self::$user_id, array( 'wptests_pt', 'post' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 32243
|
||||
*/
|
||||
public function test_count_user_posts_should_ignore_non_existent_post_types() {
|
||||
$this->assertEquals( 4, count_user_posts( self::$user_id, array( 'foo', 'post' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user