View source
<?php
namespace Drupal\Tests\lightning_workflow\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\workflows\Entity\Workflow;
class ContentTypeModerationTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'block',
'lightning_roles',
'lightning_workflow',
'views',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
$this
->drupalCreateContentType([
'type' => 'test',
'third_party_settings' => [
'lightning_workflow' => [
'workflow' => 'editorial',
],
],
]);
}
public function testSetWorkflowOnContentTypeCreation() {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$account = $this
->drupalCreateUser([
'access administration pages',
'administer content types',
]);
$this
->drupalLogin($account);
$this
->drupalGet('/admin/structure/types/add');
$page
->fillField('Name', 'Jucketry');
$page
->fillField('type', 'jucketry');
$assert_session
->fieldValueEquals('workflow', 'Editorial');
$assert_session
->optionExists('workflow', '- None -');
$page
->pressButton('Save content type');
$assert_session
->pageTextContains('The content type Jucketry has been added.');
$workflow = Workflow::load('editorial');
$plugin = $workflow
->getTypePlugin();
$this
->assertTrue($plugin
->appliesToEntityTypeAndBundle('node', 'jucketry'));
}
public function testUnpublishedAccess() {
$assert_session = $this
->assertSession();
$this
->drupalCreateNode([
'type' => 'test',
'title' => 'Moderation Test 1',
'promote' => TRUE,
'moderation_state' => 'review',
]);
$this
->drupalGet('<front>');
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextNotContains('Moderation Test 1');
$account = $this
->drupalCreateUser([
'access content overview',
'view any unpublished content',
]);
$this
->drupalLogin($account);
$this
->drupalGet('/admin/content');
$assert_session
->statusCodeEquals(200);
$this
->getSession()
->getPage()
->clickLink('Moderation Test 1');
$assert_session
->statusCodeEquals(200);
}
public function testReviewerAccess() {
$assert_session = $this
->assertSession();
$this
->drupalCreateNode([
'type' => 'test',
'title' => 'Version 1',
'moderation_state' => 'draft',
]);
$account = $this
->drupalCreateUser();
$account
->addRole('test_reviewer');
$account
->save();
$this
->drupalLogin($account);
$this
->drupalGet('/admin/content');
$assert_session
->statusCodeEquals(200);
$this
->getSession()
->getPage()
->clickLink('Version 1');
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextContains('Version 1');
}
public function testLatestUnpublishedRevisionReviewerAccess() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this
->drupalCreateNode([
'type' => 'test',
'title' => 'Version 1',
'moderation_state' => 'draft',
]);
$account = $this
->drupalCreateUser([], NULL, TRUE);
$this
->drupalLogin($account);
$this
->drupalGet('/admin/content');
$assert_session
->statusCodeEquals(200);
$page
->clickLink('Version 1');
$this
->clickEditLink();
$page
->fillField('Title', 'Version 2');
$page
->selectFieldOption('moderation_state[0][state]', 'published');
$page
->pressButton('Save');
$this
->clickEditLink();
$page
->fillField('Title', 'Version 3');
$page
->selectFieldOption('moderation_state[0][state]', 'draft');
$page
->pressButton('Save');
$this
->drupalLogout();
$account = $this
->drupalCreateUser();
$account
->addRole('test_reviewer');
$account
->save();
$this
->drupalLogin($account);
$this
->drupalGet('/admin/content');
$assert_session
->statusCodeEquals(200);
$page
->clickLink('Version 2');
$assert_session
->statusCodeEquals(200);
$assert_session
->linkExists('Latest version');
}
public function testCreateNewRevisionCheckbox() {
$assert_session = $this
->assertSession();
$account = $this
->drupalCreateUser([], NULL, TRUE);
$this
->drupalLogin($account);
$this
->drupalCreateNode([
'type' => $this
->createContentType()
->id(),
'title' => 'Deft Zebra',
]);
$this
->drupalGet('/admin/content');
$this
->getSession()
->getPage()
->clickLink('Deft Zebra');
$this
->clickEditLink();
$assert_session
->fieldExists('Create new revision');
}
public function testEnableModerationForContentType() {
$assert_session = $this
->assertSession();
$node_type = $this
->createContentType()
->id();
$account = $this
->drupalCreateUser([
'administer nodes',
"create {$node_type} content",
]);
$this
->drupalLogin($account);
$this
->drupalGet("/node/add/{$node_type}");
$assert_session
->buttonExists('Save');
$assert_session
->checkboxChecked('Published');
$assert_session
->buttonNotExists('Save and publish');
$assert_session
->buttonNotExists('Save as unpublished');
$workflow = Workflow::load('editorial');
$workflow_type = $workflow
->getTypePlugin();
$workflow_type
->addEntityTypeAndBundle('node', $node_type);
$workflow
->save();
$this
->getSession()
->reload();
$assert_session
->buttonExists('Save');
$assert_session
->fieldNotExists('status[value]');
$assert_session
->buttonNotExists('Save and publish');
$assert_session
->buttonNotExists('Save as unpublished');
}
public function testContentOverviewActions() {
$account = $this
->drupalCreateUser([], NULL, TRUE);
$this
->drupalLogin($account);
$this
->drupalCreateNode([
'type' => 'test',
'title' => 'Foo',
'moderation_state' => 'draft',
]);
$this
->drupalCreateNode([
'type' => 'test',
'title' => 'Bar',
'moderation_state' => 'draft',
]);
$this
->drupalCreateNode([
'type' => 'test',
'title' => 'Baz',
'moderation_state' => 'draft',
]);
$this
->drupalGet('/admin/content');
$assert_session = $this
->assertSession();
$assert_session
->optionNotExists('Action', 'node_publish_action');
$assert_session
->optionNotExists('Action', 'node_unpublish_action');
}
private function clickEditLink() {
$this
->assertSession()
->elementExists('css', 'a[rel="edit-form"]')
->click();
}
}