|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @see https://github.com/zendframework/zend-diactoros for the canonical source repository |
| 4 | + * @copyright Copyright (c) 2019 Zend Technologies USA Inc. (http://www.zend.com) |
| 5 | + * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License |
| 6 | + */ |
| 7 | + |
| 8 | +namespace ZendTest\Diactoros\functions; |
| 9 | + |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | +use function Zend\Diactoros\marshalUriFromSapi; |
| 12 | + |
| 13 | +class MarshalUriFromSapiTest extends TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @param string $httpsValue |
| 17 | + * @param string $expectedScheme |
| 18 | + * @dataProvider returnsUrlWithCorrectHttpSchemeFromArraysProvider |
| 19 | + */ |
| 20 | + public function testReturnsUrlWithCorrectHttpSchemeFromArrays($httpsValue, $expectedScheme) |
| 21 | + { |
| 22 | + $server = [ |
| 23 | + 'HTTPS' => $httpsValue, |
| 24 | + 'SERVER_NAME' => 'localhost', |
| 25 | + 'SERVER_PORT' => '80', |
| 26 | + 'SERVER_ADDR' => '172.22.0.4', |
| 27 | + 'REMOTE_PORT' => '36852', |
| 28 | + 'REMOTE_ADDR' => '172.22.0.1', |
| 29 | + 'SERVER_SOFTWARE' => 'nginx/1.11.8', |
| 30 | + 'GATEWAY_INTERFACE' => 'CGI/1.1', |
| 31 | + 'SERVER_PROTOCOL' => 'HTTP/1.1', |
| 32 | + 'DOCUMENT_ROOT' => '/var/www/public', |
| 33 | + 'DOCUMENT_URI' => '/index.php', |
| 34 | + 'REQUEST_URI' => '/api/messagebox-schema', |
| 35 | + 'PATH_TRANSLATED' => '/var/www/public', |
| 36 | + 'PATH_INFO' => '', |
| 37 | + 'SCRIPT_NAME' => '/index.php', |
| 38 | + 'CONTENT_LENGTH' => '', |
| 39 | + 'CONTENT_TYPE' => '', |
| 40 | + 'REQUEST_METHOD' => 'GET', |
| 41 | + 'QUERY_STRING' => '', |
| 42 | + 'SCRIPT_FILENAME' => '/var/www/public/index.php', |
| 43 | + 'FCGI_ROLE' => 'RESPONDER', |
| 44 | + 'PHP_SELF' => '/index.php', |
| 45 | + ]; |
| 46 | + |
| 47 | + $headers = [ |
| 48 | + 'HTTP_COOKIE' => '', |
| 49 | + 'HTTP_ACCEPT_LANGUAGE' => 'de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7', |
| 50 | + 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br', |
| 51 | + 'HTTP_REFERER' => 'http://localhost:8080/index.html', |
| 52 | + 'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)', |
| 53 | + 'HTTP_ACCEPT' => 'application/json,*/*', |
| 54 | + 'HTTP_CONNECTION' => 'keep-alive', |
| 55 | + 'HTTP_HOST' => 'localhost:8080', |
| 56 | + ]; |
| 57 | + |
| 58 | + $url = marshalUriFromSapi($server, $headers); |
| 59 | + |
| 60 | + self::assertSame($expectedScheme, $url->getScheme()); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @return array |
| 65 | + */ |
| 66 | + public function returnsUrlWithCorrectHttpSchemeFromArraysProvider() |
| 67 | + { |
| 68 | + return [ |
| 69 | + 'on-lowercase' => ['on', 'https'], |
| 70 | + 'on-uppercase' => ['ON', 'https'], |
| 71 | + 'off-lowercase' => ['off', 'http'], |
| 72 | + 'off-mixed-case' => ['oFf', 'http'], |
| 73 | + 'neither-on-nor-off' => ['foo', 'http'], |
| 74 | + 'empty' => ['', 'http'], |
| 75 | + ]; |
| 76 | + } |
| 77 | +} |
0 commit comments