Add PHPUnit tests

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1501 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-06-27 11:57:45 +00:00
parent 884da19d71
commit 052a8a8d1a
5 changed files with 186 additions and 12 deletions

View File

@@ -1,12 +0,0 @@
#!/bin/bash
#To run the tests, you need "phpunit" software.
# All the documentation is here :
# phpunit.de/manual/current/en/writing-tests-for-phpunit.html
#From the root dir of the project, run the tests like :
cd `dirname $0`/..
phpunit --bootstrap Tests/autoload.php Tests/test*
# You can run specific test with :
# cd `dirname $0`/..
# phpunit --bootstrap Tests/autoload.php Tests/testXXXXXXX.php

167
Tests/routeTest.php Normal file
View File

@@ -0,0 +1,167 @@
<?php
/** DomFramework - Tests
@package domframework
@author Dominique Fournier <dominique@fournier38.fr> */
/** Test the route.php file */
class test_route extends PHPUnit_Framework_TestCase
{
/** Entry null */
public function test_baseURL_1 ()
{
$this->expectOutputString("");
$route = new route ();
$route->baseURL ();
}
/** Port 80 and HTTP without module */
public function test_baseURL_2 ()
{
$this->expectOutputString("http://localhost/");
unset ($_SERVER);
$_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = 80;
$_SERVER["SCRIPT_NAME"] = "/index.php";
$route = new route ();
echo $route->baseURL ();
}
/** Port 443 and HTTPS without module */
public function test_baseURL_3 ()
{
$this->expectOutputString("https://localhost/");
unset ($_SERVER);
$_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = 443;
$_SERVER["HTTPS"] = true;
$_SERVER["SCRIPT_NAME"] = "/index.php";
$route = new route ();
echo $route->baseURL ();
}
/** Port 888 and HTTP without module */
public function test_baseURL_4 ()
{
$this->expectOutputString("http://localhost:888/");
unset ($_SERVER);
$_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = 888;
$_SERVER["SCRIPT_NAME"] = "/index.php";
$route = new route ();
echo $route->baseURL ();
}
/** Port 888 and HTTPS without module */
public function test_baseURL_5 ()
{
$this->expectOutputString("https://localhost:888/");
unset ($_SERVER);
$_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = 888;
$_SERVER["HTTPS"] = true;
$_SERVER["SCRIPT_NAME"] = "/index.php";
$route = new route ();
echo $route->baseURL ();
}
/** Port 80 and HTTP with module */
public function test_baseURL_2_module ()
{
$this->expectOutputString("http://localhost/");
unset ($_SERVER);
$_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = 80;
$_SERVER["SCRIPT_NAME"] = "/module/index.php";
$route = new route ();
echo $route->baseURL ("module");
}
/** Port 443 and HTTPS with module */
public function test_baseURL_3_module ()
{
$this->expectOutputString("https://localhost/");
unset ($_SERVER);
$_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = 443;
$_SERVER["HTTPS"] = true;
$_SERVER["SCRIPT_NAME"] = "/module/index.php";
$route = new route ();
echo $route->baseURL ("module");
}
/** Port 888 and HTTP with module */
public function test_baseURL_4_module ()
{
$this->expectOutputString("http://localhost:888/");
unset ($_SERVER);
$_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = 888;
$_SERVER["SCRIPT_NAME"] = "/module/index.php";
$route = new route ();
echo $route->baseURL ("module");
}
/** Port 888 and HTTPS with module */
public function test_baseURL_5_module ()
{
$this->expectOutputString("https://localhost:888/");
unset ($_SERVER);
$_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = 888;
$_SERVER["HTTPS"] = true;
$_SERVER["SCRIPT_NAME"] = "/module/index.php";
$route = new route ();
echo $route->baseURL ("module");
}
/** Port 80 and HTTP requestURL */
public function test_requestURL_2 ()
{
$this->expectOutputString("http://localhost/index.php?var=1");
unset ($_SERVER);
$_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = 80;
$_SERVER["REQUEST_URI"] = "/index.php?var=1";
$route = new route ();
echo $route->requestURL ();
}
/** Port 443 and HTTPS requestURL */
public function test_requestURL_3 ()
{
$this->expectOutputString("https://localhost/index.php?var=1");
unset ($_SERVER);
$_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = 443;
$_SERVER["HTTPS"] = true;
$_SERVER["REQUEST_URI"] = "/index.php?var=1";
$route = new route ();
echo $route->requestURL ();
}
/** Port 888 and HTTP requestURL */
public function test_requestURL_4 ()
{
$this->expectOutputString("http://localhost:888/index.php?var=1");
unset ($_SERVER);
$_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = 888;
$_SERVER["REQUEST_URI"] = "/index.php?var=1";
$route = new route ();
echo $route->requestURL ();
}
/** Port 888 and HTTPS requestURL */
public function test_requestURL_5 ()
{
$this->expectOutputString("https://localhost:888/index.php?var=1");
unset ($_SERVER);
$_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = 888;
$_SERVER["HTTPS"] = true;
$_SERVER["REQUEST_URI"] = "/index.php?var=1";
$route = new route ();
echo $route->requestURL ();
}
}

19
phpunit.xml Normal file
View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="Tests/autoload.php.dist"
>
<testsuites>
<testsuite name="DomFramework test suite">
<directory>Tests</directory>
</testsuite>
</testsuites>
</phpunit>