public function BrowserTestBaseTest::testGoTo in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testGoTo()
Tests basic page test.
File
- core/
tests/ Drupal/ FunctionalTests/ BrowserTestBaseTest.php, line 42
Class
- BrowserTestBaseTest
- Tests BrowserTestBase functionality.
Namespace
Drupal\FunctionalTestsCode
public function testGoTo() {
$account = $this
->drupalCreateUser();
$this
->drupalLogin($account);
// Visit a Drupal page that requires login.
$this
->drupalGet('test-page');
$this
->assertSession()
->statusCodeEquals(200);
// Test page contains some text.
$this
->assertSession()
->pageTextContains('Test page text.');
// Check that returned plain text is correct.
$text = $this
->getTextContent();
$this
->assertStringContainsString('Test page text.', $text);
$this
->assertStringNotContainsString('</html>', $text);
// Response includes cache tags that we can assert.
$this
->assertSession()
->responseHeaderEquals('X-Drupal-Cache-Tags', 'http_response rendered');
// Test that we can read the JS settings.
$js_settings = $this
->getDrupalSettings();
$this
->assertSame('azAZ09();.,\\\\/-_{}', $js_settings['test-setting']);
// Test drupalGet with a url object.
$url = Url::fromRoute('test_page_test.render_title');
$this
->drupalGet($url);
$this
->assertSession()
->statusCodeEquals(200);
// Test page contains some text.
$this
->assertSession()
->pageTextContains('Hello Drupal');
// Test that setting headers with drupalGet() works.
$this
->drupalGet('system-test/header', [], [
'Test-Header' => 'header value',
]);
$returned_header = $this
->getSession()
->getResponseHeader('Test-Header');
$this
->assertSame('header value', $returned_header);
}