function UiHelperTrait::drupalGet
Retrieves a Drupal path or an absolute path.
Parameters
string|\Drupal\Core\Url $path: Drupal path or URL to load into Mink controlled browser.
array $options: (optional) Options to be forwarded to the URL generator.
string[] $headers: An array containing additional HTTP request headers, the array keys are the header names and the array values the header values. This is useful to set for example the "Accept-Language" header for requesting the page in a different language. Note that not all headers are supported, for example the "Accept" header is always overridden by the browser. For testing REST APIs it is recommended to obtain a separate HTTP client using getHttpClient() and performing requests that way.
Return value
string The retrieved HTML string, also available as $this->getRawContent()
See also
\Drupal\Tests\BrowserTestBase::getHttpClient()
2485 calls to UiHelperTrait::drupalGet()
- AccessDeniedTest::testAccessDenied in core/modules/ system/ tests/ src/ Functional/ System/ AccessDeniedTest.php 
- Tests access denied functionality.
- AccessDeniedTest::testAccessDeniedCustomPageWithAccessDenied in core/modules/ system/ tests/ src/ Functional/ System/ AccessDeniedTest.php 
- Tests that an inaccessible custom 403 page falls back to the default.
- AccessRoleTest::testAccessRole in core/modules/ user/ tests/ src/ Functional/ Views/ AccessRoleTest.php 
- Tests role access plugin.
- AccessTest::testStaticAccessPlugin in core/modules/ views/ tests/ src/ Functional/ Plugin/ AccessTest.php 
- Tests static access check.
- ActiveLinkTest::testQueryStringQuotes in core/modules/ system/ tests/ src/ FunctionalJavascript/ ActiveLinkTest.php 
- Ensures no JS error is thrown with query strings containing special chars.
3 methods override UiHelperTrait::drupalGet()
- MenuAccessTest::drupalGet in core/modules/ system/ tests/ src/ Functional/ Menu/ MenuAccessTest.php 
- Retrieves a Drupal path or an absolute path.
- OffCanvasTestBase::drupalGet in core/modules/ system/ tests/ src/ FunctionalJavascript/ OffCanvasTestBase.php 
- Retrieves a Drupal path or an absolute path.
- UITestBase::drupalGet in core/modules/ views_ui/ tests/ src/ Functional/ UITestBase.php 
- Retrieves a Drupal path or an absolute path.
File
- 
              core/tests/ Drupal/ Tests/ UiHelperTrait.php, line 258 
Class
- UiHelperTrait
- Provides UI helper methods.
Namespace
Drupal\TestsCode
protected function drupalGet($path, array $options = [], array $headers = []) {
  $options['absolute'] = TRUE;
  $url = $this->buildUrl($path, $options);
  $session = $this->getSession();
  $this->prepareRequest();
  foreach ($headers as $header_name => $header_value) {
    if (is_int($header_name)) {
      @trigger_error('Passing an integer as header name to ' . __METHOD__ . '() is deprecated in drupal:11.1.0 and will be removed from drupal:12.0.0. Update the calling code to pass the header name as a key. See https://www.drupal.org/node/3456178', E_USER_DEPRECATED);
      [$header_name, $header_value] = explode(':', $header_value);
    }
    if (is_null($header_value)) {
      @trigger_error('Using null as a header value to ' . __METHOD__ . '() is deprecated in drupal:11.1.0 and will be removed from drupal:12.0.0. Use an empty string instead. See https://www.drupal.org/node/3456233', E_USER_DEPRECATED);
      $header_value = '';
    }
    $session->setRequestHeader($header_name, $header_value);
  }
  $session->visit($url);
  $out = $session->getPage()
    ->getContent();
  // Ensure that any changes to variables in the other thread are picked up.
  $this->refreshVariables();
  // Replace original page output with new output from redirected page(s).
  if ($new = $this->checkForMetaRefresh()) {
    $out = $new;
    // We are finished with all meta refresh redirects, so reset the counter.
    $this->metaRefreshCount = 0;
  }
  // Log only for WebDriverTestBase tests because for BrowserKitDriver we log
  // with ::getResponseLogHandler.
  if ($this->htmlOutputEnabled && !$this->isTestUsingGuzzleClient()) {
    $html_output = 'GET request to: ' . $url . '<hr />Ending URL: ' . $this->getSession()
      ->getCurrentUrl();
    $html_output .= '<hr />' . $out;
    $html_output .= $this->getHtmlOutputHeaders();
    $this->htmlOutput($html_output);
  }
  return $out;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
