407 lines
11 KiB
PHP
407 lines
11 KiB
PHP
<?php
|
|
|
|
/**
|
|
* DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Route;
|
|
|
|
/**
|
|
* Test the Route.php file
|
|
*/
|
|
class RouteTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
/// RELATIVE ///
|
|
/**
|
|
* Entry null
|
|
*/
|
|
public function testBaseURL1Relative()
|
|
{
|
|
$route = new Route();
|
|
$route->baseURL();
|
|
$this->expectOutputString("");
|
|
}
|
|
|
|
/**
|
|
* Port 80 and HTTP without module
|
|
*/
|
|
public function testBaseURL2Relative()
|
|
{
|
|
$_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 testBaseURL3Relative()
|
|
{
|
|
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 testBaseURL4Relative()
|
|
{
|
|
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 testBaseURL5Relative()
|
|
{
|
|
$_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 testBaseURL2ModuleRelative()
|
|
{
|
|
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 testBaseURL3ModuleRelative()
|
|
{
|
|
$_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 testBaseURL4ModuleRelative()
|
|
{
|
|
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 testBaseURL5ModuleRelative()
|
|
{
|
|
$_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 testBaseURL1Absolute()
|
|
{
|
|
$route = new Route();
|
|
$route->baseURL(false, true);
|
|
$this->expectOutputString("");
|
|
}
|
|
|
|
/**
|
|
* Port 80 and HTTP without module
|
|
*/
|
|
public function testBaseURL2Absolute()
|
|
{
|
|
$_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 testBaseURL3Absolute()
|
|
{
|
|
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 testBaseURL4Absolute()
|
|
{
|
|
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 testBaseURL5Absolute()
|
|
{
|
|
$_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 testBaseURL2ModuleAbsolute()
|
|
{
|
|
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 testBaseURL3ModuleAbsolute()
|
|
{
|
|
$_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 testBaseURL4ModuleAbsolute()
|
|
{
|
|
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 testBaseURL5ModuleAbsolute()
|
|
{
|
|
$_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 testRequestURL2Direct()
|
|
{
|
|
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 testRequestURL3Direct()
|
|
{
|
|
$_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 testRequestURL4Direct()
|
|
{
|
|
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 testRequestURL5Direct()
|
|
{
|
|
$_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 testRequestURL2Rewrite()
|
|
{
|
|
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 testRequestURL3Rewrite()
|
|
{
|
|
$_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 testRequestURL4Rewrite()
|
|
{
|
|
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 testRequestURL5Rewrite()
|
|
{
|
|
$_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 testErrorRateLimit1()
|
|
{
|
|
$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#");
|
|
}
|
|
}
|