You are here

public function DialogPositionTest::testDialogOpenAndClose in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalJavascriptTests/Dialog/DialogPositionTest.php \Drupal\FunctionalJavascriptTests\Dialog\DialogPositionTest::testDialogOpenAndClose()
  2. 10 core/tests/Drupal/FunctionalJavascriptTests/Dialog/DialogPositionTest.php \Drupal\FunctionalJavascriptTests\Dialog\DialogPositionTest::testDialogOpenAndClose()

Tests if the dialog UI works properly with block layout page.

File

core/tests/Drupal/FunctionalJavascriptTests/Dialog/DialogPositionTest.php, line 27

Class

DialogPositionTest
Tests the JavaScript functionality of the dialog position.

Namespace

Drupal\FunctionalJavascriptTests\Dialog

Code

public function testDialogOpenAndClose() {
  $admin_user = $this
    ->drupalCreateUser([
    'administer blocks',
  ]);
  $this
    ->drupalLogin($admin_user);
  $this
    ->drupalGet('admin/structure/block');
  $session = $this
    ->getSession();
  $assert_session = $this
    ->assertSession();
  $page = $session
    ->getPage();

  // Open the dialog using the place block link.
  $placeBlockLink = $page
    ->findLink('Place block');
  $this
    ->assertTrue($placeBlockLink
    ->isVisible(), 'Place block button exists.');
  $placeBlockLink
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $dialog = $page
    ->find('css', '.ui-dialog');
  $this
    ->assertTrue($dialog
    ->isVisible(), 'Dialog is opened after clicking the Place block button.');

  // Close the dialog again.
  $closeButton = $page
    ->find('css', '.ui-dialog-titlebar-close');
  $closeButton
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $dialog = $page
    ->find('css', '.ui-dialog');
  $this
    ->assertNull($dialog, 'Dialog is closed after clicking the close button.');

  // Resize the window. The test should pass after waiting for JavaScript to
  // finish as no Javascript errors should have been triggered. If there were
  // javascript errors the test will fail on that.
  $session
    ->resizeWindow(625, 625);
  $assert_session
    ->assertWaitOnAjaxRequest();
}