class BlockFormMessagesTest
Same name and namespace in other branches
- 11.x core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFormMessagesTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\BlockFormMessagesTest
Tests that messages appear in the off-canvas dialog with configuring blocks.
@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\FunctionalJavascriptTests\WebDriverTestBase implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\layout_builder\FunctionalJavascript\BlockFormMessagesTest uses \Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait implements \Drupal\FunctionalJavascriptTests\WebDriverTestBase
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of BlockFormMessagesTest
File
-
core/
modules/ layout_builder/ tests/ src/ FunctionalJavascript/ BlockFormMessagesTest.php, line 14
Namespace
Drupal\Tests\layout_builder\FunctionalJavascriptView source
class BlockFormMessagesTest extends WebDriverTestBase {
use ContextualLinkClickTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'layout_builder',
'block',
'node',
'contextual',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'starterkit_theme';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->createContentType([
'type' => 'bundle_with_section_field',
]);
LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')->enableLayoutBuilder()
->setOverridable()
->save();
$this->createNode([
'type' => 'bundle_with_section_field',
]);
}
/**
* Tests that validation messages are shown on the block form.
*/
public function testValidationMessage() {
// @todo Work out why this fixes random fails in this test.
// https://www.drupal.org/project/drupal/issues/3055982
$this->getSession()
->resizeWindow(800, 1000);
$assert_session = $this->assertSession();
$page = $this->getSession()
->getPage();
$this->drupalLogin($this->drupalCreateUser([
'access contextual links',
'configure any layout',
]));
$this->drupalGet('node/1/layout');
$page->findLink('Add block')
->click();
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas .block-categories'));
$page->findLink('Powered by Drupal')
->click();
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas [name="settings[label]"]'));
$page->findField('Title')
->setValue('');
$page->findButton('Add block')
->click();
$this->assertMessagesDisplayed();
$page->findField('Title')
->setValue('New title');
$page->pressButton('Add block');
$block_css_locator = '#layout-builder .block-system-powered-by-block';
$this->assertNotEmpty($assert_session->waitForElementVisible('css', $block_css_locator));
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->assertWaitOnAjaxRequest();
$this->drupalGet($this->getUrl());
$page->findButton('Save layout')
->click();
$this->assertNotEmpty($assert_session->waitForElement('css', 'div:contains("The layout override has been saved")'));
// Ensure that message are displayed when configuring an existing block.
$this->drupalGet('node/1/layout');
$assert_session->assertWaitOnAjaxRequest();
$this->clickContextualLink($block_css_locator, 'Configure', TRUE);
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas [name="settings[label]"]'));
$page->findField('Title')
->setValue('');
$page->findButton('Update')
->click();
$this->assertMessagesDisplayed();
}
/**
* Asserts that the validation messages are shown correctly.
*
* @internal
*/
protected function assertMessagesDisplayed() : void {
$assert_session = $this->assertSession();
$page = $this->getSession()
->getPage();
$messages_locator = '#drupal-off-canvas .messages--error';
$assert_session->assertWaitOnAjaxRequest();
$this->assertNotEmpty($assert_session->waitForElement('css', $messages_locator));
$assert_session->elementTextContains('css', $messages_locator, 'Title field is required.');
/** @var \Behat\Mink\Element\NodeElement[] $top_form_elements */
$top_form_elements = $page->findAll('css', '#drupal-off-canvas form > *');
// Ensure the messages are the first top level element of the form.
$this->assertStringContainsStringIgnoringCase('Title field is required.', $top_form_elements[0]->getText());
$this->assertGreaterThan(4, count($top_form_elements));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.