More complete test case

This commit is contained in:
Laurent Destailleur 2013-10-23 17:44:54 +02:00
parent a7ef6e5d70
commit 6e37e75755

View File

@ -26,7 +26,7 @@
global $conf,$user,$langs,$db; global $conf,$user,$langs,$db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
require_once 'PHPUnit/Autoload.php'; require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; //require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
@ -69,7 +69,7 @@ class CoreTest extends PHPUnit_Framework_TestCase
$this->savlangs=$langs; $this->savlangs=$langs;
$this->savdb=$db; $this->savdb=$db;
print __METHOD__." db->type=".$db->type." user->id=".$user->id; //print __METHOD__." db->type=".$db->type." user->id=".$user->id;
//print " - db ".$db->db; //print " - db ".$db->db;
print "\n"; print "\n";
} }
@ -135,78 +135,94 @@ class CoreTest extends PHPUnit_Framework_TestCase
global $dolibarr_main_db_type; global $dolibarr_main_db_type;
global $dolibarr_main_db_prefix; global $dolibarr_main_db_prefix;
$testtodo=3;
// Case 1: // Case 1:
// Test for subdir dolibarr (that point to htdocs) in root directory /var/www // Test for subdir dolibarrnew (that point to htdocs) in root directory /var/www
// URL: http://localhost/dolibarrnew/admin/system/phpinfo.php // URL: http://localhost/dolibarrnew/admin/system/phpinfo.php
// To prepare this test:
// - Create link from htdocs to /var/www/dolibarrnew
// - Put into conf.php $dolibarr_main_document_root='/var/www/dolibarrnew';
if ($testtodo == 1)
{
$_SERVER["HTTPS"]=''; $_SERVER["HTTPS"]='';
$_SERVER["SERVER_NAME"]='localhost'; $_SERVER["SERVER_NAME"]='localhost';
$_SERVER["SERVER_PORT"]='80'; $_SERVER["SERVER_PORT"]='80';
$_SERVER["DOCUMENT_ROOT"]='/var/www'; $_SERVER["DOCUMENT_ROOT"]='/var/www';
$_SERVER["SCRIPT_NAME"]='/dolibarrnew/admin/system/phpinfo.php'; $_SERVER["SCRIPT_NAME"]='/dolibarrnew/admin/system/phpinfo.php';
$expectedresult='/dolibarrnew'; $expectedresult='/dolibarrnew';
}
// Case 2: // Case 2:
// Test for subdir aaa (that point to dolibarr) in root directory /var/www // Test for subdir aaa (that point to dolibarr) in root directory /var/www
// URL: http://localhost/aaa/htdocs/admin/system/phpinfo.php // URL: http://localhost/aaa/htdocs/admin/system/phpinfo.php
// To prepare this test:
// - Create link from dolibarr to /var/www/aaa
// - Put into conf.php $dolibarr_main_document_root='/var/www/aaa/htdocs';
if ($testtodo == 2)
{
$_SERVER["HTTPS"]=''; $_SERVER["HTTPS"]='';
$_SERVER["SERVER_NAME"]='localhost'; $_SERVER["SERVER_NAME"]='localhost';
$_SERVER["SERVER_PORT"]='80'; $_SERVER["SERVER_PORT"]='80';
$_SERVER["DOCUMENT_ROOT"]='/var/www'; $_SERVER["DOCUMENT_ROOT"]='/var/www';
$_SERVER["SCRIPT_NAME"]='/aaa/htdocs/admin/system/phpinfo.php'; $_SERVER["SCRIPT_NAME"]='/aaa/htdocs/admin/system/phpinfo.php';
$expectedresult='/aaa/htdocs'; $expectedresult='/aaa/htdocs';
}
// Case 3: // Case 3:
// Test for virtual host localhostdolibarrnew that point to htdocs directory with // Test for virtual host localhostdolibarrnew that point to htdocs directory with
// a direct document root // a direct document root
// URL: http://localhostdolibarrnew/admin/system/phpinfo.php // URL: http://localhostdolibarrnew/admin/system/phpinfo.php
// To prepare this test:
// - Create virtual host localhostdolibarrnew that point to /home/ldestailleur/git/dolibarr/htdocs
// - Put into conf.php $dolibarr_main_document_root='/home/ldestailleur/git/dolibarr/htdocs';
if ($testtodo == 3)
{
$_SERVER["HTTPS"]=''; $_SERVER["HTTPS"]='';
$_SERVER["SERVER_NAME"]='localhostdolibarrnew'; $_SERVER["SERVER_NAME"]='localhostdolibarrnew';
$_SERVER["SERVER_PORT"]='80'; $_SERVER["SERVER_PORT"]='80';
$_SERVER["DOCUMENT_ROOT"]='/home/ldestail/workspace/dolibarr/htdocs'; $_SERVER["DOCUMENT_ROOT"]='/home/ldestailleur/git/dolibarr/htdocs';
$_SERVER["SCRIPT_NAME"]='/admin/system/phpinfo.php'; $_SERVER["SCRIPT_NAME"]='/admin/system/phpinfo.php';
$expectedresult=''; $expectedresult='';
}
// Case 4: // Case 4:
// Test for virtual host localhostdolibarrnew that point to htdocs directory with // Test for virtual host localhostdolibarrnew that point to htdocs directory with
// a symbolic link // a symbolic link
// URL: http://localhostdolibarrnew/admin/system/phpinfo.php // URL: http://localhostdolibarrnew/admin/system/phpinfo.php
if ($testtodo == 4)
{
$_SERVER["HTTPS"]=''; $_SERVER["HTTPS"]='';
$_SERVER["SERVER_NAME"]='localhostdolibarrnew'; $_SERVER["SERVER_NAME"]='localhostdolibarrnew';
$_SERVER["SERVER_PORT"]='80'; $_SERVER["SERVER_PORT"]='80';
$_SERVER["DOCUMENT_ROOT"]='/var/www/dolibarr'; // This is a link that point to /home/ldestail/workspace/dolibarr/htdocs $_SERVER["DOCUMENT_ROOT"]='/var/www/dolibarr'; // This is a link that point to /home/ldestail/workspace/dolibarr/htdocs
$_SERVER["SCRIPT_NAME"]='/admin/system/phpinfo.php'; $_SERVER["SCRIPT_NAME"]='/admin/system/phpinfo.php';
$expectedresult=''; $expectedresult='';
}
// Case 5: // Case 5:
// Test for alias /dolibarralias // Test for alias /dolibarralias, Test when using nginx, Test when using lighttpd
// URL: http://localhost/dolibarralias/admin/system/phpinfo.php // URL: http://localhost/dolibarralias/admin/system/phpinfo.php
// To prepare this test:
// - Copy content of dolibarr project into /var/www/dolibarr
// - Put into conf.php $dolibarr_main_document_root='/var/www/dolibarr/htdocs';
// - Put into conf.php $dolibarr_main_url_root='http://localhost/dolibarralias'; (because autodetect will fails in this case)
if ($testtodo == 5)
{
$_SERVER["HTTPS"]=''; $_SERVER["HTTPS"]='';
$_SERVER["SERVER_NAME"]='localhost'; $_SERVER["SERVER_NAME"]='localhost';
$_SERVER["SERVER_PORT"]='80'; $_SERVER["SERVER_PORT"]='80';
$_SERVER["DOCUMENT_ROOT"]='/var/www'; $_SERVER["DOCUMENT_ROOT"]='/var/www';
$_SERVER["SCRIPT_NAME"]='/dolibarralias/admin/system/phpinfo.php'; $_SERVER["SCRIPT_NAME"]='/dolibarralias/admin/system/phpinfo.php';
$expectedresult='/dolibarralias'; $expectedresult='/dolibarralias';
// Put this into conf.php because autodetect will fails in this case }
//$dolibarr_main_url_root='http://localhost/dolibarralias';
// Case 6:
// Test when using nginx
// URL: https://localhost/dolibarr/admin/system/phpinfo.php
$_SERVER["HTTPS"]='';
$_SERVER["SERVER_NAME"]='localhost';
$_SERVER["SERVER_PORT"]='80';
$_SERVER["DOCUMENT_ROOT"]='/var/www/dolibarr/htdocs';
$_SERVER["SCRIPT_NAME"]='/dolibarr/admin/system/phpinfo.php';
$expectedresult='/dolibarr';
// Put this into conf.php because autodetect will fails in this case
//$dolibarr_main_url_root='http://localhost/dolibarr';
// Force to rerun filefunc.inc.php // Force to rerun filefunc.inc.php
include dirname(__FILE__).'/../../htdocs/filefunc.inc.php'; include dirname(__FILE__).'/../../htdocs/filefunc.inc.php';
print __METHOD__." DOL_MAIN_URL_ROOT=".DOL_MAIN_URL_ROOT."\n"; print __METHOD__." DOL_MAIN_URL_ROOT=".DOL_MAIN_URL_ROOT."\n";
print __METHOD__." DOL_URL_ROOT=".DOL_URL_ROOT."\n"; print __METHOD__." DOL_URL_ROOT=".DOL_URL_ROOT."\n";
// $this->assertEquals(DOL_URL_ROOT,$expectedresult); $this->assertEquals(DOL_URL_ROOT,$expectedresult);
return true; return true;
} }