Login   Register  
PHP Classes
elePHPant
Icontem

File: myXTree/xtree_test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tereshchenko Andrey  >  myXTree  >  myXTree/xtree_test.php  >  Download  
File: myXTree/xtree_test.php
Role: Application script
Content type: text/plain
Description: myXTree test suite
Class: myXTree
myXTree is an interface to a SQL-tree.
Author: By
Last change:
Date: 10 years ago
Size: 3,776 bytes
 

Contents

Class file image Download
<?php
/**
* In front of use of this test necessary to create a database in mySQL.
* SQL queries for creation of tables can be taken from file base.sql in root
* directory. After it need specified the linking up parameters to database
* beneath in this test or in file config.ini.

* NOTE: For correct job of tests the database should be empty. Use SQL-queries
*       only from a file base.sql and do not fill in base the data from a file
*       tree.sql.
*/

$user 'root';
$pass '';
$host 'localhost';
$name 'myXTree';
$prefix 'xt_';

$root $_SERVER['DOCUMENT_ROOT'];
$config['PATH']['pear'] = $root.'/PEAR';
$config['PATH']['myxml'] = $root.'/myXML';
$config['PATH']['myxtree'] = $root.'/myXTree';

function 
getmicrotime() { 
   list(
$usec$sec) = explode(" "microtime()); 
   return ((float)
$usec + (float)$sec); 
}
$time_start getmicrotime();

if (
file_exists('config.ini')) {
    
$config parse_ini_file('config.ini'true);
    
extract($config['DB'], EXTR_OVERWRITE);
}

$dsn "mysql://$user:$pass@$host/$name";

if (
substr(PHP_OS03) == 'WIN') {
    
$searchPath implode(';'$config['PATH']).';';
} else {
    
$searchPath implode(':'$config['PATH']).':';
}
// Set the search path.
ini_set('include_path'$searchPath);

require_once(
'PHPUnit.php');
require_once(
'tests/xtree.php');
require_once(
'tests/xpath.php');
require_once(
'tests/predicate.php');
require_once(
'myDOM/myDOM.php');
require_once(
'DB.php');

function 
handleXTreeError(&$error)
{
    
raiseError($error->getMessage().', userinfo: '.$error->getUserInfo(), E_USER_WARNING);
}

$insertData 'tests/insert.xml';
$updateData 'tests/update.xml';
$relationsData 'tests/relations.xml';

$dom = new Document;
$dom2 = new Document;
$dom3 = new Document;

$dom->parseFile($insertData);

$dom2->parseFile($updateData);

$dom3->parseFile($relationsData);

$db DB::connect($dsn);
PEAR::isError($db) and
    
raiseError($db->getMessage());
    
$xtree =& myXTree::create($db$prefix);
$xtree->setErrorHandling(PEAR_ERROR_CALLBACK'handleXTreeError');

print 
'<br><br>Starting test of myXTree functions';flush();
$time_start getmicrotime();
$suite = new PHPUnit_TestSuite("XTreeTest");
$result PHPUnit::run($suite);
print 
$result->toHTML();flush();
$time getmicrotime() - $time_start;
print 
"Time: $time s.";flush();

$xtree->insert(&$dom->documentElement$parent null$deep true);

print 
'<br><br>Starting test of XPath expressions by selfjoin method';flush();
$time_start getmicrotime();
$suite = new PHPUnit_TestSuite("XPathTest");
$result PHPUnit::run($suite);
print 
$result->toHTML();flush();
$time getmicrotime() - $time_start;
print 
"Time: $time s.";flush();

print 
'<br><br>Starting test of XPath expressions by recursive method';flush();
$time_start getmicrotime();
$xtree->recursive();
$result PHPUnit::run($suite);
print 
$result->toHTML();flush();
$time getmicrotime() - $time_start;
print 
"Time: $time s.";flush();

print 
'<br><br>Starting test of predicate in XPath expressions by selfjoin method';flush();
$time_start getmicrotime();
$suite = new PHPUnit_TestSuite("PredicateTest");
$xtree->recursive(false);
$result PHPUnit::run($suite);
print 
$result->toHTML();flush();
$time getmicrotime() - $time_start;
print 
"Time: $time s.";flush();

print 
'<br><br>Starting test of predicate in XPath expressions by recursive method';flush();
$time_start getmicrotime();
$suite = new PHPUnit_TestSuite("PredicateTest");
$xtree->recursive();
$result PHPUnit::run($suite);
print 
$result->toHTML();flush();
$time getmicrotime() - $time_start;
print 
"Time: $time s.";flush();

$xtree->delete(&$dom->documentElement);

?>