public function StateAccessTest::testEditPermissions in Workbench Moderation State Access 8
File
- tests/
src/ Functional/ StateAccessTest.php, line 30 - Contains \Drupal\Tests\workbench_moderation_state_access\Functional\StateAccessTest.
Class
- StateAccessTest
- Tests the state access added by this module.
Namespace
Drupal\Tests\workbench_moderation_state_access\FunctionalCode
public function testEditPermissions() {
// Create node type.
$node_type_id = 'test';
$node_type = $this
->createNodeType('Test', $node_type_id);
// Create users.
$permissions = [
'access content',
'edit content in the draft state',
'edit any ' . $node_type_id . ' content',
'view all revisions',
'view moderation states',
];
$author = $this
->drupalCreateUser($permissions);
$permissions = [
'access content',
'edit content in the needs_review state',
'edit any ' . $node_type_id . ' content',
'view all revisions',
'view moderation states',
];
$approver = $this
->drupalCreateUser($permissions);
// Create nodes.
/** @var Node $draft_node */
$draft_node = Node::create([
'type' => $node_type_id,
'title' => 'Draft node',
'uid' => $author
->id(),
]);
$draft_node->moderation_state->target_id = 'draft';
$draft_node
->save();
/** @var Node $review_node */
$review_node = Node::create([
'type' => $node_type_id,
'title' => 'Review node',
'uid' => $approver
->id(),
]);
$review_node->moderation_state->target_id = 'needs_review';
$review_node
->save();
// Author can edit draft node, but not review node.
$access_denied = 'Access denied';
$this
->drupalLogin($author);
$this
->drupalGet('node/' . $draft_node
->id() . '/edit');
$page = $this
->getSession()
->getPage();
$this
->assertFalse($page
->hasContent($access_denied));
$this
->drupalGet('node/' . $review_node
->id() . '/edit');
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasContent($access_denied));
$this
->drupalLogin($approver);
$this
->drupalGet('node/' . $draft_node
->id() . '/edit');
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasContent($access_denied));
$this
->drupalGet('node/' . $review_node
->id() . '/edit');
$page = $this
->getSession()
->getPage();
$this
->assertFalse($page
->hasContent($access_denied));
}