3 namespace Drupal\KernelTests\Core\File;
5 use Drupal\KernelTests\KernelTestBase;
6 use Symfony\Component\HttpFoundation\Request;
9 * Tests url transform to relative.
13 class UrlTransformRelativeTest extends KernelTestBase {
15 public static $modules = ['file_test'];
18 * Tests file_url_transform_relative function.
20 * @dataProvider providerFileUrlTransformRelative
22 public function testFileUrlTransformRelative($host, $port, $https, $url, $expected) {
24 $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
25 $_SERVER['SERVER_ADDR'] = '127.0.0.1';
26 $_SERVER['SERVER_PORT'] = $port;
27 $_SERVER['SERVER_SOFTWARE'] = NULL;
28 $_SERVER['SERVER_NAME'] = $host;
29 $_SERVER['REQUEST_URI'] = '/';
30 $_SERVER['REQUEST_METHOD'] = 'GET';
31 $_SERVER['SCRIPT_NAME'] = '/index.php';
32 $_SERVER['SCRIPT_FILENAME'] = '/index.php';
33 $_SERVER['PHP_SELF'] = '/index.php';
34 $_SERVER['HTTP_USER_AGENT'] = 'Drupal command line';
35 $_SERVER['HTTPS'] = $https;
37 $request = Request::createFromGlobals();
38 \Drupal::requestStack()->push($request);
40 $this->assertSame($expected, file_url_transform_relative($url));
43 public function providerFileUrlTransformRelative() {
49 'http://example.com/page',
56 'https://example.com/page',
63 'https://example.com:8080/page',
70 'https://example.com:8443/page',
77 'http://exampleXcom/page',
78 'http://exampleXcom/page',