Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Http / TrustedHostsRequestFactoryTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Http;
4
5 use Drupal\Core\Http\TrustedHostsRequestFactory;
6 use Drupal\Tests\UnitTestCase;
7
8 /**
9  * Tests the trusted hosts request factory.
10  *
11  * @coversDefaultClass \Drupal\Core\Http\TrustedHostsRequestFactory
12  * @group Http
13  */
14 class TrustedHostsRequestFactoryTest extends UnitTestCase {
15
16   /**
17    * Tests TrustedHostsRequestFactory::createRequest().
18    *
19    * @param string $host
20    *   The host to pass into TrustedHostsRequestFactory.
21    * @param array $server
22    *   The server array to pass into
23    *   TrustedHostsRequestFactory::createRequest().
24    * @param string $expected
25    *   The expected host of the created request.
26    *
27    * @covers ::createRequest
28    * @dataProvider providerTestCreateRequest
29    */
30   public function testCreateRequest($host, $server, $expected) {
31     $request_factory = new TrustedHostsRequestFactory($host);
32     $request = $request_factory->createRequest([], [], [], [], [], $server, []);
33     $this->assertEquals($expected, $request->getHost());
34   }
35
36   /**
37    * Provides data for testCreateRequest().
38    *
39    * @return array
40    *   An array of test cases, where each test case is an array with the
41    *   following values:
42    *   - A string containing the host to pass into TrustedHostsRequestFactory.
43    *   - An array containing the server array to pass into
44    *   TrustedHostsRequestFactory::createRequest().
45    *   - A string containing the expected host of the created request.
46    */
47   public function providerTestCreateRequest() {
48     $tests = [];
49     $tests[] = ['example.com', [], 'example.com'];
50     $tests[] = ['localhost', [], 'localhost'];
51     $tests[] = ['localhost', ['HTTP_HOST' => 'localhost'], 'localhost'];
52     $tests[] = ['example.com', ['HTTP_HOST' => 'localhost'], 'example.com'];
53     return $tests;
54   }
55
56 }