class LayoutBuilderFormModeTest
Same name and namespace in other branches
- 11.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderFormModeTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderFormModeTest
Tests Layout Builder forms.
@group layout_builder
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\layout_builder\Functional\LayoutBuilderFormModeTest implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of LayoutBuilderFormModeTest
File
-
core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderFormModeTest.php, line 18
Namespace
Drupal\Tests\layout_builder\FunctionalView source
class LayoutBuilderFormModeTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'field',
'entity_test',
'layout_builder',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Set up a field with a validation constraint.
$field_storage = FieldStorageConfig::create([
'field_name' => 'foo',
'entity_type' => 'entity_test',
'type' => 'string',
]);
$field_storage->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
// Expecting required value.
'required' => TRUE,
])->save();
// Enable layout builder custom layouts.
LayoutBuilderEntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
])->enable()
->enableLayoutBuilder()
->setOverridable()
->save();
// Add the form mode and show the field with a constraint.
EntityFormMode::create([
'id' => 'entity_test.layout_builder',
'targetEntityType' => 'entity_test',
])->save();
EntityFormDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'layout_builder',
'status' => TRUE,
])->setComponent('foo', [
'type' => 'string_textfield',
])
->save();
$this->drupalLogin($this->drupalCreateUser([
'view test entity',
'configure any layout',
'configure all entity_test entity_test layout overrides',
]));
EntityTest::create()->setName($this->randomMachineName())
->save();
}
/**
* Tests that the 'Discard changes' button skips validation and ignores input.
*/
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.