Make WordPress Core


Ignore:
Timestamp:
12/14/2018 02:14:13 AM (8 years ago)
Author:
jeremyfelt
Message:

Blocks: Add the reusable block post type, wp_block.

Merges [43804] from the 5.0 branch to trunk.

See #45098.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tests/phpunit/tests/user/capabilities.php

    r43571 r44146  
    1818        protected static $super_admin = null;
    1919
     20        protected static $block_id;
     21
    2022        public static function wpSetUpBeforeClass( $factory ) {
    2123                self::$users       = array(
    … …  
    2830                self::$super_admin = $factory->user->create_and_get( array( 'role' => 'contributor' ) );
    2931                grant_super_admin( self::$super_admin->ID );
     32
     33                self::$block_id = $factory->post->create(
     34                        array(
     35                                'post_author'  => self::$users['administrator']->ID,
     36                                'post_type'    => 'wp_block',
     37                                'post_status'  => 'publish',
     38                                'post_title'   => 'Test Block',
     39                                'post_content' => '<!-- wp:core/paragraph --><p>Hello world!</p><!-- /wp:core/paragraph -->',
     40                        )
     41                );
    3042        }
    3143
    … …  
    3648
    3749        }
     50
     51        public static function wpTearDownAfterClass() {
     52                wp_delete_post( self::$block_id, true );
     53        }
     54
    3855
    3956        function _flush_roles() {
    … …  
    20962113                $this->assertSame( 333, $roles->get_site_id() );
    20972114        }
     2115
     2116        /**
     2117         * @dataProvider data_block_caps
     2118         */
     2119        function test_block_caps( $role, $cap, $use_post, $expected ) {
     2120                if ( $use_post ) {
     2121                        $this->assertEquals( $expected, self::$users[ $role ]->has_cap( $cap, self::$block_id ) );
     2122                } else {
     2123                        $this->assertEquals( $expected, self::$users[ $role ]->has_cap( $cap ) );
     2124                }
     2125        }
     2126
     2127        function data_block_caps() {
     2128                $post_caps = array(
     2129                        'edit_block',
     2130                        'read_block',
     2131                        'delete_block',
     2132                );
     2133
     2134                $all_caps = array(
     2135                        'edit_block',
     2136                        'read_block',
     2137                        'delete_block',
     2138                        'edit_blocks',
     2139                        'edit_others_blocks',
     2140                        'publish_blocks',
     2141                        'read_private_blocks',
     2142                        'delete_blocks',
     2143                        'delete_private_blocks',
     2144                        'delete_published_blocks',
     2145                        'delete_others_blocks',
     2146                        'edit_private_blocks',
     2147                        'edit_published_blocks',
     2148                );
     2149
     2150                $roles = array(
     2151                        'administrator' => $all_caps,
     2152                        'editor'        => $all_caps,
     2153                        'author'        => array(
     2154                                'read_block',
     2155                                'edit_blocks',
     2156                                'publish_blocks',
     2157                                'delete_blocks',
     2158                                'delete_published_blocks',
     2159                                'edit_published_blocks',
     2160                        ),
     2161                        'contributor'   => array(
     2162                                'read_block',
     2163                                'edit_blocks',
     2164                                'delete_blocks',
     2165                        ),
     2166                        'subscriber'    => array(),
     2167                );
     2168
     2169                $data = array();
     2170
     2171                foreach ( $roles as $role => $caps ) {
     2172                        foreach ( $caps as $cap ) {
     2173                                $use_post = in_array( $cap, $post_caps, true );
     2174                                $data[]   = array( $role, $cap, $use_post, true );
     2175                        }
     2176
     2177                        foreach ( $all_caps as $cap ) {
     2178                                if ( ! in_array( $cap, $caps, true ) ) {
     2179                                        $use_post = in_array( $cap, $post_caps, true );
     2180                                        $data[]   = array( $role, $cap, $use_post, false );
     2181                                }
     2182                        }
     2183                }
     2184
     2185                return $data;
     2186        }
    20982187}
Note: See TracChangeset for help on using the changeset viewer.