[BUGFIX] Restore getUrl support for list of headers
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / UnitDeprecated / Utility / GeneralUtilityTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Utility;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use Prophecy\Argument;
19 use Psr\Http\Message\ResponseInterface;
20 use Psr\Http\Message\StreamInterface;
21 use TYPO3\CMS\Core\Http\RequestFactory;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24
25 /**
26 * Testcase for the \TYPO3\CMS\Core\Utility\ClientUtility class.
27 */
28 class GeneralUtilityTest extends UnitTestCase
29 {
30 public function splitHeaderLinesDataProvider(): array
31 {
32 return [
33 'one-line, single header' => [
34 ['Content-Security-Policy:default-src \'self\'; img-src https://*; child-src \'none\';'],
35 ['Content-Security-Policy' => 'default-src \'self\'; img-src https://*; child-src \'none\';']
36 ],
37 'one-line, multiple headers' => [
38 [
39 'Content-Security-Policy:default-src \'self\'; img-src https://*; child-src \'none\';',
40 'Content-Security-Policy-Report-Only:default-src https:; report-uri /csp-violation-report-endpoint/'
41 ],
42 [
43 'Content-Security-Policy' => 'default-src \'self\'; img-src https://*; child-src \'none\';',
44 'Content-Security-Policy-Report-Only' => 'default-src https:; report-uri /csp-violation-report-endpoint/'
45 ]
46 ]
47 ];
48 }
49
50 /**
51 * @test
52 * @dataProvider splitHeaderLinesDataProvider
53 * @param array $headers
54 * @param array $expectedHeaders
55 */
56 public function splitHeaderLines(array $headers, array $expectedHeaders): void
57 {
58 $stream = $this->prophesize(StreamInterface::class);
59 $response = $this->prophesize(ResponseInterface::class);
60 $response->getBody()->willReturn($stream);
61 $requestFactory = $this->prophesize(RequestFactory::class);
62 $requestFactory->request(Argument::cetera())->willReturn($response);
63
64 GeneralUtility::addInstance(RequestFactory::class, $requestFactory->reveal());
65 GeneralUtility::getUrl('http://example.com', 0, $headers);
66
67 $requestFactory->request(Argument::any(), Argument::any(), ['headers' => $expectedHeaders])
68 ->shouldHaveBeenCalled();
69 }
70 }