class WorkspaceContentModerationIntegrationTest
Same name and namespace in other branches
- 11.x core/modules/content_moderation/tests/src/Functional/WorkspaceContentModerationIntegrationTest.php \Drupal\Tests\content_moderation\Functional\WorkspaceContentModerationIntegrationTest
- 10 core/modules/content_moderation/tests/src/Functional/WorkspaceContentModerationIntegrationTest.php \Drupal\Tests\content_moderation\Functional\WorkspaceContentModerationIntegrationTest
Tests Workspaces together with Content Moderation.
@group content_moderation @group workspaces
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\content_moderation\Functional\ModerationStateTestBase uses \Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\content_moderation\Functional\WorkspaceContentModerationIntegrationTest uses \Drupal\Tests\workspaces\Functional\WorkspaceTestUtilities implements \Drupal\Tests\content_moderation\Functional\ModerationStateTestBase
- class \Drupal\Tests\content_moderation\Functional\ModerationStateTestBase uses \Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of WorkspaceContentModerationIntegrationTest
File
-
core/
modules/ content_moderation/ tests/ src/ Functional/ WorkspaceContentModerationIntegrationTest.php, line 14
Namespace
Drupal\Tests\content_moderation\FunctionalView source
class WorkspaceContentModerationIntegrationTest extends ModerationStateTestBase {
use WorkspaceTestUtilities;
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
'workspaces',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->drupalLogin($this->rootUser);
// Enable moderation on Article node type.
$this->createContentTypeFromUi('Article', 'article', TRUE);
$this->setupWorkspaceSwitcherBlock();
}
/**
* Tests moderating nodes in a workspace.
*/
public function testModerationInWorkspace() {
$stage = Workspace::load('stage');
$this->switchToWorkspace($stage);
// Create two nodes, a published and a draft one.
$this->drupalGet('node/add/article');
$this->submitForm([
'title[0][value]' => 'First article - published',
'moderation_state[0][state]' => 'published',
], 'Save');
$this->drupalGet('node/add/article');
$this->submitForm([
'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);
// Check that neither of them are visible in Live.
$this->switchToLive();
$this->drupalGet('<front>');
$this->assertSession()
->pageTextNotContains('First article');
$this->assertSession()
->pageTextNotContains('Second article');
// Switch back to Stage.
$this->switchToWorkspace($stage);
// Take the first node through various moderation states.
$this->drupalGet('/node/1/edit');
$this->assertEquals('Current state Published', $this->cssSelect('#edit-moderation-state-0-current')[0]
->getText());
$this->submitForm([
'title[0][value]' => 'First article - draft',
'moderation_state[0][state]' => 'draft',
], 'Save');
$this->drupalGet('/node/1');
$this->assertSession()
->pageTextContains('First article - draft');
$this->drupalGet('/node/1/edit');
$this->assertEquals('Current state Draft', $this->cssSelect('#edit-moderation-state-0-current')[0]
->getText());
$this->submitForm([
'title[0][value]' => 'First article - published',
'moderation_state[0][state]' => 'published',
], 'Save');
$this->drupalGet('/node/1/edit');
$this->submitForm([
'title[0][value]' => 'First article - archived',
'moderation_state[0][state]' => 'archived',
], 'Save');
$this->drupalGet('/node/1');
$this->assertSession()
->pageTextContains('First article - archived');
// Get the second node to a default revision state and publish the
// workspace.
$this->drupalGet('/node/2/edit');
$this->submitForm([
'title[0][value]' => 'Second article - published',
'moderation_state[0][state]' => 'published',
], 'Save');
$stage->publish();
// The admin user can see unpublished nodes.
$this->drupalGet('/node/1');
$this->assertSession()
->pageTextContains('First article - archived');
$this->drupalGet('/node/2');
$this->assertSession()
->pageTextContains('Second article - published');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.