function LayoutBuilderContentModerationIntegrationTest::testLayoutModeration

Same name in other branches
  1. 9 core/modules/content_moderation/tests/src/Functional/LayoutBuilderContentModerationIntegrationTest.php \Drupal\Tests\content_moderation\Functional\LayoutBuilderContentModerationIntegrationTest::testLayoutModeration()
  2. 8.9.x core/modules/content_moderation/tests/src/Functional/LayoutBuilderContentModerationIntegrationTest.php \Drupal\Tests\content_moderation\Functional\LayoutBuilderContentModerationIntegrationTest::testLayoutModeration()
  3. 10 core/modules/content_moderation/tests/src/Functional/LayoutBuilderContentModerationIntegrationTest.php \Drupal\Tests\content_moderation\Functional\LayoutBuilderContentModerationIntegrationTest::testLayoutModeration()

Tests that Layout changes are respected by Content Moderation.

File

core/modules/content_moderation/tests/src/Functional/LayoutBuilderContentModerationIntegrationTest.php, line 99

Class

LayoutBuilderContentModerationIntegrationTest
Tests Content Moderation's integration with Layout Builder.

Namespace

Drupal\Tests\content_moderation\Functional

Code

public function testLayoutModeration() : void {
    $page = $this->getSession()
        ->getPage();
    $assert_session = $this->assertSession();
    // Create an unpublished node. Revision count: 1.
    $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());
    // Publish the node. Revision count: 2.
    $page->fillField('new_state', 'published');
    $page->pressButton('Apply');
    // Modify the layout.
    $page->clickLink('Layout');
    $assert_session->checkboxChecked('revision');
    $assert_session->fieldDisabled('revision');
    $page->clickLink('Add block');
    $page->clickLink('Powered by Drupal');
    $page->pressButton('Add block');
    // Save the node as a draft. Revision count: 3.
    $page->fillField('moderation_state[0][state]', 'draft');
    $page->pressButton('Save layout');
    // Block is visible on the revision page.
    $assert_session->addressEquals("node/{$node->id()}/latest");
    $assert_session->pageTextContains('Powered by Drupal');
    // Block is visible on the layout form.
    $page->clickLink('Layout');
    $assert_session->pageTextContains('Powered by Drupal');
    // Block is not visible on the live node page.
    $page->clickLink('View');
    $assert_session->pageTextNotContains('Powered by Drupal');
    // Publish the node. Revision count: 4.
    $page->clickLink('Latest version');
    $page->fillField('new_state', 'published');
    $page->pressButton('Apply');
    // Block is visible on the live node page.
    $assert_session->pageTextContains('Powered by Drupal');
    // Revert to the previous revision.
    $page->clickLink('Revisions');
    // Assert that there are 4 total revisions and 3 revert links.
    $assert_session->elementsCount('named', [
        'link',
        'Revert',
    ], 3);
    // Revert to the 2nd revision before modifying the layout.
    $this->clickLink('Revert', 1);
    $page->pressButton('Revert');
    $page->clickLink('View');
    $assert_session->pageTextNotContains('Powered by Drupal');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.