|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @see https://github.com/zendframework/zend-diactoros for the canonical source repository |
| 4 | + * @copyright Copyright (c) 2018 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 | + /** @dataProvider returnsUrlWithCorrectHttpSchemeFromArraysProvider */ |
| 16 | + public function testReturnsUrlWithCorrectHttpSchemeFromArrays(string $httpsValue, string $expectedScheme) : void |
| 17 | + { |
| 18 | + $server = [ |
| 19 | + "HTTPS" => $httpsValue, |
| 20 | + "SERVER_NAME"=> "localhost", |
| 21 | + "SERVER_PORT"=>"80", |
| 22 | + "SERVER_ADDR"=> "172.22.0.4", |
| 23 | + "REMOTE_PORT"=> "36852", |
| 24 | + "REMOTE_ADDR" => "172.22.0.1", |
| 25 | + "SERVER_SOFTWARE" => "nginx/1.11.8", |
| 26 | + "GATEWAY_INTERFACE" => "CGI/1.1", |
| 27 | + "SERVER_PROTOCOL" => "HTTP/1.1", |
| 28 | + "DOCUMENT_ROOT" => "/var/www/public", |
| 29 | + "DOCUMENT_URI" => "/index.php", |
| 30 | + "REQUEST_URI" => "/api/messagebox-schema", |
| 31 | + "PATH_TRANSLATED" => "/var/www/public", |
| 32 | + "PATH_INFO" => "", |
| 33 | + "SCRIPT_NAME" => "/index.php", |
| 34 | + "CONTENT_LENGTH" => "", |
| 35 | + "CONTENT_TYPE" => "", |
| 36 | + "REQUEST_METHOD" => "GET", |
| 37 | + "QUERY_STRING" => "", |
| 38 | + "SCRIPT_FILENAME" => "/var/www/public/index.php", |
| 39 | + "FCGI_ROLE" => "RESPONDER", |
| 40 | + "PHP_SELF" => "/index.php", |
| 41 | + ]; |
| 42 | + |
| 43 | + $headers = [ |
| 44 | + "HTTP_COOKIE" => '', |
| 45 | + "HTTP_ACCEPT_LANGUAGE" => "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7", |
| 46 | + "HTTP_ACCEPT_ENCODING" => "gzip, deflate, br", |
| 47 | + "HTTP_REFERER" => "http://localhost:8080/index.html", |
| 48 | + "HTTP_USER_AGENT" => "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/67.0.3396.99 Chrome/67.0.3396.99 Safari/537.36", |
| 49 | + "HTTP_ACCEPT" => "application/json,*/*", |
| 50 | + "HTTP_CONNECTION" => "keep-alive", |
| 51 | + "HTTP_HOST" => "localhost:8080", |
| 52 | + ]; |
| 53 | + |
| 54 | + $url = marshalUriFromSapi($server, $headers); |
| 55 | + |
| 56 | + self::assertSame($expectedScheme, $url->getScheme()); |
| 57 | + } |
| 58 | + |
| 59 | + public function returnsUrlWithCorrectHttpSchemeFromArraysProvider() : array |
| 60 | + { |
| 61 | + return [ |
| 62 | + 'on-lowercase' => ['on', 'https'], |
| 63 | + 'on-uppercase' => ['ON', 'https'], |
| 64 | + 'off-lowercase' => ['off', 'http'], |
| 65 | + 'off-mixed-case' => ['oFf', 'http'], |
| 66 | + 'neither-on-nor-off' => ['foo', 'http'], |
| 67 | + 'empty' => ['', 'http'], |
| 68 | + ]; |
| 69 | + } |
| 70 | +} |
0 commit comments