getMessagesSelectors example

$theme_config->set('default', 'olivero');
    $theme_config->save();
  }

  /** * Tests data-drupal-selector="messages" exists. */
  public function testDataDrupalSelectors() {
    $web_assert = $this->assertSession();
    $this->drupalGet('js_message_test_link');

    foreach (JSMessageTestController::getMessagesSelectors() as $messagesSelector) {
      $web_assert->elementExists('css', $messagesSelector);
      foreach (JSMessageTestController::getTypes() as $type) {
        $this->click('[id="add-' . $messagesSelector . '-' . $type . '"]');
        $selector = '[data-drupal-selector="messages"]';
        $msg_element = $web_assert->waitForElementVisible('css', $selector);
        $this->assertNotEmpty($msg_element, "Message element visible: $selector");
      }
    }
  }

}
$theme_config->save();
  }

  /** * Tests click on links to show messages and remove messages. */
  public function testAddRemoveMessages() {
    $web_assert = $this->assertSession();
    $this->drupalGet('js_message_test_link');

    $current_messages = [];
    foreach (JSMessageTestController::getMessagesSelectors() as $messagesSelector) {
      $web_assert->elementExists('css', $messagesSelector);
      foreach (JSMessageTestController::getTypes() as $type) {
        $this->click('[id="add-' . $messagesSelector . '-' . $type . '"]');
        $selector = "$messagesSelector .messages.messages--$type";
        $msg_element = $web_assert->waitForElementVisible('css', $selector);
        $this->assertNotEmpty($msg_element, "Message element visible: $selector");
        $web_assert->elementContains('css', $selector, "This is a message of the type, $type. You be the judge of its importance.");
        $current_messages[$selector] = "This is a message of the type, $type. You be the judge of its importance.";
        $this->assertCurrentMessages($current_messages$messagesSelector);
      }
      // Remove messages 1 by 1 and confirm the messages are expected.
return $this->messageLinks();
  }

  /** * Displays links to show messages via JavaScript. * * @return array * Render array for links. */
  public function messageLinks() {
    $buttons = [];
    foreach (static::getMessagesSelectors() as $messagesSelector) {
      $buttons[$messagesSelector] = [
        '#type' => 'details',
        '#open' => TRUE,
        '#title' => "Message area: $messagesSelector",
        '#attributes' => [
          'data-drupal-messages-area' => $messagesSelector,
        ],
      ];
      foreach (static::getTypes() as $type) {
        $buttons[$messagesSelector]["add-$type"] = [
          '#type' => 'html_tag',
          
Home | Imprint | This part of the site doesn't use cookies.