XMLDB/XMLDBtestUnit.php

66 lines
2.2 KiB
PHP
Raw Normal View History

2010-10-07 17:57:56 +02:00
<?
require_once 'XMLDB.php';
$xmldbtest = new XMLDB('text.xml');
if(!$xmldbtest->isLoaded()){
echo 'can\'t load test.xml<br/>';
$xmldbtest = new XMLDB('config.xml');
if($xmldbtest->isLoaded()){
// Testing selectNode($from, $attributeName = null, $attributeValue = null, $childName = null, $childValue = null)
echo 'Testing empty selectNode <br/>';
try {
$xmldbtest->selectNode();
}
catch(Exception $e){
echo $e->getMessage().'<br/><br/>';
}
echo 'Testing selectNode <br/>';
$result = $xmldbtest->selectNode('item');
echo count($result).' results <br/><br/>';
echo 'Testing selectNode id=weather with pk<br/>';
$result = $xmldbtest->selectNode('item', 'weather');
echo count($result).' results <br/><br/>';
echo 'Testing selectNode id=weather<br/>';
$result = $xmldbtest->selectNode('item', null, array('id'=>'weather'));
echo count($result).' results <br/><br/>';
echo 'Testing selectNode visibility = true<br/>';
$result = $xmldbtest->selectNode('item', null,null,array('visibility'=>'true'));
echo count($result).' results <br/><br/>';
echo 'Testing selectNode visibility = true and x = 32<br/>';
$result = $xmldbtest->selectNode('item', null ,null,array('visibility'=>'true', 'x'=>'32'));
echo count($result).' results <br/><br/>';
echo '<br/>Testing insertNode at XML root<br/>';
if($xmldbtest->insertNode(array('name'=>'item', 'attributes'=>array('id'=>'test'), 'childs'=>array('visibility'=>'true', 'x'=>'33'))))
echo "ok<br/><br/>";
else
echo "ko<br/><br/>";
echo '<br/>Testing updatingNodeAttribute with no insert <br/>';
if($xmldbtest->updateNodeAttribute('item', array('id', 'links'), array('id', 'zelda')))
echo "ok<br/><br/>";
else
echo "ko<br/><br/>";
echo '<br/>Testing updateNodeValue via attribute<br/>';
if($xmldbtest->updateNodeValue('item', array('id', 'notes'), null, 'booga!'))
echo "ok<br/><br/>";
else
echo "ko<br/><br/>";
echo '<br/>Testing deleteNode via pk<br/>';
if($xmldbtest->deleteNode('item', 'test', null))
echo "ok<br/><br/>";
else
echo "ko<br/><br/>";
}else{
exit("can't load config.xml either");
}
}