git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1653 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
155 lines
4.4 KiB
PHP
155 lines
4.4 KiB
PHP
<?php
|
|
/** DomFramework - Tests
|
|
@package domframework
|
|
@author Dominique Fournier <dominique@fournier38.fr> */
|
|
|
|
/** Test the config.php file */
|
|
class test_config extends PHPUnit_Framework_TestCase
|
|
{
|
|
|
|
public function test_ExternFile ()
|
|
{
|
|
if (file_exists ("/tmp/testconf.php"))
|
|
unlink ("/tmp/testconf.php");
|
|
}
|
|
|
|
public function test_params1 ()
|
|
{
|
|
$c = new config ();
|
|
$res = $c->params ();
|
|
$this->assertSame (array (), $res);
|
|
}
|
|
|
|
public function testGet1 ()
|
|
{
|
|
$c = new config ();
|
|
$c->confFile = "/tmp/testconf.php";
|
|
$c->default = array (
|
|
"database"=>array (
|
|
"dsn"=>null,
|
|
"username"=>null,
|
|
"password"=>null,
|
|
"driver_options"=>null,
|
|
"tableprefix"=>""));
|
|
$res = $c->get ("database");
|
|
$this->assertSame (array (
|
|
"dsn" => null,
|
|
"username" => null,
|
|
"password" => null,
|
|
"driver_options" => null,
|
|
"tableprefix" => ""), $res);
|
|
}
|
|
|
|
public function testSet1 ()
|
|
{
|
|
$c = new config ();
|
|
$c->confFile = "/tmp/testconf.php";
|
|
$c->default = array (
|
|
"database"=>array (
|
|
"dsn"=>null,
|
|
"tableprefix"=>""));
|
|
$res = $c->set ("database", array ("dsn"=>1,"tableprefix"=>3));
|
|
$this->assertSame (true, $res);
|
|
}
|
|
|
|
public function testGet2 ()
|
|
{
|
|
$c = new config ();
|
|
$c->confFile = "/tmp/testconf.php";
|
|
$c->default = array (
|
|
"database"=>array (
|
|
"dsn"=>null,
|
|
"tableprefix"=>""));
|
|
$res = $c->get ("database");
|
|
$this->assertSame (array (
|
|
"dsn" => 1,
|
|
"tableprefix" => 3), $res);
|
|
}
|
|
|
|
/** Can't create file */
|
|
public function testGet3 ()
|
|
{
|
|
$c = new config ();
|
|
$c->confFile = "/tmp/1/2.3/dd/testconf.php";
|
|
$c->default = array (
|
|
"database"=>array (
|
|
"dsn"=>null,
|
|
"tableprefix"=>""));
|
|
$this->setExpectedException ("Exception");
|
|
$res = $c->get ("database");
|
|
}
|
|
|
|
/** Can't read the file */
|
|
public function testGet4 ()
|
|
{
|
|
$c = new config ();
|
|
$c->confFile = "/tmp/testconf.php";
|
|
chmod ("/tmp/testconf.php", 0222);
|
|
$c->default = array (
|
|
"database"=>array (
|
|
"dsn"=>null,
|
|
"tableprefix"=>""));
|
|
$this->setExpectedException ("Exception");
|
|
$res = $c->get ("database");
|
|
}
|
|
|
|
/** File non exists and can not be created */
|
|
public function testSet2 ()
|
|
{
|
|
$c = new config ();
|
|
$c->confFile = "/tmp/1/2.3/dd/testconf.php";
|
|
$c->default = array (
|
|
"database"=>array (
|
|
"dsn"=>null,
|
|
"tableprefix"=>""));
|
|
$this->setExpectedException ("Exception");
|
|
$res = $c->set ("database", array ("dsn"=>1,"tableprefix"=>3));
|
|
}
|
|
|
|
/** Can't read the file */
|
|
public function testSet3 ()
|
|
{
|
|
$c = new config ();
|
|
$c->confFile = "/tmp/testconf.php";
|
|
chmod ("/tmp/testconf.php", 0222);
|
|
$c->default = array (
|
|
"database"=>array (
|
|
"dsn"=>null,
|
|
"tableprefix"=>""));
|
|
$this->setExpectedException ("Exception");
|
|
$res = $c->set ("database", array ("dsn"=>1,"tableprefix"=>3));
|
|
}
|
|
|
|
/** Can't write the file */
|
|
public function testSet4 ()
|
|
{
|
|
$c = new config ();
|
|
$c->confFile = "/tmp/testconf.php";
|
|
chmod ("/tmp/testconf.php", 0444);
|
|
$c->default = array (
|
|
"database"=>array (
|
|
"dsn"=>null,
|
|
"tableprefix"=>""));
|
|
$this->setExpectedException ("Exception");
|
|
$res = $c->set ("database", array ("dsn"=>1,"tableprefix"=>3));
|
|
}
|
|
|
|
/** Save TRUE/FALSE/NULL/String values */
|
|
public function testSet5 ()
|
|
{
|
|
$c = new config ();
|
|
$c->confFile = "/tmp/testconf.php";
|
|
chmod ("/tmp/testconf.php", 0666);
|
|
$c->default = array (
|
|
"database"=>array (
|
|
"dsn"=>null,
|
|
"user"=>null,
|
|
"password"=>null,
|
|
"tableprefix"=>""));
|
|
$res = $c->set ("database", array ("dsn"=>true, "user"=>null,
|
|
"password"=>"text",
|
|
"tableprefix"=>false));
|
|
$this->assertSame (true, $res);
|
|
}
|
|
}
|