View source
<?php
namespace Drupal\Tests\content_moderation\Functional;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
class LayoutBuilderContentModerationIntegrationTest extends BrowserTestBase {
use ContentModerationTestTrait;
protected static $modules = [
'layout_builder',
'node',
'content_moderation',
'menu_ui',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_tasks_block');
$this
->createContentType([
'type' => 'bundle_with_section_field',
]);
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'bundle_with_section_field');
$workflow
->save();
LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
->enableLayoutBuilder()
->setOverridable()
->save();
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'edit any bundle_with_section_field content',
'view bundle_with_section_field revisions',
'revert bundle_with_section_field revisions',
'view own unpublished content',
'view latest version',
'use editorial transition create_new_draft',
'use editorial transition publish',
]));
}
public function testLayoutModeration() {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$node = $this
->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The first node title',
'body' => [
[
'value' => 'The first node body',
],
],
]);
_menu_ui_node_save($node, [
'title' => 'bar',
'menu_name' => 'main',
'description' => 'view bar',
'parent' => '',
]);
$this
->drupalGet($node
->toUrl());
$page
->fillField('new_state', 'published');
$page
->pressButton('Apply');
$page
->clickLink('Layout');
$assert_session
->checkboxChecked('revision');
$assert_session
->fieldDisabled('revision');
$page
->clickLink('Add block');
$page
->clickLink('Powered by Drupal');
$page
->pressButton('Add block');
$page
->fillField('moderation_state[0][state]', 'draft');
$page
->pressButton('Save layout');
$assert_session
->addressEquals("node/{$node->id()}/latest");
$assert_session
->pageTextContains('Powered by Drupal');
$page
->clickLink('Layout');
$assert_session
->pageTextContains('Powered by Drupal');
$page
->clickLink('View');
$assert_session
->pageTextNotContains('Powered by Drupal');
$page
->clickLink('Latest version');
$page
->fillField('new_state', 'published');
$page
->pressButton('Apply');
$assert_session
->pageTextContains('Powered by Drupal');
$page
->clickLink('Revisions');
$assert_session
->elementsCount('named', [
'link',
'Revert',
], 3);
$this
->clickLink('Revert', 1);
$page
->pressButton('Revert');
$page
->clickLink('View');
$assert_session
->pageTextNotContains('Powered by Drupal');
}
}