3 require_once 'PHPUnit.php';
6 require_once 'diogenes/diogenes.database.inc.php';
8 class DBInitialTest
extends PHPUnit_TestCase
12 function DBInitialTest($name)
14 parent
::PHPUnit_TestCase($name);
16 if (!extension_loaded('mysql') && !dl('mysql.so'))
18 die("The MySQL module is not your PHP configuration and could not be loaded, fix your PHP setup!");
21 $conn = mysql_connect('localhost', 'test');
25 die("You need to have a MySQL database running on the local host, with a user\ncalled 'test' with no password.");
28 $rv = mysql_query("DROP DATABASE test");
31 die("Database drop failed. The user 'test' must have full privileges to the\n'test' database.");
34 mysql_query("CREATE DATABASE test");
36 system("mysql -u test test < config/db/diogenes.sql");
41 $tables = array('diogenes_auth', 'diogenes_logactions',
43 'diogenes_logsessions', 'diogenes_option',
44 'diogenes_perm', 'diogenes_site');
46 $DB = DB
::Connect('mysql://test@localhost/test');
49 die($DB->getMessage()."\n".$DB->getUserInfo()."\n");
52 $this->assertEquals($tables, $DB->getCol('show tables'));
56 class DiogenesDatabaseTest
extends PHPUnit_TestCase
58 function testConstructor()
60 $DB = new DiogenesDatabase('localhost', 'test', 'test', '');
62 $this->assertTrue(is_object($DB));
67 $db = new DiogenesDatabase('tst', 'localhost', 'test', '');
69 $this->assertTrue($db->err());
70 $this->assertEquals(1049, $db->errno());
71 $this->assertEquals("Unknown database 'tst'", $db->error());
74 $this->assertFalse($db->err());
75 $this->assertEquals(0, $db->errno());
76 $this->assertEquals('', $db->error());
80 function testMoreErrors()
82 $db = new DiogenesDatabase('test', 'localhost', 'test', '');
84 $this->assertFalse($db->err(), "Should be no error");
88 $this->assertTrue($db->err(), "Should be error");
89 $this->assertEquals(1064, $db->errno());
90 $this->assertEquals("You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SLECT' at line 1", $db->error());
91 $this->assertEquals("SLECT", $db->errinfo());
94 $this->assertEquals('', $db->errinfo());