From: Jan Schneider Date: Tue, 21 Dec 2010 19:08:45 +0000 (+0100) Subject: Add test for selfUrl(). X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=c712764a11dee3455c9977b70dc1261fa94af42b;p=horde.git Add test for selfUrl(). --- diff --git a/framework/Core/test/Horde/Core/Autoload.php b/framework/Core/test/Horde/Core/Autoload.php index c6bef89d6..3914d9b32 100644 --- a/framework/Core/test/Horde/Core/Autoload.php +++ b/framework/Core/test/Horde/Core/Autoload.php @@ -11,18 +11,7 @@ * @link http://pear.horde.org/index.php?package=Core */ -if (!spl_autoload_functions()) { - spl_autoload_register( - create_function( - '$class', - '$filename = str_replace(array(\'::\', \'_\'), \'/\', $class);' - . '$err_mask = E_ALL ^ E_WARNING;' - . '$oldErrorReporting = error_reporting($err_mask);' - . 'include "$filename.php";' - . 'error_reporting($oldErrorReporting);' - ) - ); -} +require_once 'Horde/Test/Autoload.php'; -/** Catch strict standards */ +/* Catch strict standards */ error_reporting(E_ALL | E_STRICT); diff --git a/framework/Core/test/Horde/Core/UrlTest.php b/framework/Core/test/Horde/Core/UrlTest.php index a740bbd11..148b9a13d 100644 --- a/framework/Core/test/Horde/Core/UrlTest.php +++ b/framework/Core/test/Horde/Core/UrlTest.php @@ -1,12 +1,16 @@ * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @category Horde * @package Core * @subpackage UnitTests */ - class Horde_Core_UrlTest extends PHPUnit_Framework_TestCase { public function testUrl() @@ -285,13 +289,84 @@ class Horde_Core_UrlTest extends PHPUnit_Framework_TestCase } } } + + public function testSelfUrl() + { + $GLOBALS['registry'] = new Registry(); + $GLOBALS['browser'] = new Browser(); + $GLOBALS['conf']['server']['name'] = 'example.com'; + $GLOBALS['conf']['server']['port'] = 80; + $GLOBALS['conf']['use_ssl'] = 3; + $_COOKIE[session_name()] = 'foo'; + + // Simple script access. + $_SERVER['SCRIPT_NAME'] = '/hordeurl/test.php'; + $_SERVER['QUERY_STRING'] = ''; + $this->assertEquals('/hordeurl/test.php', (string)Horde::selfUrl()); + $this->assertEquals('/hordeurl/test.php', (string)Horde::selfUrl(true)); + $this->assertEquals('http://example.com/hordeurl/test.php', (string)Horde::selfUrl(true, false, true)); + $this->assertEquals('https://example.com/hordeurl/test.php', (string)Horde::selfUrl(true, false, true, true)); + + // No SCRIPT_NAME. + unset($_SERVER['SCRIPT_NAME']); + $_SERVER['PHP_SELF'] = '/hordeurl/test.php'; + $_SERVER['QUERY_STRING'] = ''; + $this->assertEquals('/hordeurl/test.php', (string)Horde::selfUrl()); + + // With parameters. + $_SERVER['SCRIPT_NAME'] = '/hordeurl/test.php'; + $_SERVER['QUERY_STRING'] = 'foo=bar&x=y'; + $this->assertEquals('/hordeurl/test.php', (string)Horde::selfUrl()); + $this->assertEquals('/hordeurl/test.php?foo=bar&x=y', (string)Horde::selfUrl(true)); + $this->assertEquals('http://example.com/hordeurl/test.php?foo=bar&x=y', (string)Horde::selfUrl(true, false, true)); + $this->assertEquals('https://example.com/hordeurl/test.php?foo=bar&x=y', (string)Horde::selfUrl(true, false, true, true)); + + // index.php script name. + $_SERVER['SCRIPT_NAME'] = '/hordeurl/index.php'; + $_SERVER['QUERY_STRING'] = 'foo=bar&x=y'; + $this->assertEquals('/hordeurl/', (string)Horde::selfUrl()); + $this->assertEquals('/hordeurl/?foo=bar&x=y', (string)Horde::selfUrl(true)); + $this->assertEquals('http://example.com/hordeurl/?foo=bar&x=y', (string)Horde::selfUrl(true, false, true)); + + // Directory access. + $_SERVER['SCRIPT_NAME'] = '/hordeurl/'; + $_SERVER['QUERY_STRING'] = 'foo=bar&x=y'; + $this->assertEquals('/hordeurl/', (string)Horde::selfUrl()); + $this->assertEquals('/hordeurl/?foo=bar&x=y', (string)Horde::selfUrl(true)); + $this->assertEquals('http://example.com/hordeurl/?foo=bar&x=y', (string)Horde::selfUrl(true, false, true)); + + // Path info. + $_SERVER['REQUEST_URI'] = '/hordeurl/test.php/foo/bar?foo=bar&x=y'; + $_SERVER['SCRIPT_NAME'] = '/hordeurl/test.php'; + $_SERVER['QUERY_STRING'] = 'foo=bar&x=y'; + $this->assertEquals('/hordeurl/test.php', (string)Horde::selfUrl()); + $this->assertEquals('/hordeurl/test.php/foo/bar?foo=bar&x=y', (string)Horde::selfUrl(true)); + $this->assertEquals('http://example.com/hordeurl/test.php/foo/bar?foo=bar&x=y', (string)Horde::selfUrl(true, false, true)); + + // URL rewriting. + $_SERVER['REQUEST_URI'] = '/hordeurl/test/foo/bar?foo=bar&x=y'; + $_SERVER['SCRIPT_NAME'] = '/hordeurl/test/index.php'; + $_SERVER['QUERY_STRING'] = 'foo=bar&x=y'; + $this->assertEquals('/hordeurl/test/', (string)Horde::selfUrl()); + $this->assertEquals('/hordeurl/test/foo/bar?foo=bar&x=y', (string)Horde::selfUrl(true)); + $this->assertEquals('http://example.com/hordeurl/test/foo/bar?foo=bar&x=y', (string)Horde::selfUrl(true, false, true)); + $_SERVER['REQUEST_URI'] = '/hordeurl/foo/bar?foo=bar&x=y'; + $_SERVER['SCRIPT_NAME'] = '/hordeurl/test.php'; + $this->assertEquals('/hordeurl/test.php', (string)Horde::selfUrl()); + $this->assertEquals('/hordeurl/foo/bar?foo=bar&x=y', (string)Horde::selfUrl(true)); + } } class Registry { - - function get() + public function get() { return '/hordeurl'; } +} +class Browser { + public function hasQuirk() + { + return false; + } }