function DialogTest::testHttpMethod

Same name in other branches
  1. 10 core/tests/Drupal/FunctionalJavascriptTests/Ajax/DialogTest.php \Drupal\FunctionalJavascriptTests\Ajax\DialogTest::testHttpMethod()

Tests dialog link opener with different HTTP methods.

File

core/tests/Drupal/FunctionalJavascriptTests/Ajax/DialogTest.php, line 231

Class

DialogTest
Performs tests on opening and manipulating dialogs via AJAX commands.

Namespace

Drupal\FunctionalJavascriptTests\Ajax

Code

public function testHttpMethod() : void {
    $assert = $this->assertSession();
    $script = <<<SCRIPT
(function() {
  return document.querySelector('div[aria-describedby="drupal-modal"]').offsetWidth;
}())
SCRIPT;
    // Open the modal dialog with POST HTTP method.
    $this->drupalGet('/ajax-test/http-methods');
    $this->clickLink('Link');
    $assert->assertWaitOnAjaxRequest();
    $assert->pageTextContains('Modal dialog contents');
    $width = $this->getSession()
        ->getDriver()
        ->evaluateScript($script);
    // The theme is adding 4px as padding and border on each side.
    $this->assertSame(808, $width);
    // Switch to GET HTTP method.
    // @see \Drupal\ajax_test\Controller\AjaxTestController::httpMethods()
    \Drupal::state()->set('ajax_test.http_method', 'GET');
    // Open the modal dialog with GET HTTP method.
    $this->drupalGet('/ajax-test/http-methods');
    $this->clickLink('Link');
    $assert->assertWaitOnAjaxRequest();
    $assert->pageTextContains('Modal dialog contents');
    $width = $this->getSession()
        ->getDriver()
        ->evaluateScript($script);
    // The theme is adding 4px as padding and border on each side.
    $this->assertSame(808, $width);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.