Make WordPress Core


Ignore:
Timestamp:
09/03/2016 02:15:00 AM (10 years ago)
Author:
johnbillion
Message:

Taxonomy: Introduce some taxonomy capability tests in preparation for introducing more fine grained capabilities for terms.

See #35614

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/capabilities.php

    r38482 r38516  
    919919
    920920        /**
     921         * @dataProvider dataTaxonomies
     922         *
     923         * @ticket 35614
     924         */
     925        public function test_taxonomy_capabilities_are_correct( $taxonomy ) {
     926                if ( ! taxonomy_exists( $taxonomy ) ) {
     927                        register_taxonomy( $taxonomy, 'post' );
     928                }
     929
     930                $tax  = get_taxonomy( $taxonomy );
     931                $user = self::$users['administrator'];
     932
     933                // Primitive capabilities for all taxonomies should match this:
     934                $expected = array(
     935                        'manage_terms' => 'manage_categories',
     936                        'edit_terms'   => 'manage_categories',
     937                        'delete_terms' => 'manage_categories',
     938                        'assign_terms' => 'edit_posts',
     939                );
     940
     941                foreach ( $expected as $meta_cap => $primitive_cap ) {
     942                        $caps = map_meta_cap( $tax->cap->$meta_cap, $user->ID );
     943                        $this->assertEquals( array(
     944                                $primitive_cap,
     945                        ), $caps, "Meta cap: {$meta_cap}" );
     946                }
     947        }
     948
     949        public function dataTaxonomies() {
     950                return array(
     951                        array(
     952                                'post_tag',
     953                        ),
     954                        array(
     955                                'category',
     956                        ),
     957                        array(
     958                                'standard_custom_taxo',
     959                        ),
     960                );
     961        }
     962
     963        /**
     964         * @ticket 35614
     965         */
     966        public function test_taxonomy_capabilities_with_custom_caps_are_correct() {
     967                $expected = array(
     968                        'manage_terms' => 'one',
     969                        'edit_terms'   => 'two',
     970                        'delete_terms' => 'three',
     971                        'assign_terms' => 'four',
     972                );
     973                $taxonomy = 'custom_cap_taxo';
     974                register_taxonomy( $taxonomy, 'post', array(
     975                        'capabilities' => $expected,
     976                ) );
     977
     978                $tax  = get_taxonomy( $taxonomy );
     979                $user = self::$users['administrator'];
     980
     981                foreach ( $expected as $meta_cap => $primitive_cap ) {
     982                        $caps = map_meta_cap( $tax->cap->$meta_cap, $user->ID );
     983                        $this->assertEquals( array(
     984                                $primitive_cap,
     985                        ), $caps, "Meta cap: {$meta_cap}" );
     986                }
     987        }
     988
     989        /**
    921990         * @ticket 21786
    922991         */
Note: See TracChangeset for help on using the changeset viewer.