From 470a9fa6e2fe611f4e3d26600a083834c531137c Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 3 Sep 2016 02:15:00 +0000 Subject: [PATCH] Taxonomy: Introduce some taxonomy capability tests in preparation for introducing more fine grained capabilities for terms. See #35614 git-svn-id: https://develop.svn.wordpress.org/trunk@38516 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/user/capabilities.php | 69 +++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php index ab8b83ac9e..ac947b2eb0 100644 --- a/tests/phpunit/tests/user/capabilities.php +++ b/tests/phpunit/tests/user/capabilities.php @@ -917,6 +917,75 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertFalse($contributor->has_cap('delete_page', $page)); } + /** + * @dataProvider dataTaxonomies + * + * @ticket 35614 + */ + public function test_taxonomy_capabilities_are_correct( $taxonomy ) { + if ( ! taxonomy_exists( $taxonomy ) ) { + register_taxonomy( $taxonomy, 'post' ); + } + + $tax = get_taxonomy( $taxonomy ); + $user = self::$users['administrator']; + + // Primitive capabilities for all taxonomies should match this: + $expected = array( + 'manage_terms' => 'manage_categories', + 'edit_terms' => 'manage_categories', + 'delete_terms' => 'manage_categories', + 'assign_terms' => 'edit_posts', + ); + + foreach ( $expected as $meta_cap => $primitive_cap ) { + $caps = map_meta_cap( $tax->cap->$meta_cap, $user->ID ); + $this->assertEquals( array( + $primitive_cap, + ), $caps, "Meta cap: {$meta_cap}" ); + } + } + + public function dataTaxonomies() { + return array( + array( + 'post_tag', + ), + array( + 'category', + ), + array( + 'standard_custom_taxo', + ), + ); + } + + /** + * @ticket 35614 + */ + public function test_taxonomy_capabilities_with_custom_caps_are_correct() { + $expected = array( + 'manage_terms' => 'one', + 'edit_terms' => 'two', + 'delete_terms' => 'three', + 'assign_terms' => 'four', + ); + $taxonomy = 'custom_cap_taxo'; + register_taxonomy( $taxonomy, 'post', array( + 'capabilities' => $expected, + ) ); + + $tax = get_taxonomy( $taxonomy ); + $user = self::$users['administrator']; + + foreach ( $expected as $meta_cap => $primitive_cap ) { + $caps = map_meta_cap( $tax->cap->$meta_cap, $user->ID ); + $this->assertEquals( array( + $primitive_cap, + ), $caps, "Meta cap: {$meta_cap}" ); + } + } + /** * @ticket 21786 */