public function FilterAccessTest::testEditAccess in Workbench Access 8
Test edit access integration.
File
- tests/
src/ Kernel/ FilterAccessTest.php, line 130
Class
- FilterAccessTest
- Tests workbench_access integration with entity_test.
Namespace
Drupal\Tests\workbench_access\KernelCode
public function testEditAccess() {
// The first user in a kernel test gets UID 1, so we need to make sure we're
// not testing with that user.
$this
->createUser();
// Create two users with equal permissions but assign one of them to the
// section.
$permissions = [
'administer filters',
];
$allowed_editor = $this
->createUser($permissions);
$this->container
->get('workbench_access.user_section_storage')
->addUser($this->scheme, $allowed_editor, [
'filter_html_escape',
]);
$allowed_editor
->save();
$editor_with_no_access = $this
->createUser($permissions);
// Test an entity that is not assigned to a section. Both should be allowed
// because we do not assert access control by default.
$this
->assertTrue($this->accessHandler
->access($this->filterFormat1, 'update', $allowed_editor));
$this
->assertTrue($this->accessHandler
->access($this->filterFormat1, 'update', $editor_with_no_access));
// Create an entity that is assigned to a section.
$this
->assertTrue($this->accessHandler
->access($this->filterFormat2, 'update', $allowed_editor));
$this
->assertFalse($this->accessHandler
->access($this->filterFormat2, 'update', $editor_with_no_access));
// With strict checking, entities that are not assigned to a section return
// false.
$this
->config('workbench_access.settings')
->set('deny_on_empty', 1)
->save();
$this->accessHandler
->resetCache();
$this
->assertFalse($this->accessHandler
->access($this->filterFormat1, 'update', $allowed_editor));
$this
->assertFalse($this->accessHandler
->access($this->filterFormat1, 'update', $editor_with_no_access));
}