Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 46dbee3

Browse files
heiglandreasweierophinney
authored andcommitted
Add test to verify Scheme retrieval is correct
This adds the test and the CHANGELOG-entry for the changed method
1 parent 0c4e083 commit 46dbee3

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ All notable changes to this project will be documented in this file, in reverse
2222

2323
### Fixed
2424

25-
- Nothing.
25+
- [#363](https://github.com/zendframework/zend-diactoros/issues/363) modifies detection of HTTPS schemas via the `$_SERVER['HTTPS']` value
26+
such that an empty HTTPS-key will result in a scheme of `http` and not
27+
`https`.
2628

2729
## 2.1.2 - 2019-04-29
2830

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
declare(strict_types = 1);
9+
10+
namespace ZendTest\Diactoros\functions;
11+
12+
use PHPUnit\Framework\TestCase;
13+
use function Zend\Diactoros\marshalUriFromSapi;
14+
15+
class MarshalUriFromSapiTest extends TestCase
16+
{
17+
/** @dataProvider returnsUrlWithCorrectHttpSchemeFromArraysProvider */
18+
public function testReturnsUrlWithCorrectHttpSchemeFromArrays(string $httpsValue, string $expectedScheme) : void
19+
{
20+
$server = [
21+
"HTTPS" => $httpsValue,
22+
"SERVER_NAME"=> "localhost",
23+
"SERVER_PORT"=>"80",
24+
"SERVER_ADDR"=> "172.22.0.4",
25+
"REMOTE_PORT"=> "36852",
26+
"REMOTE_ADDR" => "172.22.0.1",
27+
"SERVER_SOFTWARE" => "nginx/1.11.8",
28+
"GATEWAY_INTERFACE" => "CGI/1.1",
29+
"SERVER_PROTOCOL" => "HTTP/1.1",
30+
"DOCUMENT_ROOT" => "/var/www/public",
31+
"DOCUMENT_URI" => "/index.php",
32+
"REQUEST_URI" => "/api/messagebox-schema",
33+
"PATH_TRANSLATED" => "/var/www/public",
34+
"PATH_INFO" => "",
35+
"SCRIPT_NAME" => "/index.php",
36+
"CONTENT_LENGTH" => "",
37+
"CONTENT_TYPE" => "",
38+
"REQUEST_METHOD" => "GET",
39+
"QUERY_STRING" => "",
40+
"SCRIPT_FILENAME" => "/var/www/public/index.php",
41+
"FCGI_ROLE" => "RESPONDER",
42+
"PHP_SELF" => "/index.php",
43+
];
44+
45+
$headers = [
46+
"HTTP_COOKIE" => '',
47+
"HTTP_ACCEPT_LANGUAGE" => "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
48+
"HTTP_ACCEPT_ENCODING" => "gzip, deflate, br",
49+
"HTTP_REFERER" => "http://localhost:8080/index.html",
50+
"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",
51+
"HTTP_ACCEPT" => "application/json,*/*",
52+
"HTTP_CONNECTION" => "keep-alive",
53+
"HTTP_HOST" => "localhost:8080",
54+
];
55+
56+
$url = marshalUriFromSapi($server, $headers);
57+
58+
self::assertSame($expectedScheme, $url->getScheme());
59+
}
60+
61+
public function returnsUrlWithCorrectHttpSchemeFromArraysProvider() : array
62+
{
63+
return [
64+
'on-lowercase' => ['on', 'https'],
65+
'on-uppercase' => ['ON', 'https'],
66+
'off-lowercase' => ['off', 'http'],
67+
'off-mixed-case' => ['oFf', 'http'],
68+
'neither-on-nor-off' => ['foo', 'http'],
69+
'empty' => ['', 'http'],
70+
];
71+
}
72+
}

0 commit comments

Comments
 (0)