test for item capabilities name

This commit is contained in:
Jacson Passold 2018-03-01 15:58:13 -03:00
parent aff09b7b7e
commit 77185872db
1 changed files with 56 additions and 0 deletions

View File

@ -89,4 +89,60 @@ class Permissions extends TAINACAN_UnitTestCase {
$this->assertFalse(user_can($u2, $collection_unser->cap->edit_post, $collection_unser->get_id()));
}
/**
* @group permission_others_collections
*/
function test_edit_others_collections() {
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste1',
'description' => 'adasdasdsa',
),
true
);
$item = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'testeItem',
'collection' => $collection,
),
true
);
$new_author_user = $this->factory()->user->create(array( 'role' => 'author' ));
wp_set_current_user($new_author_user);
$collection2 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'teste2',
'description' => 'adasdasdsa',
),
true
);
$item2 = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'testeItem',
'collection' => $collection2,
),
true
);
// Once we had a bug that items of all collections shared the same capability type. they should not.
// This test avoid it to happen
$this->assertTrue(current_user_can( $item2->get_capabilities()->edit_post, $item2->get_id() ), 'author should be able to edit items in his collection');
$this->assertFalse(current_user_can( $item->get_capabilities()->edit_post, $item->get_id() ), 'author should not be able to edit items in admins collection');
$this->assertTrue($item2->can_edit(), 'author should be able to edit items in his collection');
$this->assertFalse($item->can_edit(), 'author should not be able to edit items in admins collection');
$this->assertNotEquals($item->get_capabilities()->edit_posts, $item2->get_capabilities()->edit_posts);
}
}