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

Commit

Permalink
Add test to verify Scheme retrieval is correct
Browse files Browse the repository at this point in the history
This adds the test and the CHANGELOG-entry for the changed method
  • Loading branch information
heiglandreas authored and weierophinney committed Jul 10, 2019
1 parent 0c4e083 commit 46dbee3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

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

## 2.1.2 - 2019-04-29

Expand Down
72 changes: 72 additions & 0 deletions test/functions/MarshalUriFromSapiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* @see https://github.com/zendframework/zend-diactoros for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
*/

declare(strict_types = 1);

namespace ZendTest\Diactoros\functions;

use PHPUnit\Framework\TestCase;
use function Zend\Diactoros\marshalUriFromSapi;

class MarshalUriFromSapiTest extends TestCase
{
/** @dataProvider returnsUrlWithCorrectHttpSchemeFromArraysProvider */
public function testReturnsUrlWithCorrectHttpSchemeFromArrays(string $httpsValue, string $expectedScheme) : void
{
$server = [
"HTTPS" => $httpsValue,
"SERVER_NAME"=> "localhost",
"SERVER_PORT"=>"80",
"SERVER_ADDR"=> "172.22.0.4",
"REMOTE_PORT"=> "36852",
"REMOTE_ADDR" => "172.22.0.1",
"SERVER_SOFTWARE" => "nginx/1.11.8",
"GATEWAY_INTERFACE" => "CGI/1.1",
"SERVER_PROTOCOL" => "HTTP/1.1",
"DOCUMENT_ROOT" => "/var/www/public",
"DOCUMENT_URI" => "/index.php",
"REQUEST_URI" => "/api/messagebox-schema",
"PATH_TRANSLATED" => "/var/www/public",
"PATH_INFO" => "",
"SCRIPT_NAME" => "/index.php",
"CONTENT_LENGTH" => "",
"CONTENT_TYPE" => "",
"REQUEST_METHOD" => "GET",
"QUERY_STRING" => "",
"SCRIPT_FILENAME" => "/var/www/public/index.php",
"FCGI_ROLE" => "RESPONDER",
"PHP_SELF" => "/index.php",
];

$headers = [
"HTTP_COOKIE" => '',
"HTTP_ACCEPT_LANGUAGE" => "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
"HTTP_ACCEPT_ENCODING" => "gzip, deflate, br",
"HTTP_REFERER" => "http://localhost:8080/index.html",
"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",
"HTTP_ACCEPT" => "application/json,*/*",
"HTTP_CONNECTION" => "keep-alive",
"HTTP_HOST" => "localhost:8080",
];

$url = marshalUriFromSapi($server, $headers);

self::assertSame($expectedScheme, $url->getScheme());
}

public function returnsUrlWithCorrectHttpSchemeFromArraysProvider() : array
{
return [
'on-lowercase' => ['on', 'https'],
'on-uppercase' => ['ON', 'https'],
'off-lowercase' => ['off', 'http'],
'off-mixed-case' => ['oFf', 'http'],
'neither-on-nor-off' => ['foo', 'http'],
'empty' => ['', 'http'],
];
}
}

0 comments on commit 46dbee3

Please sign in to comment.