3 require_once('simpletest/unit_tester.php');
4 require_once('simpletest/reporter.php');
6 class TableTest
extends UnitTestCase
{
10 define('WARAQ_ROOT', '..');
11 require_once WARAQ_ROOT
.'/ini.php';
12 require_once '../lib/database.php';
13 $this->dbsqlite
=& new BDB("sqlite:bazdig-test.db");
14 $this->dbmysql
=& new BDB("mysql:host=localhost;dbname=markkit", "root");
15 $this->dbmysql2
=& new BDB(array('type' => 'mysql', 'host' => 'localhost', 'name' => 'markkit'), "root");
16 $this->dbsqlite2
=& new BDB(array('type' => 'sqlite', 'name' => 'bazdig-test.db'));
17 $this->table
= new Table('sql');
18 $this->table2
= new Table('marks');
25 function test_httpGet()
29 $result = $this->dbmysql2
->httpGet($bazdig->get('/test/query_string.php'));
30 $expected = "dbt=mysql&dbn=markkit&dbh=localhost&dbu=root&dbp=";
31 $this->assertEqual($expected, $result);
34 function test_getDsn()
36 $result = $this->dbmysql2
->getDsn();
37 $expected = "mysql:host=localhost;dbname=markkit";
38 $this->assertEqual($expected, $result);
39 $result = $this->dbsqlite2
->getDsn();
40 $expected = "sqlite:bazdig-test.db";
41 $this->assertEqual($expected, $result);
44 function test_listTables()
46 $tables = $this->dbsqlite
->listTables();
47 $expected = array($this->table
, new Table('bash'));
48 $this->assertEqual($expected, $tables);
49 $expected = array(new Table('ctrl_patch'), new Table('marks'));
50 $tables = $this->dbmysql
->listTables();
51 $this->assertEqual($expected, $tables);
52 $tables = $this->dbmysql2
->listTables();
53 $this->assertEqual($expected, $tables);
56 function test_loadColumns()
58 $this->table
->loadColumns($this->dbsqlite
);
59 $expected = array(new Column('id'), new Column('code'), new Column('date'));
60 $this->assertEqual($expected, $this->table
->columns
);
61 $expected = array(new Column('id', 'varchar(50)'), new Column('creationDate', 'datetime'), new Column('pageUrl', 'varchar(255)'), new Column('text', 'varchar(255)'), new Column('owner', 'varchar(50)'), new Column ('startNodePath', 'varchar(128)'), new Column ('startOffset', 'int(11)'), new Column('endNodePath', 'varchar(128)'), new Column('endOffset', 'int(11)'));
62 $this->table2
->loadColumns($this->dbmysql
);
63 $this->assertEqual($expected, $this->table2
->columns
);
64 $this->table2
->loadColumns($this->dbmysql2
);
65 $this->assertEqual($expected, $this->table2
->columns
);
70 $test =& new TableTest
;
71 $test->run(new HtmlReporter());