3 namespace Drupal\Tests\Core\Http;
5 use Drupal\Core\Http\TrustedHostsRequestFactory;
6 use Drupal\Tests\UnitTestCase;
9 * Tests the trusted hosts request factory.
11 * @coversDefaultClass \Drupal\Core\Http\TrustedHostsRequestFactory
14 class TrustedHostsRequestFactoryTest extends UnitTestCase {
17 * Tests TrustedHostsRequestFactory::createRequest().
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.
27 * @covers ::createRequest
28 * @dataProvider providerTestCreateRequest
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());
37 * Provides data for testCreateRequest().
40 * An array of test cases, where each test case is an array with the
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.
47 public function providerTestCreateRequest() {
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'];