From 6c59336f4a8adb5cc31934b04409ed0d54b5fbb4 Mon Sep 17 00:00:00 2001 From: Christian A. Weber Date: Mon, 6 Jun 2016 19:03:33 +0200 Subject: add 2nd parameter to it_url::absolute() to force a protocol --- tests/it_url.t | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'tests/it_url.t') diff --git a/tests/it_url.t b/tests/it_url.t index b6569b1..00052d6 100755 --- a/tests/it_url.t +++ b/tests/it_url.t @@ -71,30 +71,50 @@ is( 'punycode $url->realhostname' ); -$_SERVER['HTTP_HOST'] = "gna.ch"; +# it_url::absolute() tests +list ($_SERVER['HTTP_HOST'], $_SERVER['SERVER_PORT'], $_SERVER['HTTPS']) = ["gna.ch", null, null]; is( it_url::absolute("/"), 'http://gna.ch/', 'it_url::absolute basic' ); -$_SERVER['SERVER_PORT'] = 42; -$_SERVER['HTTP_HOST'] = "gna.ch:42"; +list ($_SERVER['HTTP_HOST'], $_SERVER['SERVER_PORT'], $_SERVER['HTTPS']) = ["gna.ch:42", 42, null]; is( it_url::absolute("/port"), 'http://gna.ch:42/port', 'it_url::absolute with non-standard port' ); -$_SERVER['HTTPS'] = true; -$_SERVER['HTTP_HOST'] = "gna.ch"; -$_SERVER['SERVER_PORT'] = 443; +list ($_SERVER['HTTP_HOST'], $_SERVER['SERVER_PORT'], $_SERVER['HTTPS']) = ["gna.ch", 443, true]; is( it_url::absolute("/https"), 'https://gna.ch/https', 'it_url::absolute for https' ); +list ($_SERVER['HTTP_HOST'], $_SERVER['SERVER_PORT'], $_SERVER['HTTPS']) = ["gna.ch", null, null]; +is( + it_url::absolute("/https", "https"), + 'https://gna.ch/https', + 'it_url::absolute force https in http context' +); + +list ($_SERVER['HTTP_HOST'], $_SERVER['SERVER_PORT'], $_SERVER['HTTPS']) = ["gna.ch", 443, true]; +is( + it_url::absolute("/foo", "http"), + 'http://gna.ch/foo', + 'it_url::absolute force http in https context' +); + +list ($_SERVER['HTTP_HOST'], $_SERVER['SERVER_PORT'], $_SERVER['HTTPS']) = ["gna.ch", null, null]; +is( + it_url::absolute("http://gna.ch/foo", "https"), + 'https://gna.ch/foo', + 'it_url::absolute force https overwriting existing url' +); + + $url = new it_url('http://www.gna.ch/'); $page = $url->get(); ok( -- cgit v1.2.3