View source
<?php
namespace Drupal\Tests\bamboo_twig\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\bamboo_twig\Entity\TemplateWhispererSuggestionEntityInterface;
class BambooTwigSecurityTest extends KernelTestBase {
protected $entityTypeManager;
public static $modules = [
'system',
'user',
'bamboo_twig',
'bamboo_twig_security',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installSchema('system', [
'sequences',
'key_value',
]);
$this->entityTypeManager = $this->container
->get('entity_type.manager');
$this->securityExtension = $this->container
->get('bamboo_twig_security.twig.security');
$adminUser = $this->entityTypeManager
->getStorage('user')
->create([
'uid' => 1,
'mail' => 'admin',
'name' => 'admin',
'status' => 1,
]);
$adminUser
->addRole('administrator');
$adminUser
->save();
$adminUser = $this->entityTypeManager
->getStorage('user')
->create([
'uid' => 2,
'mail' => 'anonymous',
'name' => 'anonymous',
'status' => 1,
]);
$adminUser
->save();
}
public function testHasPermissions() {
$result = $this->securityExtension
->hasPermissions([
'bypass node access',
], 'OR', 1);
$this
->assertTrue($result);
}
public function testHasNotPermissions() {
$result = $this->securityExtension
->hasPermissions([
'bypass node access',
], 'OR', 2);
$this
->assertFalse($result);
}
public function testHasRoles() {
$result = $this->securityExtension
->hasRoles([
'administrator',
], 'OR', 1);
$this
->assertTrue($result);
}
public function testHasNotRoles() {
$result = $this->securityExtension
->hasRoles([
'administrator',
], 'OR', 2);
$this
->assertFalse($result);
}
public function testHasPermissionsInvalidConjunction() {
$this
->setExpectedException(\InvalidArgumentException::class, 'Invalid conjunction type "XOR".');
$result = $this->securityExtension
->hasPermissions([
'bypass node access',
], 'XOR', 1);
}
public function testHasRolesInvalidConjunction() {
$this
->setExpectedException(\InvalidArgumentException::class, 'Invalid conjunction type "XOR".');
$result = $this->securityExtension
->hasRoles([
'administrator',
], 'XOR', 1);
}
}