simple perm test using map

This commit is contained in:
Jacson Passold 2018-01-10 21:09:41 -02:00
parent a1447bcd5b
commit 6ba5122dfe
2 changed files with 30 additions and 6 deletions

View File

@ -31,8 +31,9 @@ class Collections extends TAINACAN_UnitTestCase {
$user_id = get_current_user_id();
$this->assertEquals($new_user, $user_id);
global $Tainacan_Collections;
$this->assertTrue($Tainacan_Collections->can_read($x));
//global $Tainacan_Collections;
//$this->assertTrue($Tainacan_Collections->can_read($x));
$this->assertFalse(current_user_can('edit_collection'));
$autor1 = $this->factory()->user->create(array( 'role' => 'author' ));
wp_set_current_user($autor1);
@ -49,9 +50,20 @@ class Collections extends TAINACAN_UnitTestCase {
$this->assertEquals($autor1_id, $x->WP_Post->post_author);
$autor2 = $this->factory()->user->create(array( 'role' => 'author' ));
wp_set_current_user($autor2);
$x2 = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'testeCapsOwner2',
'description' => 'adasdasdsa',
'default_order' => 'DESC'
),
true
);
$current_user_id = get_current_user_id();
$this->assertEquals($autor2, $current_user_id);
$this->assertFalse($Tainacan_Collections->can_edit($x, $current_user_id));
$this->assertFalse(current_user_can($x->cap->edit_post, $x->WP_Post->ID));
$this->assertTrue(current_user_can($x2->cap->edit_post, $x2->WP_Post->ID));
$this->assertFalse(user_can($autor2, $x->cap->edit_post, $x->WP_Post->ID));
}
/**

View File

@ -2,6 +2,8 @@
namespace Tainacan\Tests;
use Tainacan\Entities\Collection;
/**
* Class TestCollections
*
@ -17,19 +19,29 @@ class Permissions extends TAINACAN_UnitTestCase {
*
*/
function test_roles () {
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'testePerms',
'description' => 'adasdasdsa',
),
true
);
$new_user = $this->factory()->user->create(array( 'role' => 'subscriber' ));
wp_set_current_user($new_user);
$user_id = get_current_user_id();
$this->assertEquals($new_user, $user_id);
$this->assertTrue(user_can($user_id, 'read_'.\Tainacan\Entities\Collection::get_post_type()), 'User cannot read Collections');
//var_dump($collection->cap);
$this->assertTrue(user_can($user_id, $collection->cap->read, $collection->get_id()), 'A subscriber user cannot read Collections');
$this->assertTrue(user_can($user_id, 'subscriber'));
$this->assertFalse(user_can($user_id, 'edit_'.\Tainacan\Entities\Collection::get_post_type()), 'A subscriber user can edit a Collections?');
$this->assertFalse(user_can($user_id, $collection->cap->edit_post, $collection->get_id()), 'A subscriber user can edit a Collections?');
$new_admin_user = $this->factory()->user->create(array( 'role' => 'administrator' ));
wp_set_current_user($new_admin_user);
$user_id = get_current_user_id();
$this->assertTrue(user_can($user_id, 'administrator'));
$this->assertTrue(user_can($user_id, 'edit_'.\Tainacan\Entities\Collection::get_post_type()), 'A administrator user cannot edit a Collections?');
$this->assertTrue(user_can($user_id, $collection->cap->edit_post, $collection->get_id()), 'A administrator user cannot edit a Collections?');
//TODO test all roles and check the capabilities
}