2017-12-21 00:25:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tainacan\Tests;
|
|
|
|
|
2018-01-10 23:09:41 +00:00
|
|
|
use Tainacan\Entities\Collection;
|
|
|
|
|
2017-12-21 00:25:46 +00:00
|
|
|
/**
|
|
|
|
* Class TestCollections
|
|
|
|
*
|
|
|
|
* @package Test_Tainacan
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group permissions
|
|
|
|
*/
|
|
|
|
class Permissions extends TAINACAN_UnitTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function test_roles () {
|
2018-01-10 23:09:41 +00:00
|
|
|
$collection = $this->tainacan_entity_factory->create_entity(
|
|
|
|
'collection',
|
|
|
|
array(
|
|
|
|
'name' => 'testePerms',
|
|
|
|
'description' => 'adasdasdsa',
|
|
|
|
),
|
|
|
|
true
|
|
|
|
);
|
2017-12-21 00:25:46 +00:00
|
|
|
$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);
|
2018-01-10 23:09:41 +00:00
|
|
|
//var_dump($collection->cap);
|
|
|
|
$this->assertTrue(user_can($user_id, $collection->cap->read, $collection->get_id()), 'A subscriber user cannot read Collections');
|
2017-12-21 00:25:46 +00:00
|
|
|
$this->assertTrue(user_can($user_id, 'subscriber'));
|
2018-01-10 23:09:41 +00:00
|
|
|
$this->assertFalse(user_can($user_id, $collection->cap->edit_post, $collection->get_id()), 'A subscriber user can edit a Collections?');
|
|
|
|
|
2017-12-21 00:25:46 +00:00
|
|
|
|
|
|
|
$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'));
|
2018-01-10 23:09:41 +00:00
|
|
|
$this->assertTrue(user_can($user_id, $collection->cap->edit_post, $collection->get_id()), 'A administrator user cannot edit a Collections?');
|
2017-12-21 00:25:46 +00:00
|
|
|
//TODO test all roles and check the capabilities
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|