Commit a83adc88 authored by Chris Burge's avatar Chris Burge
Browse files

Issue #3257311 by Chris Burge, vselivanov, Grabby: Validation Errors are Not...

Issue #3257311 by Chris Burge, vselivanov, Grabby: Validation Errors are Not Displayed in Settings Tray
parent 9500dc62
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -256,6 +256,10 @@ class ManageComponentAttributesForm extends FormBase {

    $form['#tree'] = TRUE;

    // Workaround for core bug:
    // https://www.drupal.org/project/drupal/issues/2897377.
    $form['#id'] = Html::cleanCssIdentifier($this->getFormId());

    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Update'),
+18 −19
Original line number Diff line number Diff line
@@ -125,25 +125,25 @@ class ComponentAttributeTest extends WebDriverTestBase {
    $page->fillField('block_attributes[id]', '(block-id-test');
    $page->pressButton('Update');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSettingsTrayOpen();
    $this->assertSettingsTrayValidationMessage('Element ID must be a valid CSS ID');
    $page->fillField('block_attributes[id]', 'block-id-test');

    $page->fillField('block_attributes[class]', '*block-class1 block-class2');
    $page->pressButton('Update');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSettingsTrayOpen();
    $this->assertSettingsTrayValidationMessage('Classes must be valid CSS classes');
    $page->fillField('block_attributes[class]', 'block-class1 block-class2');

    $page->fillField('block_attributes[style]', 'color blue;');
    $page->pressButton('Update');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSettingsTrayOpen();
    $this->assertSettingsTrayValidationMessage('Inline styles must be valid CSS');
    $page->fillField('block_attributes[style]', 'color: blue;');

    $page->fillField('block_attributes[data]', 'data-block-test' . PHP_EOL . 'ata-block-test2|test-value');
    $page->pressButton('Update');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSettingsTrayOpen();
    $this->assertSettingsTrayValidationMessage('Data attributes must being with "data-"');
    $page->fillField('block_attributes[data]', 'data-block-test' . PHP_EOL . 'data-block-test2|test-value');

    $page->pressButton('Update');
@@ -157,25 +157,25 @@ class ComponentAttributeTest extends WebDriverTestBase {
    $page->fillField('block_title_attributes[id]', '(block-title-id-test');
    $page->pressButton('Update');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSettingsTrayOpen();
    $this->assertSettingsTrayValidationMessage('Element ID must be a valid CSS ID');
    $page->fillField('block_title_attributes[id]', 'block-title-id-test');

    $page->fillField('block_title_attributes[class]', '*block-title-class1 block-title-class2');
    $page->pressButton('Update');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSettingsTrayOpen();
    $this->assertSettingsTrayValidationMessage('Classes must be valid CSS classes');
    $page->fillField('block_title_attributes[class]', 'block-title-class1 block-title-class2');

    $page->fillField('block_title_attributes[style]', 'color white;');
    $page->pressButton('Update');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSettingsTrayOpen();
    $this->assertSettingsTrayValidationMessage('Inline styles must be valid CSS');
    $page->fillField('block_title_attributes[style]', 'color: white;');

    $page->fillField('block_title_attributes[data]', 'data-block-title-test' . PHP_EOL . 'ata-block-title-test2|test-value-title');
    $page->pressButton('Update');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSettingsTrayOpen();
    $this->assertSettingsTrayValidationMessage('Data attributes must being with "data-"');
    $page->fillField('block_title_attributes[data]', 'data-block-title-test' . PHP_EOL . 'data-block-title-test2|test-value-title');

    $page->pressButton('Update');
@@ -189,25 +189,25 @@ class ComponentAttributeTest extends WebDriverTestBase {
    $page->fillField('block_content_attributes[id]', '(block-content-id-test');
    $page->pressButton('Update');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSettingsTrayOpen();
    $this->assertSettingsTrayValidationMessage('Element ID must be a valid CSS ID');
    $page->fillField('block_content_attributes[id]', 'block-content-id-test');

    $page->fillField('block_content_attributes[class]', '*block-content-class1 block-content-class2');
    $page->pressButton('Update');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSettingsTrayOpen();
    $this->assertSettingsTrayValidationMessage('Classes must be valid CSS classes');
    $page->fillField('block_content_attributes[class]', 'block-content-class1 block-content-class2');

    $page->fillField('block_content_attributes[style]', 'color red;');
    $page->pressButton('Update');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSettingsTrayOpen();
    $this->assertSettingsTrayValidationMessage('Inline styles must be valid CSS');
    $page->fillField('block_content_attributes[style]', 'color: red;');

    $page->fillField('block_content_attributes[data]', 'data-block-content-test' . PHP_EOL . 'ata-block-content-test2|test-value-content');
    $page->pressButton('Update');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertSettingsTrayOpen();
    $this->assertSettingsTrayValidationMessage('Data attributes must being with "data-"');
    $page->fillField('block_content_attributes[data]', 'data-block-content-test' . PHP_EOL . 'data-block-content-test2|test-value-content');

    $page->pressButton('Update');
@@ -421,16 +421,15 @@ class ComponentAttributeTest extends WebDriverTestBase {

  /**
   * Helper method to assert the settings tray is open.
   *
   * @param string $message
   *   The expected validation message.
   */
  private function assertSettingsTrayOpen() {
  private function assertSettingsTrayValidationMessage($message = '') {
    $page = $this->getSession()->getPage();
    // Due to https://www.drupal.org/project/drupal/issues/2897377, validation
    // in the settings tray fails silently, so check that the form did not
    // submit and close instead of checking for the error message. When the
    // validation issue is fixed, this method can be removed and actual
    // error messages can be checked.

    $element = $page->find('xpath', '//form[contains(@id, "layout-builder-manage-attributes-form")]');
    $this->assertNotNull($element);
    $this->assertStringContainsString($message, $element->getText(), "Validation message found: " . $message);
  }

  /**