View source
<?php
namespace Drupal\workbench_moderation\Tests;
use Drupal\node\NodeInterface;
class NodeAccessTest extends ModerationStateTestBase {
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this->adminUser);
$this
->createContentTypeFromUI('Moderated content', 'moderated_content', TRUE, [
'draft',
'needs_review',
'published',
], 'draft');
$this
->grantUserPermissionToCreateContentOfType($this->adminUser, 'moderated_content');
}
public function testPageAccess() {
$this
->drupalLogin($this->adminUser);
$this
->drupalPostForm('node/add/moderated_content', [
'title[0][value]' => 'moderated content',
], t('Save and Create New Draft'));
$nodes = \Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'title' => 'moderated content',
]);
if (!$nodes) {
$this
->fail('Test node was not saved correctly.');
return;
}
$node = reset($nodes);
$view_path = 'node/' . $node
->id();
$edit_path = 'node/' . $node
->id() . '/edit';
$latest_path = 'node/' . $node
->id() . '/latest';
$this
->drupalPostForm($edit_path, [], t('Save and Request Review'));
$this
->drupalPostForm($edit_path, [], t('Save and Publish'));
$this
->drupalLogout();
$this
->drupalGet($edit_path);
$this
->assertResponse(403);
$this
->drupalGet($latest_path);
$this
->assertResponse(403);
$this
->drupalGet($view_path);
$this
->assertResponse(200);
$this
->drupalLogin($this->adminUser);
$this
->drupalPostForm($edit_path, [
'title[0][value]' => 'moderated content revised',
], t('Save and Create New Draft'));
$user = $this
->createUser([
'use draft_draft transition',
'use draft_needs_review transition',
'use published_draft transition',
'use needs_review_published transition',
'view latest version',
'view any unpublished content',
]);
$this
->drupalLogin($user);
$this
->drupalGet($edit_path);
$this
->assertResponse(403);
$this
->drupalGet($latest_path);
$this
->assertResponse(200);
$this
->drupalGet($view_path);
$this
->assertResponse(200);
$user = $this
->createUser([
'use draft_needs_review transition',
'use published_draft transition',
'use needs_review_published transition',
]);
$this
->drupalLogin($user);
$this
->drupalGet($edit_path);
$this
->assertResponse(403);
$this
->drupalGet($latest_path);
$this
->assertResponse(403);
$this
->drupalGet($view_path);
$this
->assertResponse(200);
}
}