http.php

Same filename in other branches
  1. 7.x modules/simpletest/tests/http.php
  2. 9 core/modules/system/tests/http.php
  3. 8.9.x core/modules/system/tests/http.php
  4. 11.x core/modules/system/tests/http.php

Fake an HTTP request, for use during testing.

File

core/modules/system/tests/http.php

View source
<?php


/**
 * @file
 * Fake an HTTP request, for use during testing.
 */
use Drupal\Core\Test\TestKernel;
use Symfony\Component\HttpFoundation\Request;
chdir('../../../..');
$autoloader = (require_once 'autoload.php');
// Change to HTTP.
$_SERVER['HTTPS'] = NULL;
ini_set('session.cookie_secure', FALSE);
foreach ($_SERVER as &$value) {
    // Because HTTPS is null.
    $value = $value ? str_replace('core/modules/system/tests/http.php', 'index.php', $value) : "";
    $value = $value ? str_replace('https://', 'http://', $value) : "";
}
$kernel = new TestKernel('testing', $autoloader, TRUE);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

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