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