ContentRoleManagerTest.php in Lightning Core 8.4
File
modules/lightning_roles/tests/src/Kernel/ContentRoleManagerTest.php
View source
<?php
namespace Drupal\Tests\lightning_roles\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\user\Entity\Role;
class ContentRoleManagerTest extends KernelTestBase {
protected static $modules = [
'lightning_roles',
'node',
'system',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installConfig('lightning_roles');
$this
->installEntitySchema('user');
}
public function test() {
$node_type = NodeType::create([
'type' => 'page',
]);
$node_type
->save();
$this->container
->get('lightning.content_roles')
->grantPermissions('creator', [
'bypass node access',
]);
$role = Role::load('page_creator');
$expected_creator_permissions = [
'create page content',
'edit own page content',
'view page revisions',
'view own unpublished content',
'create url aliases',
'access in-place editing',
'access contextual links',
'access toolbar',
'bypass node access',
];
foreach ($expected_creator_permissions as $permission) {
$this
->assertTrue($role
->hasPermission($permission));
}
$this
->assertFalse($role
->isAdmin());
$role = Role::load('page_reviewer');
$expected_reviewer_permissions = [
'access content overview',
'edit any page content',
'delete any page content',
];
foreach ($expected_reviewer_permissions as $permission) {
$this
->assertTrue($role
->hasPermission($permission));
}
$this
->assertFalse($role
->isAdmin());
$node_type
->delete();
$roles = Role::loadMultiple([
'page_creator',
'page_reviewer',
]);
$this
->assertEmpty($roles);
}
}