XMLDB/XMLDBtestUnit.php

91 lines
4.2 KiB
PHP
Raw Normal View History

2010-10-07 17:57:56 +02:00
<?
require_once('simpletest/autorun.php');
require_once('log.php');
2010-10-07 17:57:56 +02:00
require_once 'XMLDB.php';
2010-10-08 17:06:08 +02:00
class TestOfLogging extends UnitTestCase {
function test(){
//$this->expectException(new Exception('uhoh, no table selected'));
@unlink('test.log');
$log = new Log('test.log');
$log->message('creating "test.xml" with a table');
$this->assertTrue($xmldbtest1 = new XMLDB('test.xml', 'id', true));
$this->assertTrue($xmldbtest1->createTable('table1'));
//$xmldbtest = new XMLDB('text.xml');
//$log->message('Trying to load an inexistant DB');
//$this->assertFalse($xmldbtest->isLoaded());
$log->message('Trying to load "database.xml"');
$xmldbtest = new XMLDB('database.xml');
$this->assertTrue($xmldbtest->isLoaded());
$log->message('Trying to create 2 wrong tables');
$this->assertFalse($xmldbtest->createTable('*'));
$this->assertFalse($xmldbtest->createTable('table1'));
$log->message('Trying to insert item "test" into "table1"');
$this->assertTrue($xmldbtest->insertItem('test', array('pwet'=>'cacahuete'), array('visibility'=>'true', 'x'=>'33'), 'table1'));
$log->message('Trying to do several select');
$this->assertEqual($xmldbtest->selectAllFromTable('table1', 'count'), 8);
$this->assertEqual($xmldbtest->selectFromPK('table1', 'weather', 'count'), 1);
$this->assertEqual($xmldbtest->selectFromAttribute('table1', array('id'=>'weather'), 'count'),1);
$this->assertEqual($xmldbtest->selectFromChildren('table1',array('visibility'=>'true'),'count'), 6);
$this->assertEqual($xmldbtest->selectFromChildren('*',array('visibility'=>'true'),'count'), 8);
$this->assertEqual($xmldbtest->selectFromChildren('table1',array('visibility'=>'true', 'x'=>'32'),'count'), 1);
$log->message('Trying to do several inserts');
$this->assertFalse($xmldbtest->insertItem('test', null, array('visibility'=>'true', 'x'=>'33'), 'table1'));
$this->assertTrue($xmldbtest->insertItem('test2', null, array('visibility'=>'true', 'x'=>'33'), 'table1'));
$log->message('Trying to do several updates');
$this->assertTrue($xmldbtest->updateItemAttribute('table1', array('id', 'links'), array('id', 'zelda')));
$this->assertTrue($xmldbtest->updateItemValue('table1', array('id', 'notes'), null, 'booga!'));
$log->message('Trying to delete the item "clock" from "table1"');
//var_dump($xmldbtest->selectFromPK('table1', 'clock', 'node'), true);
//$this->assertTrue($xmldbtest->deleteNode($xmldbtest->selectFromPK('table1', 'clock', 'node')));
$this->assertTrue($xmldbtest->deleteItem('table1','clock'));
//var_dump($xmldbtest->selectFromPK('table1', 'search', 'node')->item(0));
$log->message('Trying to move an element to another table');
$this->assertTrue($xmldbtest->move( $xmldbtest->selectFromPK('table1', 'search', 'node'), 'table2'));
$log->message('Trying to erase a DB');
$xmldbtest1->dropDatabase(true);
$xmldbtest2 = new XMLDB('database2.xml');
$this->assertTrue($xmldbtest2->isTableAI('table1'));
$this->assertTrue($xmldbtest2->insertItem(null, null, null,'table1'));
$this->assertEqual($xmldbtest2->getChildValue('sex', $xmldbtest2->selectFromPK('table1', '3', 'node')), 'M');
$this->assertTrue($xmldbtest2->createTable('table3', true, 2));
$personnes = array(
3 => array(
'nom' => 'Desmidt',
'prenom' => 'clément'
),
4 => array(
'nom' => 'Chou',
'prenom' => 'Chen'
),
5 => array(
'nom' => 'Votocek',
'prenom' => 'Sophie'
),
6 => array(
'nom' => 'Dupond',
'prenom' => 'Jean'
)
);
foreach($personnes as $personne){
$this->assertTrue($xmldbtest2->insertItem(null, null, $personne, 'table3'));
}
$this->assertTrue($xmldbtest2->deleteITem('table3', '4'));
$this->assertTrue($xmldbtest2->insertItem(null, null, array('visibility'=>'true', 'x'=>'31'), 'table3'));
//$this->assertTrue($xmldbtest2->insertItem(null, null, array('visibility'=>'true', 'x'=>'33'), 'table3'));
//$this->assertEqual($xmldbtest2->getAttribute('aivalue', $xmldbtest2->selectTable('table3')), 5);
/*$log->message('Trying to select w/o anything');
$xmldbtest->select();*/
}
2010-10-08 17:06:08 +02:00
2010-10-07 17:57:56 +02:00
}
$test = new TestOfLogging;
$test->test();