You are here

public function LayoutBuilderModalTest::testContextualLinks in Layout Builder Modal 8

Tests contextual links.

File

tests/src/FunctionalJavascript/LayoutBuilderModalTest.php, line 167

Class

LayoutBuilderModalTest
Tests Layout Builder Modal.

Namespace

Drupal\Tests\layout_builder_modal\FunctionalJavascript

Code

public function testContextualLinks() {
  $layout_url = 'node/1/layout';
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->drupalGet($layout_url);
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->click('.layout-builder__add-section .layout-builder__link--add');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->clickLink('Two column');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $button = $assert_session
    ->elementExists('css', '.layout-builder-configure-section .button--primary');
  $button
    ->press();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->click('.layout-builder__add-block .layout-builder__link--add');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->clickLink('Authored by');
  $assert_session
    ->assertWaitOnAjaxRequest();
  $button = $assert_session
    ->elementExists('css', '#layout-builder-add-block .button--primary');
  $button
    ->press();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $contextual_links = $page
    ->findAll('css', '.layout-builder-block-update a');
  $dialog_options = [];
  foreach ($contextual_links as $key => $contextual_link) {
    $dialog_options[$key] = $contextual_link
      ->getAttribute('data-dialog-options');
  }
  \Drupal::configFactory()
    ->getEditable('layout_builder_modal.settings')
    ->set('modal_width', 600)
    ->save();
  $this
    ->drupalGet($layout_url);
  $assert_session
    ->assertWaitOnAjaxRequest();
  $contextual_links = $page
    ->findAll('css', '.layout-builder-block-update a');
  $updated_dialog_options = [];
  foreach ($contextual_links as $key => $contextual_link) {
    $updated_dialog_options[$key] = $contextual_link
      ->getAttribute('data-dialog-options');
  }
  foreach ($dialog_options as $key => $dialog_option) {
    $this
      ->assertNotSame($dialog_option, $updated_dialog_options[$key]);
  }
}