XMLDB/XMLDBtestUnit.php
2010-10-08 15:06:08 +00:00

95 lines
3.5 KiB
PHP

<?
require_once 'XMLDB.php';
echo 'Creating new DB (should be "ok" creating a new file "test")<br/>';
if($xmldbtest1 = new XMLDB('test.xml', 'id', true))
echo "ok";
else
echo "ko";
echo '<br/>Creating new table (should be "ok" adding table1 in test)<br/>';
if($xmldbtest1->createTable('table1'))
echo "ok";
else
echo "ko";
echo '<br/>loading an inexistant DB (error)<br/>';
$xmldbtest = new XMLDB('text.xml');
if(!$xmldbtest->isLoaded()){
echo '<br/><br/>can\'t load test.xml<br/>';
$xmldbtest = new XMLDB('database.xml');
if($xmldbtest->isLoaded()){
// Testing select($from, $attributeName = null, $attributeValue = null, $childName = null, $childValue = null)
echo 'Testing empty select (exception)<br/>';
try {
$xmldbtest->select();
}
catch(Exception $e){
echo $e->getMessage().'<br/><br/>';
}
echo '<br/>Creating new table name "*" (should be "ko" table already exist)<br/>';
if($xmldbtest->createTable('*'))
echo "ok";
else
echo "ko";
echo '<br/>Creating new table (should be "ko" table already exist)<br/>';
if($xmldbtest->createTable('table1'))
echo "ok";
else
echo "ko";
echo '<br/>Testing insertNode at XML root (should insert an item named "test" into table1)<br/>';
if($xmldbtest->insertNode(array('name'=>'item', 'attributes'=>array('id'=>'test'), 'childs'=>array('visibility'=>'true', 'x'=>'33')), 'table1'))
echo "ok<br/><br/>";
else
echo "ko<br/><br/>";
echo 'Testing select (should give 8 results - 7 from the file + 1 we created earlier)<br/>';
$result = $xmldbtest->select('table1');
echo count($result).' results <br/><br/>';
echo 'Testing select id=weather with pk (should find 1 result)<br/>';
$result = $xmldbtest->selectFromPK('table1', 'weather');
echo count($result).' results <br/><br/>';
echo 'Testing select id=weather (should find 1 result)<br/>';
$result = $xmldbtest->select('table1', null, array('id'=>'weather'));
echo count($result).' results <br/><br/>';
echo 'Testing select visibility = true (should throw 6 results - 5 from the base file + 1 we created)<br/>';
$result = $xmldbtest->select('table1', null,null,array('visibility'=>'true'));
echo count($result).' results<br/><br/>';
echo 'Testing select visibility = true on all tables (should find 8 results - 7 from the base file + 1 we created)<br/>';
$result = $xmldbtest->select('*', null,null,array('visibility'=>'true'));
echo count($result).' results <br/><br/>';
echo 'Testing select visibility = true and x = 32 (experimental - should find 1)<br/>';
$result = $xmldbtest->selectFromChilds('table1',array('visibility'=>'true', 'x'=>'32'));
echo count($result).' results<br/><br/>';
echo '<br/>Testing updatingNodeAttribute with no insert (should be ok and change the item "links" into "zelda" haha)<br/>';
if($xmldbtest->updateNodeAttribute('table1', array('id', 'links'), array('id', 'zelda')))
echo "ok<br/><br/>";
else
echo "ko<br/><br/>";
echo '<br/>Testing updateNodeValue via attribute (should be ok - inserting "booga!" into the item named "notes")<br/>';
if($xmldbtest->updateNodeValue('table1', array('id', 'notes'), null, 'booga!'))
echo "ok<br/><br/>";
else
echo "ko<br/><br/>";
echo '<br/>Testing deleteNode via pk (should be ok - deleting the item clock into table1)<br/>';
if($xmldbtest->deleteNode('table1', 'clock', null))
echo "ok<br/><br/>";
else
echo "ko<br/><br/>";
}else{
exit("can't load config.xml either");
}
}