protected function EntityHierarchyWorkbenchAccessTest::checkAccess in Entity Reference Hierarchy 8.2
Same name and namespace in other branches
- 3.x modules/entity_hierarchy_workbench_access/tests/src/Kernel/EntityHierarchyWorkbenchAccessTest.php \Drupal\Tests\entity_hierarchy_workbench_access\Kernel\EntityHierarchyWorkbenchAccessTest::checkAccess()
Checks access.
Parameters
\Drupal\Core\Entity\EntityInterface[] $allowed: Entities that should have access to.
\Drupal\Core\Entity\EntityInterface[] $disallowed: Entities that should not have access to.
\Drupal\Core\Session\AccountInterface $editor: Account to check access with.
1 call to EntityHierarchyWorkbenchAccessTest::checkAccess()
- EntityHierarchyWorkbenchAccessTest::testWorkbenchAccessIntegration in modules/
entity_hierarchy_workbench_access/ tests/ src/ Kernel/ EntityHierarchyWorkbenchAccessTest.php - Tests integration.
File
- modules/
entity_hierarchy_workbench_access/ tests/ src/ Kernel/ EntityHierarchyWorkbenchAccessTest.php, line 245
Class
- EntityHierarchyWorkbenchAccessTest
- Tests interaction between entity_hierarchy and workbench_access.
Namespace
Drupal\Tests\entity_hierarchy_workbench_access\KernelCode
protected function checkAccess(array $allowed, array $disallowed, AccountInterface $editor) {
$this->container
->get('account_switcher')
->switchTo($editor);
foreach ($allowed as $entity) {
$this
->assertTrue($entity
->access('update', $editor));
$this
->assertTrue($entity
->access('delete', $editor));
// Check can nominate as parent.
$new_child = Node::create([
'type' => $this->childNodeType
->id(),
'title' => 'A new child',
self::FIELD_NAME => $entity
->id(),
]);
$this
->assertEmpty($new_child
->validate());
}
foreach ($disallowed as $entity) {
$this
->assertFalse($entity
->access('update', $editor));
$this
->assertFalse($entity
->access('delete', $editor));
// Check cannot nominate as parent.
$new_child = Node::create([
'type' => $this->childNodeType
->id(),
'title' => 'A new child',
self::FIELD_NAME => $entity
->id(),
]);
$this
->assertNotEmpty($new_child
->validate());
$new_child
->save();
// But can if the item is previously saved and they're not changing the
// parent.
$this
->assertEmpty($new_child
->validate());
}
}