ModerationStateAccessTest.php in Workbench Moderation 8
File
tests/src/Functional/ModerationStateAccessTest.php
View source
<?php
namespace Drupal\Tests\workbench_moderation\Functional;
use Drupal\node\Entity\Node;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\workbench_moderation\Traits\WorkbenchModerationTestTrait;
class ModerationStateAccessTest extends BrowserTestBase {
use WorkbenchModerationTestTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'workbench_moderation_test_views',
'workbench_moderation',
'node',
'views',
'options',
'user',
'system',
];
public function testViewShowsCorrectStates() {
$node_type_id = 'test';
$node_type = $this
->createNodeType('Test', $node_type_id);
$permissions = [
'access content',
'view all revisions',
'view moderation states',
];
$editor1 = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($editor1);
$node_1 = Node::create([
'type' => $node_type_id,
'title' => 'Draft node',
'uid' => $editor1
->id(),
]);
$node_1->moderation_state->target_id = 'draft';
$node_1
->save();
$node_2 = Node::create([
'type' => $node_type_id,
'title' => 'Review node',
'uid' => $editor1
->id(),
]);
$node_2->moderation_state->target_id = 'needs_review';
$node_2
->save();
$node_3 = Node::create([
'type' => $node_type_id,
'title' => 'Published node',
'uid' => $editor1
->id(),
]);
$node_3->moderation_state->target_id = 'published';
$node_3
->save();
$node_3
->setTitle('Archived node');
$node_3->moderation_state->target_id = 'archived';
$node_3
->save();
$this
->drupalGet('/latest');
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasLink('Draft'));
$this
->assertTrue($page
->hasLink('Needs Review'));
$this
->assertTrue($page
->hasLink('Archived'));
$this
->assertFalse($page
->hasLink('Published'));
$permissions = [
'access content',
'view all revisions',
'administer moderation states',
];
$admin1 = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($admin1);
$this
->drupalGet('/latest');
$page = $this
->getSession()
->getPage();
$this
->assertEquals(200, $this
->getSession()
->getStatusCode());
$this
->assertTrue($page
->hasLink('Draft'));
$this
->assertTrue($page
->hasLink('Needs Review'));
$this
->assertTrue($page
->hasLink('Archived'));
$this
->assertFalse($page
->hasLink('Published'));
}
}