function BrowserTestBaseTest::testGoTo

Same name in other branches
  1. 8.9.x core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testGoTo()
  2. 10 core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php \Drupal\FunctionalTests\BrowserTestBaseTest::testGoTo()
  3. 11.x 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());
}

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