function FunctionalTestSetupTrait::setupBaseUrl

Same name in other branches
  1. 9 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::setupBaseUrl()
  2. 10 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::setupBaseUrl()
  3. 11.x core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::setupBaseUrl()

Sets up the base URL based upon the environment variable.

Throws

\Exception Thrown when no SIMPLETEST_BASE_URL environment variable is provided.

5 calls to FunctionalTestSetupTrait::setupBaseUrl()
BrowserTestBase::setUp in core/tests/Drupal/Tests/BrowserTestBase.php
InstallerTestBase::setUp in core/tests/Drupal/FunctionalTests/Installer/InstallerTestBase.php
SelectProfileFormTest::setUp in core/tests/Drupal/FunctionalJavascriptTests/Core/Installer/Form/SelectProfileFormTest.php
TestSiteInstallCommand::setup in core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php
Creates a test drupal installation.
UpdatePathTestBase::setUp in core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php
Overrides WebTestBase::setUp() for update testing.

File

core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php, line 575

Class

FunctionalTestSetupTrait
Defines a trait for shared functional test setup functionality.

Namespace

Drupal\Core\Test

Code

protected function setupBaseUrl() {
    global $base_url;
    // Get and set the domain of the environment we are running our test
    // coverage against.
    $base_url = getenv('SIMPLETEST_BASE_URL');
    if (!$base_url) {
        throw new \Exception('You must provide a SIMPLETEST_BASE_URL environment variable to run some PHPUnit based functional tests.');
    }
    // Setup $_SERVER variable.
    $parsed_url = parse_url($base_url);
    $host = $parsed_url['host'] . (isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '');
    $path = isset($parsed_url['path']) ? rtrim(rtrim($parsed_url['path']), '/') : '';
    $port = isset($parsed_url['port']) ? $parsed_url['port'] : 80;
    $this->baseUrl = $base_url;
    // If the passed URL schema is 'https' then setup the $_SERVER variables
    // properly so that testing will run under HTTPS.
    if ($parsed_url['scheme'] === 'https') {
        $_SERVER['HTTPS'] = 'on';
    }
    $_SERVER['HTTP_HOST'] = $host;
    $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
    $_SERVER['SERVER_ADDR'] = '127.0.0.1';
    $_SERVER['SERVER_PORT'] = $port;
    $_SERVER['SERVER_SOFTWARE'] = NULL;
    $_SERVER['SERVER_NAME'] = 'localhost';
    $_SERVER['REQUEST_URI'] = $path . '/';
    $_SERVER['REQUEST_METHOD'] = 'GET';
    $_SERVER['SCRIPT_NAME'] = $path . '/index.php';
    $_SERVER['SCRIPT_FILENAME'] = $path . '/index.php';
    $_SERVER['PHP_SELF'] = $path . '/index.php';
    $_SERVER['HTTP_USER_AGENT'] = 'Drupal command line';
}

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