CategoryAccessControlHandlerTest.php in Mass Contact 8
File
tests/src/Kernel/CategoryAccessControlHandlerTest.php
View source
<?php
namespace Drupal\Tests\mass_contact\Kernel;
use Drupal\simpletest\UserCreationTrait;
class CategoryAccessControlHandlerTest extends MassContactTestBase {
use UserCreationTrait;
use CategoryCreationTrait;
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installSchema('system', [
'sequences',
]);
$this
->createUser();
}
public function testViewAccess() {
$account = $this
->createUser();
$category = $this
->createCategory();
$this
->assertFalse($category
->access('view', $account));
$this
->assertFalse($category
->access('update', $account));
$this
->assertFalse($category
->access('create', $account));
$this
->assertFalse($category
->access('delete', $account));
$account = $this
->createUser([
'mass contact administer',
]);
$this
->assertTrue($category
->access('view', $account));
$this
->assertTrue($category
->access('update', $account));
$this
->assertTrue($category
->access('create', $account));
$this
->assertTrue($category
->access('delete', $account));
$account = $this
->createUser([
'mass contact send to users in the ' . $category
->id() . ' category',
]);
$this
->assertTrue($category
->access('view', $account));
$this
->assertFalse($category
->access('update', $account));
$this
->assertFalse($category
->access('create', $account));
$this
->assertFalse($category
->access('delete', $account));
$category2 = $this
->createCategory();
$this
->assertFalse($category2
->access('view', $account));
$this
->assertFalse($category2
->access('update', $account));
$this
->assertFalse($category2
->access('create', $account));
$this
->assertFalse($category2
->access('delete', $account));
}
}