function UrlTransformRelativeTest::testFileUrlTransformRelative

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/File/UrlTransformRelativeTest.php \Drupal\KernelTests\Core\File\UrlTransformRelativeTest::testFileUrlTransformRelative()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/File/UrlTransformRelativeTest.php \Drupal\KernelTests\Core\File\UrlTransformRelativeTest::testFileUrlTransformRelative()
  3. 10 core/tests/Drupal/KernelTests/Core/File/UrlTransformRelativeTest.php \Drupal\KernelTests\Core\File\UrlTransformRelativeTest::testFileUrlTransformRelative()

Tests transformRelative() function.

@dataProvider providerFileUrlTransformRelative

File

core/tests/Drupal/KernelTests/Core/File/UrlTransformRelativeTest.php, line 29

Class

UrlTransformRelativeTest
Tests URL transform to relative.

Namespace

Drupal\KernelTests\Core\File

Code

public function testFileUrlTransformRelative($host, $port, $https, $base_path, $root_relative, $url, $expected) : void {
    $_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'] = $host;
    $_SERVER['REQUEST_URI'] = "{$base_path}/";
    $_SERVER['REQUEST_METHOD'] = 'GET';
    $_SERVER['SCRIPT_NAME'] = "{$base_path}/index.php";
    $_SERVER['SCRIPT_FILENAME'] = "{$base_path}/index.php";
    $_SERVER['PHP_SELF'] = "{$base_path}/index.php";
    $_SERVER['HTTP_USER_AGENT'] = 'Drupal command line';
    $_SERVER['HTTPS'] = $https;
    $request = Request::createFromGlobals();
    $request->setSession(new Session(new MockArraySessionStorage()));
    \Drupal::requestStack()->push($request);
    $this->assertSame($expected, \Drupal::service('file_url_generator')->transformRelative($url, $root_relative));
}

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