Commit 26613e46 authored by alban's avatar alban

[enh] WIP : the testbed is now database-ready

parent fbc3ba93
my.cnf
local.sh
<?php
$pathList = array_merge( array("."),explode(PATH_SEPARATOR,get_include_path()));
// *****************************************************************************
//
// Alternc bootstrapping
// bureau/class/config.php file is -not- test friendly
// @todo streamline test and prod
//
// *****************************************************************************
// Autoloading
// ***********
$pathList = array_merge( array("."),explode(PATH_SEPARATOR,get_include_path()));
set_include_path(implode(PATH_SEPARATOR, $pathList));
require_once('AutoLoader.php');
// Register the directory to your include files
AutoLoader::registerDirectory('lib');
AutoLoader::registerDirectory('../bureau/class');
AutoLoader::registerDirectory('.');
define('ALTERNC_PANEL', "../bureau"); // Custom
require_once ALTERNC_PANEL."/class/db_mysql.php";
require_once ALTERNC_PANEL."/class/functions.php";
// General variables setup
// *********************
if(is_readable('local.sh')){
$configFile = file_get_contents('local.sh', 'r');
} else if(is_readable('/etc/alternc/local.sh')){
$configFile = file_get_contents('/etc/alternc/local.sh', 'r');
} else {
throw new Exception("You must provide a local.sh file", 1 );
}
$configFile = explode("\n",$configFile);
$compat = array('DEFAULT_MX' => 'MX',
'MYSQL_USER' => 'MYSQL_LOGIN',
'MYSQL_PASS' => 'MYSQL_PWD',
'NS1_HOSTNAME' => 'NS1',
'NS2_HOSTNAME' => 'NS2'
);
foreach ($configFile as $line) {
if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $matches)) {
$GLOBALS['L_'.$matches[1]] = $matches[2];
if (isset($compat[$matches[1]])) {
$GLOBALS['L_'.$compat[$matches[1]]] = $matches[2];
}
}
}
// Constants and globals
// ********************
// Define constants from vars of /etc/alternc/local.sh
define('ALTERNC_MAIL', "$L_ALTERNC_MAIL");
define('ALTERNC_HTML', "$L_ALTERNC_HTML");
if(isset($L_ALTERNC_LOGS_ARCHIVE)){
define('ALTERNC_LOGS_ARCHIVE', "$L_ALTERNC_LOGS_ARCHIVE");
}
define('ALTERNC_LOGS', "$L_ALTERNC_LOGS");
define('ALTERNC_LOCALES', ALTERNC_PANEL."/locales");
define('ALTERNC_LOCK_JOBS', '/var/run/alternc/jobs-lock');
define('ALTERNC_LOCK_PANEL', '/var/lib/alternc/panel/nologin.lock');
define('ALTERNC_APACHE2_GEN_TMPL_DIR', '/etc/alternc/templates/apache2/');
define('ALTERNC_VHOST_DIR', "/var/lib/alternc/apache-vhost/");
define('ALTERNC_VHOST_FILE', ALTERNC_VHOST_DIR."vhosts_all.conf");
define('ALTERNC_VHOST_MANUALCONF', ALTERNC_VHOST_DIR."manual/");
$root = ALTERNC_PANEL."/";
// Database variables setup
// ***********************
if ( is_readable("my.cnf") ) {
$mysqlConfigFile = file_get_contents("my.cnf");
} else if ( is_readable("/etc/alternc/dbusers.cnf") ) {
$mysqlConfigFile = file_get_contents("/etc/alternc/dbusers.cnf");
} else if ( is_readable("/etc/alternc/my.cnf") ) {
$mysqlConfigFile = file_get_contents("/etc/alternc/my.cnf");
} else {
throw new Exception("You must provide a mysql configuration file", 1 );
}
$mysqlConfigFile = explode("\n",$mysqlConfigFile);
foreach ($mysqlConfigFile as $line) {
if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $matches)) {
switch ($matches[1]) {
case "user":
$user = $matches[2];
break;
case "password":
$password = $matches[2];
break;
case "database":
$database = $matches[2];
break;
}
}
if (preg_match('/^#alternc_var ([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $matches)) {
$$matches[1] = $matches[2];
}
}
// Database default
// ********************************************
if( ! $database ){
$database = "alternc_phpunit";
}
/**
* Class for MySQL management in the bureau
*
* This class heriting from the db class of the phplib manages
* the connection to the MySQL database.
*/
class DB_system extends DB_Sql {
var $Host,$Database,$User,$Password;
/**
* Constructor
*/
function DB_system($user,$database,$password) {
global $L_MYSQL_HOST,$L_MYSQL_DATABASE,$L_MYSQL_LOGIN,$L_MYSQL_PWD;
$this->Host = "127.0.0.1";
$this->Database = $database;
$this->User = $user;
$this->Password = $password;
}
}
// Creates database from schema
// *********************************************
$queryList = array(
"mysql -u $user --password='$password' -e 'DROP DATABASE IF EXISTS $database '",
"mysql -u $user --password='$password' -e 'CREATE DATABASE $database'",
"mysql -u $user --password='$password' $database < ".__DIR__."/../install/mysql.sql"
);
foreach ($queryList as $exec_command) {
exec($exec_command,$output,$return_var);
if( $return_var){
throw new \Exception("[!] Mysql exec error : $exec_command \n Error : \n ".print_r($output,1));
}
}
$db = new \DB_system($user,$database,$password);
$cuid = 0;
$variables = new \m_variables();
$mem = new \m_mem();
$err = new \m_err();
$authip = new \m_authip();
$hooks = new \m_hooks();
......@@ -3,6 +3,6 @@
* This is the abstract class for all tests
* @see http://phpunit.de/manual/
*/
abstract class AlterncTest extends PHPUnit_Framework_TestCase
abstract class AlterncTest extends PHPUnit_Extensions_Database_TestCase
{
}
\ No newline at end of file
<phpunit
bootstrap="bootstrap.php"
>
<testsuites>
<testsuite name="AlternCTests">
<directory>tests/bureau</directory>
</testsuite>
</testsuites>
</phpunit>
......@@ -77,7 +77,7 @@ class DummyTest extends AlterncTest
*/
public function testDependance()
{
$this->assertTrue(FALSE);
$this->assertTrue(TRUE);
return TRUE;
}
......
<?php
class LogTest extends AlterncTest
{
/**
*
* @var m_log
*/
private $logger;
protected function setUp()
{
$this->logger = new m_log();
}
protected function tearDown()
{
}
public function testPushAndPop()
{
$stack = array();
$this->assertEquals(0, count($stack));
array_push($stack, 'foo');
$this->assertEquals('foo', $stack[count($stack)-1]);
$this->assertEquals(1, count($stack));
$this->assertEquals('foo', array_pop($stack));
$this->assertEquals(0, count($stack));
}
}
<?php
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-03-13 at 15:55:58.
*/
class m_actionTest extends PHPUnit_Framework_TestCase
{
/**
* @var m_action
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new m_action;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @covers m_action::do_action
* @todo Implement testDo_action().
*/
public function testDo_action()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::create_file
* @todo Implement testCreate_file().
*/
public function testCreate_file()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::create_dir
* @todo Implement testCreate_dir().
*/
public function testCreate_dir()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::fix_user
* @todo Implement testFix_user().
*/
public function testFix_user()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::fix_dir
* @todo Implement testFix_dir().
*/
public function testFix_dir()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::fix_file
* @todo Implement testFix_file().
*/
public function testFix_file()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::del
* @todo Implement testDel().
*/
public function testDel()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::move
* @todo Implement testMove().
*/
public function testMove()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::archive
* @todo Implement testArchive().
*/
public function testArchive()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::set
* @todo Implement testSet().
*/
public function testSet()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::get_old
* @todo Implement testGet_old().
*/
public function testGet_old()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::purge
* @todo Implement testPurge().
*/
public function testPurge()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::get_action
* @todo Implement testGet_action().
*/
public function testGet_action()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::begin
* @todo Implement testBegin().
*/
public function testBegin()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::finish
* @todo Implement testFinish().
*/
public function testFinish()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::reset_job
* @todo Implement testReset_job().
*/
public function testReset_job()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::get_job
* @todo Implement testGet_job().
*/
public function testGet_job()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_action::cancel
* @todo Implement testCancel().
*/
public function testCancel()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}
This diff is collapsed.
<?php
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-03-13 at 15:55:58.
*/
class m_authipTest extends PHPUnit_Framework_TestCase
{
/**
* @var m_authip
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new m_authip;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @covers m_authip::list_ip_whitelist
* @todo Implement testList_ip_whitelist().
*/
public function testList_ip_whitelist()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::hook_menu
* @todo Implement testHook_menu().
*/
public function testHook_menu()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::list_ip
* @todo Implement testList_ip().
*/
public function testList_ip()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::ip_delete
* @todo Implement testIp_delete().
*/
public function testIp_delete()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::get_allowed
* @todo Implement testGet_allowed().
*/
public function testGet_allowed()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::is_wl
* @todo Implement testIs_wl().
*/
public function testIs_wl()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::is_in_subnet
* @todo Implement testIs_in_subnet().
*/
public function testIs_in_subnet()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::ip_save_whitelist
* @todo Implement testIp_save_whitelist().
*/
public function testIp_save_whitelist()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::ip_save
* @todo Implement testIp_save().
*/
public function testIp_save()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::alternc_del_member
* @todo Implement testAlternc_del_member().
*/
public function testAlternc_del_member()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::get_auth_class
* @todo Implement testGet_auth_class().
*/
public function testGet_auth_class()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::ip_affected_save
* @todo Implement testIp_affected_save().
*/
public function testIp_affected_save()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::ip_affected_delete
* @todo Implement testIp_affected_delete().
*/
public function testIp_affected_delete()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::call_hooks
* @todo Implement testCall_hooks().
*/
public function testCall_hooks()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
/**
* @covers m_authip::list_affected
* @todo Implement testList_affected().
*/
public function testList_affected()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}
This diff is collapsed.
<?php
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-03-13 at 15:55:58.
*/
class m_cronTest extends PHPUnit_Framework_TestCase
{
/**
* @var m_cron
*/