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
This commit is contained in:
parent
6f62798887
commit
470a9fa6e2
@ -917,6 +917,75 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
|
|||||||
$this->assertFalse($contributor->has_cap('delete_page', $page));
|
$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
|
* @ticket 21786
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user