Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / File / UrlTransformRelativeTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\File;
4
5 use Drupal\KernelTests\KernelTestBase;
6 use Symfony\Component\HttpFoundation\Request;
7
8 /**
9  * Tests url transform to relative.
10  *
11  * @group Utility
12  */
13 class UrlTransformRelativeTest extends KernelTestBase {
14
15   public static $modules = ['file_test'];
16
17   /**
18    * Tests file_url_transform_relative function.
19    *
20    * @dataProvider providerFileUrlTransformRelative
21    */
22   public function testFileUrlTransformRelative($host, $port, $https, $url, $expected) {
23
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;
36
37     $request = Request::createFromGlobals();
38     \Drupal::requestStack()->push($request);
39
40     $this->assertSame($expected, file_url_transform_relative($url));
41   }
42
43   public function providerFileUrlTransformRelative() {
44     $data = [];
45     $data[] = [
46       'example.com',
47       80,
48       '',
49       'http://example.com/page',
50       '/page',
51     ];
52     $data[] = [
53       'example.com',
54       443,
55       'on',
56       'https://example.com/page',
57       '/page',
58     ];
59     $data[] = [
60       'example.com',
61       8080,
62       '',
63       'https://example.com:8080/page',
64       '/page',
65     ];
66     $data[] = [
67       'example.com',
68       8443,
69       'on',
70       'https://example.com:8443/page',
71       '/page',
72     ];
73     $data[] = [
74       'example.com',
75       80,
76       '',
77       'http://exampleXcom/page',
78       'http://exampleXcom/page',
79     ];
80     return $data;
81   }
82
83 }