Added basical functions
This commit is contained in:
@@ -1,59 +1,88 @@
|
||||
<?
|
||||
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 'can\'t load test.xml<br/>';
|
||||
$xmldbtest = new XMLDB('config.xml');
|
||||
echo '<br/><br/>can\'t load test.xml<br/>';
|
||||
$xmldbtest = new XMLDB('database.xml');
|
||||
if($xmldbtest->isLoaded()){
|
||||
// Testing selectNode($from, $attributeName = null, $attributeValue = null, $childName = null, $childValue = null)
|
||||
echo 'Testing empty selectNode <br/>';
|
||||
// Testing select($from, $attributeName = null, $attributeValue = null, $childName = null, $childValue = null)
|
||||
echo 'Testing empty select (exception)<br/>';
|
||||
try {
|
||||
$xmldbtest->selectNode();
|
||||
$xmldbtest->select();
|
||||
}
|
||||
catch(Exception $e){
|
||||
echo $e->getMessage().'<br/><br/>';
|
||||
}
|
||||
|
||||
echo 'Testing selectNode <br/>';
|
||||
$result = $xmldbtest->selectNode('item');
|
||||
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 selectNode id=weather with pk<br/>';
|
||||
$result = $xmldbtest->selectNode('item', 'weather');
|
||||
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 selectNode id=weather<br/>';
|
||||
$result = $xmldbtest->selectNode('item', null, array('id'=>'weather'));
|
||||
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 selectNode visibility = true<br/>';
|
||||
$result = $xmldbtest->selectNode('item', null,null,array('visibility'=>'true'));
|
||||
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 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 '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 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 '<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<br/>';
|
||||
if($xmldbtest->updateNodeValue('item', array('id', 'notes'), null, 'booga!'))
|
||||
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<br/>';
|
||||
if($xmldbtest->deleteNode('item', 'test', null))
|
||||
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/>";
|
||||
|
Reference in New Issue
Block a user