test collections capabilites #274
This commit is contained in:
parent
277f061512
commit
79813f79c9
|
@ -47,6 +47,10 @@ class Roles {
|
||||||
'display_name' => __('Create Collections', 'tainacan'),
|
'display_name' => __('Create Collections', 'tainacan'),
|
||||||
'description' => __('Create new collections to the repository', 'tainacan')
|
'description' => __('Create new collections to the repository', 'tainacan')
|
||||||
],
|
],
|
||||||
|
'tnc_rep_delete_collections' => [
|
||||||
|
'display_name' => __('Delete Collections', 'tainacan'),
|
||||||
|
'description' => __('Delete their own collections from the repository', 'tainacan')
|
||||||
|
],
|
||||||
'tnc_rep_edit_taxonomies' => [
|
'tnc_rep_edit_taxonomies' => [
|
||||||
'display_name' => __('Create and edit taxonomies', 'tainacan'),
|
'display_name' => __('Create and edit taxonomies', 'tainacan'),
|
||||||
'description' => __('Create new taxonomies and edit its terms', 'tainacan')
|
'description' => __('Create new taxonomies and edit its terms', 'tainacan')
|
||||||
|
|
|
@ -181,8 +181,8 @@ class Collection extends Entity {
|
||||||
return (object) [
|
return (object) [
|
||||||
// meta
|
// meta
|
||||||
'edit_post' => "tnc_col_edit_item",
|
'edit_post' => "tnc_col_edit_item",
|
||||||
'read_post' => "tnc_col_edit_item",
|
'read_post' => "tnc_col_read_item",
|
||||||
'delete_post' => "tnc_col_edit_item",
|
'delete_post' => "tnc_col_delete_item",
|
||||||
|
|
||||||
// primitive
|
// primitive
|
||||||
'edit_posts' => "tnc_rep_edit_collections",
|
'edit_posts' => "tnc_rep_edit_collections",
|
||||||
|
@ -190,9 +190,9 @@ class Collection extends Entity {
|
||||||
'publish_posts' => "tnc_rep_edit_collections",
|
'publish_posts' => "tnc_rep_edit_collections",
|
||||||
'read_private_posts' => "tnc_rep_read_private_collections",
|
'read_private_posts' => "tnc_rep_read_private_collections",
|
||||||
'read' => "read",
|
'read' => "read",
|
||||||
'delete_posts' => "tnc_rep_edit_collections",
|
'delete_posts' => "tnc_rep_delete_collections",
|
||||||
'delete_private_posts' => "tnc_rep_edit_collections",
|
'delete_private_posts' => "tnc_rep_delete_collections",
|
||||||
'delete_published_posts' => "tnc_rep_edit_collections",
|
'delete_published_posts' => "tnc_rep_delete_collections",
|
||||||
'delete_others_posts' => "manage_tainacan",
|
'delete_others_posts' => "manage_tainacan",
|
||||||
'edit_private_posts' => "tnc_rep_edit_collections",
|
'edit_private_posts' => "tnc_rep_edit_collections",
|
||||||
'edit_published_posts' => "tnc_rep_edit_collections",
|
'edit_published_posts' => "tnc_rep_edit_collections",
|
||||||
|
|
|
@ -645,4 +645,96 @@ class Capabilities extends TAINACAN_UnitTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group collections
|
||||||
|
*/
|
||||||
|
function test_collections_metacaps() {
|
||||||
|
|
||||||
|
wp_set_current_user($this->subscriber2->ID);
|
||||||
|
|
||||||
|
$this->subscriber2->add_cap( 'tnc_rep_edit_collections' );
|
||||||
|
|
||||||
|
$my_collection = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'collection',
|
||||||
|
array(
|
||||||
|
'name' => 'My Col',
|
||||||
|
'status' => 'publish'
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertFalse( $this->public_collection->can_edit() );
|
||||||
|
$this->assertTrue( $this->public_collection->can_read() );
|
||||||
|
$this->assertFalse( $this->public_collection->can_delete() );
|
||||||
|
$this->assertFalse( $this->private_collection->can_edit() );
|
||||||
|
$this->assertFalse( $this->private_collection->can_read() );
|
||||||
|
$this->assertFalse( $this->private_collection->can_delete() );
|
||||||
|
$this->assertTrue( $my_collection->can_edit() );
|
||||||
|
$this->assertTrue( $my_collection->can_read() );
|
||||||
|
$this->assertFalse( $my_collection->can_delete() );
|
||||||
|
|
||||||
|
$this->subscriber2->add_cap( 'tnc_rep_delete_collections' );
|
||||||
|
|
||||||
|
$this->assertFalse( $this->public_collection->can_edit() );
|
||||||
|
$this->assertTrue( $this->public_collection->can_read() );
|
||||||
|
$this->assertFalse( $this->public_collection->can_delete() );
|
||||||
|
$this->assertFalse( $this->private_collection->can_edit() );
|
||||||
|
$this->assertFalse( $this->private_collection->can_read() );
|
||||||
|
$this->assertFalse( $this->private_collection->can_delete() );
|
||||||
|
$this->assertTrue( $my_collection->can_edit() );
|
||||||
|
$this->assertTrue( $my_collection->can_read() );
|
||||||
|
$this->assertTrue( $my_collection->can_delete() );
|
||||||
|
|
||||||
|
$this->subscriber2->add_cap( 'tnc_rep_read_private_collections' );
|
||||||
|
|
||||||
|
$this->assertFalse( $this->public_collection->can_edit() );
|
||||||
|
$this->assertTrue( $this->public_collection->can_read() );
|
||||||
|
$this->assertFalse( $this->public_collection->can_delete() );
|
||||||
|
$this->assertFalse( $this->private_collection->can_edit() );
|
||||||
|
$this->assertTrue( $this->private_collection->can_read() );
|
||||||
|
$this->assertFalse( $this->private_collection->can_delete() );
|
||||||
|
|
||||||
|
$this->subscriber2->add_cap( 'manage_tainacan' );
|
||||||
|
|
||||||
|
$this->assertTrue( $this->public_collection->can_edit() );
|
||||||
|
$this->assertTrue( $this->public_collection->can_read() );
|
||||||
|
$this->assertTrue( $this->public_collection->can_delete() );
|
||||||
|
$this->assertTrue( $this->private_collection->can_edit() );
|
||||||
|
$this->assertTrue( $this->private_collection->can_read() );
|
||||||
|
$this->assertTrue( $this->private_collection->can_delete() );
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group collections
|
||||||
|
*/
|
||||||
|
function test_fetch_collections() {
|
||||||
|
global $current_user;
|
||||||
|
wp_set_current_user($this->subscriber2->ID);
|
||||||
|
|
||||||
|
$this->subscriber2->add_cap( 'tnc_rep_edit_collections' );
|
||||||
|
|
||||||
|
$my_collection = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'collection',
|
||||||
|
array(
|
||||||
|
'name' => 'My Col',
|
||||||
|
'status' => 'publish'
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$cols = tainacan_collections()->fetch([], 'OBJECT');
|
||||||
|
$this->assertEquals(2, sizeof($cols));
|
||||||
|
|
||||||
|
$this->subscriber2->add_cap( 'tnc_rep_read_private_collections' );
|
||||||
|
$current_user = $this->subscriber2; // force update current user object with new capabilities
|
||||||
|
|
||||||
|
$cols = tainacan_collections()->fetch([], 'OBJECT');
|
||||||
|
$this->assertEquals(3, sizeof($cols));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue