XMLDB/XMLDBtestUnit.php

95 lines
3.5 KiB
PHP
Raw Normal View History

2010-10-07 17:57:56 +02:00
<?
require_once 'XMLDB.php';
2010-10-08 17:06:08 +02:00
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/>';
2010-10-07 17:57:56 +02:00
$xmldbtest = new XMLDB('text.xml');
if(!$xmldbtest->isLoaded()){
2010-10-08 17:06:08 +02:00
echo '<br/><br/>can\'t load test.xml<br/>';
$xmldbtest = new XMLDB('database.xml');
2010-10-07 17:57:56 +02:00
if($xmldbtest->isLoaded()){
2010-10-08 17:06:08 +02:00
// Testing select($from, $attributeName = null, $attributeValue = null, $childName = null, $childValue = null)
echo 'Testing empty select (exception)<br/>';
2010-10-07 17:57:56 +02:00
try {
2010-10-08 17:06:08 +02:00
$xmldbtest->select();
2010-10-07 17:57:56 +02:00
}
catch(Exception $e){
echo $e->getMessage().'<br/><br/>';
}
2010-10-08 17:06:08 +02:00
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/>";
2010-10-07 17:57:56 +02:00
2010-10-08 17:06:08 +02:00
echo 'Testing select (should give 8 results - 7 from the file + 1 we created earlier)<br/>';
$result = $xmldbtest->select('table1');
2010-10-07 17:57:56 +02:00
echo count($result).' results <br/><br/>';
2010-10-08 17:06:08 +02:00
echo 'Testing select id=weather with pk (should find 1 result)<br/>';
$result = $xmldbtest->selectFromPK('table1', 'weather');
2010-10-07 17:57:56 +02:00
echo count($result).' results <br/><br/>';
2010-10-08 17:06:08 +02:00
echo 'Testing select id=weather (should find 1 result)<br/>';
$result = $xmldbtest->select('table1', null, array('id'=>'weather'));
2010-10-07 17:57:56 +02:00
echo count($result).' results <br/><br/>';
2010-10-08 17:06:08 +02:00
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'));
2010-10-07 17:57:56 +02:00
echo count($result).' results <br/><br/>';
2010-10-08 17:06:08 +02:00
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/>';
2010-10-07 17:57:56 +02:00
2010-10-08 17:06:08 +02:00
2010-10-07 17:57:56 +02:00
2010-10-08 17:06:08 +02:00
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')))
2010-10-07 17:57:56 +02:00
echo "ok<br/><br/>";
else
echo "ko<br/><br/>";
2010-10-08 17:06:08 +02:00
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!'))
2010-10-07 17:57:56 +02:00
echo "ok<br/><br/>";
else
echo "ko<br/><br/>";
2010-10-08 17:06:08 +02:00
echo '<br/>Testing deleteNode via pk (should be ok - deleting the item clock into table1)<br/>';
if($xmldbtest->deleteNode('table1', 'clock', null))
2010-10-07 17:57:56 +02:00
echo "ok<br/><br/>";
else
echo "ko<br/><br/>";
}else{
exit("can't load config.xml either");
}
}