You are here

public function BrowserTestBaseTest::testGoTo in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testGoTo()

Tests basic page test.

File

core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php, line 45

Class

BrowserTestBaseTest
Tests BrowserTestBase functionality.

Namespace

Drupal\FunctionalTests

Code

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);

  // Ensure Drupal Javascript settings are not part of the page text.
  $this
    ->assertArrayHasKey('currentPathIsAdmin', $this
    ->getDrupalSettings()['path']);
  $this
    ->assertStringNotContainsString('currentPathIsAdmin', $text);

  // Response includes cache tags that we can assert.
  $this
    ->assertSession()
    ->responseHeaderExists('X-Drupal-Cache-Tags');
  $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',
  ]);
  $this
    ->assertSession()
    ->responseHeaderExists('Test-Header');
  $this
    ->assertSession()
    ->responseHeaderEquals('Test-Header', 'header value');

  // Ensure that \Drupal\Tests\UiHelperTrait::isTestUsingGuzzleClient() works
  // as expected.
  $this
    ->assertTrue($this
    ->isTestUsingGuzzleClient());
}