function LayoutBuilderFormModeTest::testDiscardValidation

Same name in other branches
  1. 10 core/modules/layout_builder/tests/src/Functional/LayoutBuilderFormModeTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderFormModeTest::testDiscardValidation()
  2. 11.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderFormModeTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderFormModeTest::testDiscardValidation()

Tests that the 'Discard changes' button skips validation and ignores input.

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderFormModeTest.php, line 95

Class

LayoutBuilderFormModeTest
Tests Layout Builder forms.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testDiscardValidation() {
    $page = $this->getSession()
        ->getPage();
    $assert_session = $this->assertSession();
    // When submitting the form normally, a validation error should be shown.
    $this->drupalGet('entity_test/1/layout');
    $assert_session->fieldExists('foo[0][value]');
    $assert_session->elementAttributeContains('named', [
        'field',
        'foo[0][value]',
    ], 'required', 'required');
    $page->pressButton('Save layout');
    $assert_session->pageTextContains('foo field is required.');
    // When Discarding changes, a validation error will not be shown.
    // Reload the form for fresh state.
    $this->drupalGet('entity_test/1/layout');
    $page->pressButton('Discard changes');
    $assert_session->pageTextNotContains('foo field is required.');
    $assert_session->addressEquals('entity_test/1/layout/discard-changes');
    // Submit the form to ensure no invalid form state retained.
    $page->pressButton('Confirm');
    $assert_session->pageTextContains('The changes to the layout have been discarded.');
}

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