* @license BSD */ namespace Domframework\Tests; use Domframework\Route; /** Test the Route.php file */ class RouteTest extends \PHPUnit_Framework_TestCase { /// RELATIVE /// /** Entry null */ public function test_baseURL_1_relative () { $route = new Route (); $route->baseURL (); $this->expectOutputString(""); } /** Port 80 and HTTP without module */ public function test_baseURL_2_relative () { $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "80"; $_SERVER["SCRIPT_NAME"] = "/index.php"; $route = new Route (); echo $route->baseURL (); $this->expectOutputString("/"); } /** Port 443 and HTTPS without module */ public function test_baseURL_3_relative () { unset ($_SERVER["HTTPS"]); $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "443"; $_SERVER["HTTPS"] = true; $_SERVER["SCRIPT_NAME"] = "/index.php"; $route = new Route (); echo $route->baseURL (); $this->expectOutputString("/"); } /** Port 888 and HTTP without module */ public function test_baseURL_4_relative () { unset ($_SERVER["HTTPS"]); $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "888"; $_SERVER["SCRIPT_NAME"] = "/index.php"; $route = new Route (); echo $route->baseURL (); $this->expectOutputString("/"); } /** Port 888 and HTTPS without module */ public function test_baseURL_5_relative () { $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "888"; $_SERVER["HTTPS"] = true; $_SERVER["SCRIPT_NAME"] = "/index.php"; $route = new Route (); echo $route->baseURL (); $this->expectOutputString("/"); } /** Port 80 and HTTP with module */ public function test_baseURL_2_module_relative () { unset ($_SERVER["HTTPS"]); $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "80"; $_SERVER["SCRIPT_NAME"] = "/module/index.php"; $route = new Route (); echo $route->baseURL ("module"); $this->expectOutputString("/"); } /** Port 443 and HTTPS with module */ public function test_baseURL_3_module_relative () { $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "443"; $_SERVER["HTTPS"] = true; $_SERVER["SCRIPT_NAME"] = "/module/index.php"; $route = new Route (); echo $route->baseURL ("module"); $this->expectOutputString("/"); } /** Port 888 and HTTP with module */ public function test_baseURL_4_module_relative () { unset ($_SERVER["HTTPS"]); $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "888"; $_SERVER["SCRIPT_NAME"] = "/module/index.php"; $route = new Route (); echo $route->baseURL ("module"); $this->expectOutputString("/"); } /** Port 888 and HTTPS with module */ public function test_baseURL_5_module_relative () { $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "888"; $_SERVER["HTTPS"] = true; $_SERVER["SCRIPT_NAME"] = "/module/index.php"; $route = new Route (); echo $route->baseURL ("module"); $this->expectOutputString("/"); } /// ABSOLUTE /// /** Entry null */ public function test_baseURL_1_absolute () { $route = new Route (); $route->baseURL (false, true); $this->expectOutputString(""); } /** Port 80 and HTTP without module */ public function test_baseURL_2_absolute () { $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "80"; $_SERVER["SCRIPT_NAME"] = "/index.php"; $route = new Route (); echo $route->baseURL (false, true); $this->expectOutputString("https://localhost:80/"); } /** Port 443 and HTTPS without module */ public function test_baseURL_3_absolute () { unset ($_SERVER["HTTPS"]); $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "443"; $_SERVER["HTTPS"] = true; $_SERVER["SCRIPT_NAME"] = "/index.php"; $route = new Route (); echo $route->baseURL (false, true); $this->expectOutputString("https://localhost/"); } /** Port 888 and HTTP without module */ public function test_baseURL_4_absolute () { unset ($_SERVER["HTTPS"]); $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "888"; $_SERVER["SCRIPT_NAME"] = "/index.php"; $route = new Route (); echo $route->baseURL (false, true); $this->expectOutputString("http://localhost:888/"); } /** Port 888 and HTTPS without module */ public function test_baseURL_5_absolute () { $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "888"; $_SERVER["HTTPS"] = true; $_SERVER["SCRIPT_NAME"] = "/index.php"; $route = new Route (); echo $route->baseURL (false, true); $this->expectOutputString("https://localhost:888/"); } /** Port 80 and HTTP with module */ public function test_baseURL_2_module_absolute () { unset ($_SERVER["HTTPS"]); $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "80"; $_SERVER["SCRIPT_NAME"] = "/module/index.php"; $route = new Route (); echo $route->baseURL ("module", true); $this->expectOutputString("http://localhost/"); } /** Port 443 and HTTPS with module */ public function test_baseURL_3_module_absolute () { $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "443"; $_SERVER["HTTPS"] = true; $_SERVER["SCRIPT_NAME"] = "/module/index.php"; $route = new Route (); echo $route->baseURL ("module", true); $this->expectOutputString("https://localhost/"); } /** Port 888 and HTTP with module */ public function test_baseURL_4_module_absolute () { unset ($_SERVER["HTTPS"]); $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "888"; $_SERVER["SCRIPT_NAME"] = "/module/index.php"; $route = new Route (); echo $route->baseURL ("module", true); $this->expectOutputString("http://localhost:888/"); } /** Port 888 and HTTPS with module */ public function test_baseURL_5_module_absolute () { $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "888"; $_SERVER["HTTPS"] = true; $_SERVER["SCRIPT_NAME"] = "/module/index.php"; $route = new Route (); echo $route->baseURL ("module", true); $this->expectOutputString("https://localhost:888/"); } /// REQUESTURL /// /** Port 80 and HTTP requestURL */ public function test_requestURL_2_direct () { unset ($_SERVER["HTTPS"]); $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "80"; $_SERVER["SCRIPT_NAME"] = "/index.php"; $_SERVER["REQUEST_URI"] = "/index.php?url=bla"; $route = new Route (); echo $route->requestURL (); $this->expectOutputString("index.php?url=bla"); } /** Port 443 and HTTPS requestURL */ public function test_requestURL_3_direct () { $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "443"; $_SERVER["HTTPS"] = true; $_SERVER["SCRIPT_NAME"] = "/index.php"; $_SERVER["REQUEST_URI"] = "/index.php?var=1"; $route = new Route (); echo $route->requestURL (); $this->expectOutputString("index.php?var=1"); } /** Port 888 and HTTP requestURL */ public function test_requestURL_4_direct () { unset ($_SERVER["HTTPS"]); $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "888"; $_SERVER["SCRIPT_NAME"] = "/index.php"; $_SERVER["REQUEST_URI"] = "/index.php?var=1"; $route = new Route (); echo $route->requestURL (); $this->expectOutputString("index.php?var=1"); } /** Port 888 and HTTPS requestURL */ public function test_requestURL_5_direct () { $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "888"; $_SERVER["HTTPS"] = true; $_SERVER["SCRIPT_NAME"] = "/index.php"; $_SERVER["REQUEST_URI"] = "/index.php?var=1"; $route = new Route (); echo $route->requestURL (); $this->expectOutputString("index.php?var=1"); } /** Port 80 and HTTP requestURL */ public function test_requestURL_2_rewrite () { unset ($_SERVER["HTTPS"]); $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "80"; $_SERVER["SCRIPT_NAME"] = "/index.php"; $_SERVER["REQUEST_URI"] = "/bla"; $route = new Route (); echo $route->requestURL (); $this->expectOutputString("bla"); } /** Port 443 and HTTPS requestURL */ public function test_requestURL_3_rewrite () { $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "443"; $_SERVER["HTTPS"] = true; $_SERVER["SCRIPT_NAME"] = "/index.php"; $_SERVER["REQUEST_URI"] = "/var=1"; $route = new Route (); echo $route->requestURL (); $this->expectOutputString("var=1"); } /** Port 888 and HTTP requestURL */ public function test_requestURL_4_rewrite () { unset ($_SERVER["HTTPS"]); $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "888"; $_SERVER["SCRIPT_NAME"] = "/index.php"; $_SERVER["REQUEST_URI"] = "/var=1"; $route = new Route (); echo $route->requestURL (); $this->expectOutputString("var=1"); } /** Port 888 and HTTPS requestURL */ public function test_requestURL_5_rewrite () { $_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_PORT"] = "888"; $_SERVER["HTTPS"] = true; $_SERVER["SCRIPT_NAME"] = "/index.php"; $_SERVER["REQUEST_URI"] = "/var=1"; $route = new Route (); echo $route->requestURL (); $this->expectOutputString("var=1"); } /** Ratelimiting in errors */ public function test_errorRateLimit1 () { $route = new Route (); $route->ratelimiter->storageDir = "/tmp/ratelimit-".time(); $route->error (new \Exception ("test1", 500)); $route->error (new \Exception ("test2", 500)); $route->error (new \Exception ("test3", 500)); $route->error (new \Exception ("test4", 500)); $route->error (new \Exception ("test5", 500)); $route->error (new \Exception ("test6", 500)); $route->error (new \Exception ("test7", 500)); $route->error (new \Exception ("test8", 500)); $route->error (new \Exception ("test9", 500)); $route->error (new \Exception ("test0", 500)); $route->error (new \Exception ("test11", 500)); $this->expectOutputRegex("#Too much error requests#"); } }