mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-04 17:20:07 +00:00
Blocks: Add the reusable block post type, wp_block.
Merges [43804] from the 5.0 branch to trunk. See #45098. git-svn-id: https://develop.svn.wordpress.org/trunk@44146 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -17,6 +17,8 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
|
||||
);
|
||||
protected static $super_admin = null;
|
||||
|
||||
protected static $block_id;
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$users = array(
|
||||
'administrator' => $factory->user->create_and_get( array( 'role' => 'administrator' ) ),
|
||||
@@ -27,6 +29,16 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
|
||||
);
|
||||
self::$super_admin = $factory->user->create_and_get( array( 'role' => 'contributor' ) );
|
||||
grant_super_admin( self::$super_admin->ID );
|
||||
|
||||
self::$block_id = $factory->post->create(
|
||||
array(
|
||||
'post_author' => self::$users['administrator']->ID,
|
||||
'post_type' => 'wp_block',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => 'Test Block',
|
||||
'post_content' => '<!-- wp:core/paragraph --><p>Hello world!</p><!-- /wp:core/paragraph -->',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
@@ -36,6 +48,11 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
|
||||
|
||||
}
|
||||
|
||||
public static function wpTearDownAfterClass() {
|
||||
wp_delete_post( self::$block_id, true );
|
||||
}
|
||||
|
||||
|
||||
function _flush_roles() {
|
||||
// we want to make sure we're testing against the db, not just in-memory data
|
||||
// this will flush everything and reload it from the db
|
||||
@@ -2095,4 +2112,76 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
|
||||
|
||||
$this->assertSame( 333, $roles->get_site_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_block_caps
|
||||
*/
|
||||
function test_block_caps( $role, $cap, $use_post, $expected ) {
|
||||
if ( $use_post ) {
|
||||
$this->assertEquals( $expected, self::$users[ $role ]->has_cap( $cap, self::$block_id ) );
|
||||
} else {
|
||||
$this->assertEquals( $expected, self::$users[ $role ]->has_cap( $cap ) );
|
||||
}
|
||||
}
|
||||
|
||||
function data_block_caps() {
|
||||
$post_caps = array(
|
||||
'edit_block',
|
||||
'read_block',
|
||||
'delete_block',
|
||||
);
|
||||
|
||||
$all_caps = array(
|
||||
'edit_block',
|
||||
'read_block',
|
||||
'delete_block',
|
||||
'edit_blocks',
|
||||
'edit_others_blocks',
|
||||
'publish_blocks',
|
||||
'read_private_blocks',
|
||||
'delete_blocks',
|
||||
'delete_private_blocks',
|
||||
'delete_published_blocks',
|
||||
'delete_others_blocks',
|
||||
'edit_private_blocks',
|
||||
'edit_published_blocks',
|
||||
);
|
||||
|
||||
$roles = array(
|
||||
'administrator' => $all_caps,
|
||||
'editor' => $all_caps,
|
||||
'author' => array(
|
||||
'read_block',
|
||||
'edit_blocks',
|
||||
'publish_blocks',
|
||||
'delete_blocks',
|
||||
'delete_published_blocks',
|
||||
'edit_published_blocks',
|
||||
),
|
||||
'contributor' => array(
|
||||
'read_block',
|
||||
'edit_blocks',
|
||||
'delete_blocks',
|
||||
),
|
||||
'subscriber' => array(),
|
||||
);
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $roles as $role => $caps ) {
|
||||
foreach ( $caps as $cap ) {
|
||||
$use_post = in_array( $cap, $post_caps, true );
|
||||
$data[] = array( $role, $cap, $use_post, true );
|
||||
}
|
||||
|
||||
foreach ( $all_caps as $cap ) {
|
||||
if ( ! in_array( $cap, $caps, true ) ) {
|
||||
$use_post = in_array( $cap, $post_caps, true );
|
||||
$data[] = array( $role, $cap, $use_post, false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user