function HttpKernelUiHelperTrait::drupalGet
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/HttpKernelUiHelperTrait.php \Drupal\Tests\HttpKernelUiHelperTrait::drupalGet()
Retrieves a Drupal path.
Requests are sent to the HTTP kernel.
Parameters
\Drupal\Core\Url|string $path: The Drupal path to load into Mink controlled browser, as a string or a Url object. (Note that the Symfony browser's functionality of paths relative to the previous request is not available, because an initial '/' is assumed if not present.)
array $options: (optional) Options to be forwarded to the URL generator. The 'absolute' option is not supported.
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 Mink's BrowserKitDriver normalizes header names to uppercase, while Symfony's HTTP classes normalize to lower case, which may cause a header to not be found with certain APIs.
Return value
string The retrieved HTML string.
See also
\Drupal\Tests\BrowserTestBase::getHttpClient()
20 calls to HttpKernelUiHelperTrait::drupalGet()
- AdminMetaTagTest::testMetaTag in core/
modules/ system/ tests/ src/ Kernel/ System/ AdminMetaTagTest.php - Verify that the meta tag HTML is generated correctly.
- ContentNegotiationTest::testBogusAcceptHeader in core/
modules/ system/ tests/ src/ Kernel/ DrupalKernel/ ContentNegotiationTest.php - Verifies HTML responses for bogus Accept headers.
- DefaultMetatagsTest::testMetaTag in core/
modules/ system/ tests/ src/ Kernel/ Page/ DefaultMetatagsTest.php - Tests meta tags.
- DefaultMobileMetaTagsTest::testDefaultMetaTagsExist in core/
modules/ system/ tests/ src/ Kernel/ System/ DefaultMobileMetaTagsTest.php - Verifies that the default mobile meta tags are added.
- DefaultMobileMetaTagsTest::testRemovingDefaultMetaTags in core/
modules/ system/ tests/ src/ Kernel/ System/ DefaultMobileMetaTagsTest.php - Verifies that the default mobile meta tags can be removed.
File
-
core/
tests/ Drupal/ Tests/ HttpKernelUiHelperTrait.php, line 67
Class
- HttpKernelUiHelperTrait
- Provides UI helper methods using the HTTP kernel to make requests.
Namespace
Drupal\TestsCode
protected function drupalGet($path, array $options = [], array $headers = []) : string {
$session = $this->getSession();
if (is_string($path) && !str_starts_with($path, '/')) {
$path = '/' . $path;
}
if (is_object($path) || $options) {
$path = $this->buildUrl($path, $options);
}
foreach ($headers as $header_name => $header_value) {
assert(is_string($header_name));
$session->setRequestHeader($header_name, $header_value);
}
$session->visit($path);
$out = $session->getPage()
->getContent();
if ($this->htmlOutputEnabled) {
$html_output = 'GET request to: ' . $path;
$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.