public function ModerationStateAccessTest::testViewShowsCorrectStates in Drupal 8
Same name and namespace in other branches
- 9 core/modules/content_moderation/tests/src/Functional/ModerationStateAccessTest.php \Drupal\Tests\content_moderation\Functional\ModerationStateAccessTest::testViewShowsCorrectStates()
Test the view operation access handler with the view permission.
File
- core/
modules/ content_moderation/ tests/ src/ Functional/ ModerationStateAccessTest.php, line 54
Class
- ModerationStateAccessTest
- Tests the view access control handler for moderation state entities.
Namespace
Drupal\Tests\content_moderation\FunctionalCode
public function testViewShowsCorrectStates() {
$permissions = [
'access content',
'view all revisions',
];
$editor1 = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($editor1);
$node_1 = Node::create([
'type' => 'test',
'title' => 'Draft node',
'uid' => $editor1
->id(),
]);
$node_1->moderation_state->value = 'draft';
$node_1
->save();
$node_2 = Node::create([
'type' => 'test',
'title' => 'Published node',
'uid' => $editor1
->id(),
]);
$node_2->moderation_state->value = 'published';
$node_2
->save();
// Resave the node with a new state.
$node_2
->setTitle('Archived node');
$node_2->moderation_state->value = 'archived';
$node_2
->save();
// Now show the View, and confirm that the state labels are showing.
$this
->drupalGet('/latest');
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasContent('Draft'));
$this
->assertTrue($page
->hasContent('Archived'));
$this
->assertFalse($page
->hasContent('Published'));
// Now log in as an admin and test the same thing.
$permissions = [
'access content',
'view all revisions',
];
$admin1 = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($admin1);
$this
->drupalGet('/latest');
$page = $this
->getSession()
->getPage();
$this
->assertEquals(200, $this
->getSession()
->getStatusCode());
$this
->assertTrue($page
->hasContent('Draft'));
$this
->assertTrue($page
->hasContent('Archived'));
$this
->assertFalse($page
->hasContent('Published'));
}