View source
<?php
namespace Drupal\Tests\content_moderation\Functional;
use Drupal\Tests\workspaces\Functional\WorkspaceTestUtilities;
use Drupal\workspaces\Entity\Workspace;
class WorkspaceContentModerationIntegrationTest extends ModerationStateTestBase {
use WorkspaceTestUtilities;
public static $modules = [
'node',
'workspaces',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this->rootUser);
$this
->createContentTypeFromUi('Article', 'article', TRUE);
$this
->setupWorkspaceSwitcherBlock();
}
public function testModerationInWorkspace() {
$stage = Workspace::load('stage');
$this
->switchToWorkspace($stage);
$this
->drupalPostForm('node/add/article', [
'title[0][value]' => 'First article - published',
'moderation_state[0][state]' => 'published',
], 'Save');
$this
->drupalPostForm('node/add/article', [
'title[0][value]' => 'Second article - draft',
'moderation_state[0][state]' => 'draft',
], 'Save');
$first_article = $this
->drupalGetNodeByTitle('First article - published', TRUE);
$this
->assertEquals('published', $first_article->moderation_state->value);
$second_article = $this
->drupalGetNodeByTitle('Second article - draft', TRUE);
$this
->assertEquals('draft', $second_article->moderation_state->value);
$this
->switchToLive();
$this
->drupalGet('<front>');
$this
->assertNoText('First article');
$this
->assertNoText('Second article');
$this
->switchToWorkspace($stage);
$this
->drupalGet('/node/1/edit');
$this
->assertEquals('Current state Published', $this
->cssSelect('#edit-moderation-state-0-current')[0]
->getText());
$this
->drupalPostForm(NULL, [
'title[0][value]' => 'First article - draft',
'moderation_state[0][state]' => 'draft',
], 'Save');
$this
->drupalGet('/node/1');
$this
->assertText('First article - draft');
$this
->drupalGet('/node/1/edit');
$this
->assertEquals('Current state Draft', $this
->cssSelect('#edit-moderation-state-0-current')[0]
->getText());
$this
->drupalPostForm(NULL, [
'title[0][value]' => 'First article - published',
'moderation_state[0][state]' => 'published',
], 'Save');
$this
->drupalPostForm('/node/1/edit', [
'title[0][value]' => 'First article - archived',
'moderation_state[0][state]' => 'archived',
], 'Save');
$this
->drupalGet('/node/1');
$this
->assertText('First article - archived');
$this
->drupalPostForm('/node/2/edit', [
'title[0][value]' => 'Second article - published',
'moderation_state[0][state]' => 'published',
], 'Save');
$stage
->publish();
$this
->drupalGet('/node/1');
$this
->assertText('First article - archived');
$this
->drupalGet('/node/2');
$this
->assertText('Second article - published');
}
}