3 namespace Drupal\Tests\Core\Http;
4 use Drupal\Core\Http\TrustedHostsRequestFactory;
5 use Drupal\Tests\UnitTestCase;
8 * Tests the trusted hosts request factory.
10 * @coversDefaultClass \Drupal\Core\Http\TrustedHostsRequestFactory
13 class TrustedHostsRequestFactoryTest extends UnitTestCase {
16 * Tests TrustedHostsRequestFactory::createRequest().
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.
26 * @covers ::createRequest
27 * @dataProvider providerTestCreateRequest
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());
36 * Provides data for testCreateRequest().
39 * An array of test cases, where each test case is an array with the
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.
46 public function providerTestCreateRequest() {
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'];