| 1 |
<?php
|
| 2 |
//DEFINES
|
| 3 |
define('SONIA_TEST_NUMBER_OF_CLASSESS','100');
|
| 4 |
//number of objects
|
| 5 |
define('SONIA_TEST_NUMBER_OF_OBJECTS','222');
|
| 6 |
|
| 7 |
define('SONIA_TEST_NAME','Laptop Medium 2');
|
| 8 |
|
| 9 |
/**
|
| 10 |
* A script to be called directly which runs through the loading and running
|
| 11 |
* of a few basic SONIA tests.
|
| 12 |
*
|
| 13 |
* Cache functions are not yet tested as that requires Drupal, and these tests deal
|
| 14 |
* less with performant issues than basic functionality
|
| 15 |
*
|
| 16 |
* @license AGPL
|
| 17 |
* @license 2006 KBCMS LLC
|
| 18 |
* @author Jonathan Hendler
|
| 19 |
* @package SONIA
|
| 20 |
* @version 0.31
|
| 21 |
* */
|
| 22 |
class ST
|
| 23 |
{
|
| 24 |
/**
|
| 25 |
* total number of tests to be run
|
| 26 |
* */
|
| 27 |
public $test_count;
|
| 28 |
|
| 29 |
/**
|
| 30 |
* cleanup the database when finished
|
| 31 |
* */
|
| 32 |
public $do_cleanup;
|
| 33 |
|
| 34 |
/**
|
| 35 |
* */
|
| 36 |
public $start_time;
|
| 37 |
|
| 38 |
/***/
|
| 39 |
public $end_time;
|
| 40 |
|
| 41 |
|
| 42 |
/**
|
| 43 |
*
|
| 44 |
* */
|
| 45 |
public $total_success;
|
| 46 |
|
| 47 |
/**
|
| 48 |
* why have the functionality outsisw the builtin function?
|
| 49 |
* so it can be tested outside the builtin function
|
| 50 |
* */
|
| 51 |
function __construct($do_cleanup = true)
|
| 52 |
{
|
| 53 |
$this->init();
|
| 54 |
$this->do_cleanup = $do_cleanup;
|
| 55 |
$this->base_uri = 'http://mydrupalsite.com/node/';
|
| 56 |
$this->total_success = true;
|
| 57 |
|
| 58 |
}
|
| 59 |
|
| 60 |
function endAll()
|
| 61 |
{
|
| 62 |
global $max_memory_usage;
|
| 63 |
$memory = "Max Memory used: $max_memory_usage";
|
| 64 |
$total_time = $this->end_time - $this->start_time;
|
| 65 |
$sub = 'End of tests.';
|
| 66 |
$content = 'Note: The get_memory_usage is emulated on some machines. On a P4HT 2.8 Ghz this was a 1 second delay.';
|
| 67 |
|
| 68 |
$title = 'end';
|
| 69 |
// $this->all_test_results[$title]['time'] = $total_time;
|
| 70 |
// $this->all_test_results[$title]['subtitle'] = $sub;
|
| 71 |
// $this->all_test_results[$title]['comments'] = $content;
|
| 72 |
// $this->all_test_results[$title]['memory'] = $max_memory_usage;
|
| 73 |
// $this->all_test_results[$title]['success'] = $this->total_success;
|
| 74 |
//output all results
|
| 75 |
sonia_test_output_results($this->all_test_results);
|
| 76 |
printTestName("Time Elapsed: $total_time seconds. $memory", $content);
|
| 77 |
}
|
| 78 |
|
| 79 |
function __destruct()
|
| 80 |
{
|
| 81 |
|
| 82 |
if($this->do_cleanup) $this->testcleanup();
|
| 83 |
|
| 84 |
}
|
| 85 |
|
| 86 |
function runtests( )
|
| 87 |
{
|
| 88 |
global $tests;
|
| 89 |
|
| 90 |
//variables
|
| 91 |
|
| 92 |
//number of classes
|
| 93 |
$nc = SONIA_TEST_NUMBER_OF_CLASSESS;
|
| 94 |
//number of objects
|
| 95 |
$no = SONIA_TEST_NUMBER_OF_OBJECTS;
|
| 96 |
|
| 97 |
$this->start_time = this_microtime();
|
| 98 |
$this->start_create_class_time = this_microtime();
|
| 99 |
|
| 100 |
//create classes
|
| 101 |
$this->create_classes($nc);
|
| 102 |
//create hierarchy
|
| 103 |
$this->create_superclasses($nc);
|
| 104 |
//
|
| 105 |
$this->class_properties($nc);
|
| 106 |
$this->create_objects($no,$nc);
|
| 107 |
|
| 108 |
$this->search_classes($no,$nc);
|
| 109 |
$this->start_end_class_time = this_microtime();
|
| 110 |
|
| 111 |
$this->end_time = this_microtime();
|
| 112 |
//log results
|
| 113 |
|
| 114 |
$this->endAll();
|
| 115 |
}
|
| 116 |
|
| 117 |
|
| 118 |
//Load SONIA
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
/**
|
| 123 |
* create a class which needs an ID
|
| 124 |
* then create a class which does not need an id
|
| 125 |
*
|
| 126 |
* */
|
| 127 |
function create_classes($nc)
|
| 128 |
{
|
| 129 |
$success = false;
|
| 130 |
$content = '';
|
| 131 |
|
| 132 |
$this->createClassesAutoID($nc);
|
| 133 |
$this->createClassesWithID($nc);
|
| 134 |
|
| 135 |
}
|
| 136 |
|
| 137 |
function create_superclasses($nc)
|
| 138 |
{
|
| 139 |
$content = 'All Passed';
|
| 140 |
$success = false;
|
| 141 |
$base_uri = 'http://mydrupalsite.com/node/';
|
| 142 |
$this->test_start();
|
| 143 |
for($i = 0; $i<$nc;$i++)
|
| 144 |
{
|
| 145 |
if ($i >0)
|
| 146 |
{
|
| 147 |
$regulator = ($i>7)? ($i%5): 1;
|
| 148 |
$uri1 = $base_uri.$i;
|
| 149 |
$uri2 = $base_uri.($i-1);
|
| 150 |
// if ($uri1 == $uri2) print "<br />$uri1 == $uri2";
|
| 151 |
$this->sonia->store->setSubclass($uri1,$uri2);
|
| 152 |
}
|
| 153 |
}
|
| 154 |
|
| 155 |
$get_id = $nc - ($nc /10) - ($nc /10);
|
| 156 |
$superclasses = $this->sonia->store->getAllCategoriesRecursive($base_uri.$get_id,0,'START LABEL');
|
| 157 |
|
| 158 |
$depth = ArrayDepth($superclasses);
|
| 159 |
$success = (($depth) == ((3*($nc-$get_id))-1));
|
| 160 |
if (!$success)
|
| 161 |
{
|
| 162 |
$content = "((3*($nc-$get_id))-1) == $depth " ;
|
| 163 |
$this->total_success = false;
|
| 164 |
}
|
| 165 |
|
| 166 |
//now check to see that they are there
|
| 167 |
$this->test_end('Created Subclass Relationships', 'Subclasses set in groups', $content,$success);
|
| 168 |
//printTest('Set Subclases in '.$total.' seconds ', 'Set ID based Classes as subclasses of eachother, tested this was true',$content,$success);
|
| 169 |
}
|
| 170 |
|
| 171 |
function delete_subclasses()
|
| 172 |
{
|
| 173 |
$content = 'All Passed';
|
| 174 |
$success = false;
|
| 175 |
$base_uri = 'http://mydrupalsite.com/node/';
|
| 176 |
$superclasses = $this->sonia->store->getAllCategoriesRecursive( );
|
| 177 |
dbg($superclasses,'$superclasses?');
|
| 178 |
$this->sonia->deleteClass($base_uri.'4');
|
| 179 |
$superclasses = $this->sonia->store->getAllCategoriesRecursive($base_uri.'0',0,true);
|
| 180 |
|
| 181 |
$depth = ArrayDepth($superclasses);
|
| 182 |
$success = ($depth == 6);
|
| 183 |
if (!$success)
|
| 184 |
{
|
| 185 |
$content = 'should be 6 $depth ='.$depth;
|
| 186 |
dbg($superclasses,'$superclasses?');
|
| 187 |
$this->total_success = false;
|
| 188 |
}
|
| 189 |
|
| 190 |
printTest('Deleted Subclases ', 'Deleted Subclasses from ID 4 and below, tested this was true',$content,$success);
|
| 191 |
}
|
| 192 |
|
| 193 |
/**
|
| 194 |
* update the labels , add and alter descriptions
|
| 195 |
* add and alter tags
|
| 196 |
* **/
|
| 197 |
function update_classes()
|
| 198 |
{
|
| 199 |
$content = 'All Passed';
|
| 200 |
$success = true;
|
| 201 |
$base_uri = 'http://mydrupalsite.com/node/';
|
| 202 |
$original_class_label = 'My First Class';
|
| 203 |
$class_one = $base_uri.'0';
|
| 204 |
$class_two = $base_uri.'1';
|
| 205 |
|
| 206 |
$label_1_before = $this->sonia->getLabel($class_one);
|
| 207 |
if ($label_1_before != $original_class_label.' 0')
|
| 208 |
{
|
| 209 |
$success = false;
|
| 210 |
$content = "$label_1_before != $original_class_label";
|
| 211 |
}
|
| 212 |
|
| 213 |
$label_2_before = $this->sonia->getLabel($class_two);
|
| 214 |
if ($label_2_before != $original_class_label.' 1')
|
| 215 |
{
|
| 216 |
$success = false;
|
| 217 |
$content = "$label_2_before != $original_class_label";
|
| 218 |
}
|
| 219 |
|
| 220 |
$new_label_1 = "Second Class Name";
|
| 221 |
$new_label_2 = "Second Class Name Updated too";
|
| 222 |
|
| 223 |
$this->sonia->updateClass($class_one,$new_label_1);
|
| 224 |
$this->sonia->updateClass($class_two,$new_label_2);
|
| 225 |
|
| 226 |
|
| 227 |
$label_1_after = $this->sonia->getLabel($class_one);
|
| 228 |
$label_2_after = $this->sonia->getLabel($class_two);
|
| 229 |
|
| 230 |
if ($label_1_after != $new_label_1)
|
| 231 |
{
|
| 232 |
$success = false;
|
| 233 |
$content = "$label_1_after != $new_label_1";
|
| 234 |
}
|
| 235 |
|
| 236 |
if ($label_2_after != $new_label_2)
|
| 237 |
{
|
| 238 |
$success = false;
|
| 239 |
$content = "$label_2_after != $new_label_2";
|
| 240 |
}
|
| 241 |
|
| 242 |
$class_1_description = 'Very Very very nice. 150897 haf9upq84797-8q4-75camp(*^$^80 afa sdf af';
|
| 243 |
|
| 244 |
//add comment
|
| 245 |
$this->sonia->createComment($class_one,$class_1_description);
|
| 246 |
|
| 247 |
//check comment
|
| 248 |
$rdescription = $this->sonia->getComment($class_one);
|
| 249 |
|
| 250 |
if ($class_1_description != $rdescription)
|
| 251 |
{
|
| 252 |
$success = false;
|
| 253 |
$content = "$class_1_description != $rdescription";
|
| 254 |
}
|
| 255 |
|
| 256 |
$class_1_description = $class_1_description .' UPDATED';
|
| 257 |
//update comment
|
| 258 |
|
| 259 |
$this->sonia->updateComment($class_one,$class_1_description);
|
| 260 |
//temp
|
| 261 |
$this->sonia->createComment($class_one,$class_1_description);
|
| 262 |
$rdescription = $this->sonia->getComment($class_one);
|
| 263 |
|
| 264 |
if ($class_1_description != $rdescription)
|
| 265 |
{
|
| 266 |
$success = false;
|
| 267 |
$content = " UPDATE FAILED: $class_1_description != $rdescription";
|
| 268 |
}
|
| 269 |
//delete comment
|
| 270 |
|
| 271 |
$this->sonia->deleteComment($class_one);
|
| 272 |
|
| 273 |
$rdescription = $this->sonia->getComment($class_one);
|
| 274 |
|
| 275 |
if ('' != $rdescription)
|
| 276 |
{
|
| 277 |
$success = false;
|
| 278 |
$content = " Delete FAILED: null != $rdescription";
|
| 279 |
}
|
| 280 |
|
| 281 |
if (!$success)
|
| 282 |
{
|
| 283 |
$this->total_success = false;
|
| 284 |
}
|
| 285 |
|
| 286 |
printTest('Updated classes ',
|
| 287 |
'Retrieved two classes Labels. Updated two classes labels. Retrieved and tested these and comments.',$content,$success);
|
| 288 |
}
|
| 289 |
|
| 290 |
function class_properties($nc)
|
| 291 |
{
|
| 292 |
$content = 'All Passed';
|
| 293 |
$success = true;
|
| 294 |
$base_uri = $this->base_uri;
|
| 295 |
$original_class_label = 'My First Class';
|
| 296 |
$class_one = $base_uri.'0';
|
| 297 |
$class_two = $base_uri.'1';
|
| 298 |
$class_three = $base_uri.'3';
|
| 299 |
$count = 0;
|
| 300 |
$this->test_start();
|
| 301 |
$property_label_one = ' First Clss for properties';
|
| 302 |
$property_label_two = ' Second Clss for properties';
|
| 303 |
//$this->base_uri
|
| 304 |
$class_array_one = array($class_one,$class_two);
|
| 305 |
$class_array_two = array($class_one);
|
| 306 |
|
| 307 |
$property1 = $this->sonia->createProperty($property_label_one,$class_array_one );
|
| 308 |
$property2 = $this->sonia->createProperty($property_label_two, $class_array_two);
|
| 309 |
|
| 310 |
if (!$this->sonia->propertyExists($property2))
|
| 311 |
{
|
| 312 |
$success = false;
|
| 313 |
$content = "$property2 should exist!!";
|
| 314 |
}
|
| 315 |
//echo "<br> \$property1 $property1 \$property2 $property2 <br/>";
|
| 316 |
|
| 317 |
$this->sonia->addPropertyToClass($class_two,$property2);
|
| 318 |
|
| 319 |
$class1_properties = $this->sonia->getAllClassProperties($count, $class_one);
|
| 320 |
//get all properties of each class
|
| 321 |
$class1_properties = $class1_properties['rdfs:domain']['subclasses'];
|
| 322 |
|
| 323 |
if (!array_key_exists($property1,$class1_properties) || !array_key_exists($property2,$class1_properties))
|
| 324 |
{
|
| 325 |
$success = false;
|
| 326 |
$content = "$property1 not found OR $property2 not found in class $class_one ";
|
| 327 |
}
|
| 328 |
|
| 329 |
$class2_properties = $this->sonia->getAllClassProperties($count, $class_two);
|
| 330 |
//get all properties of each class
|
| 331 |
$class2_properties = $class2_properties['rdfs:domain']['subclasses'];
|
| 332 |
|
| 333 |
if (!array_key_exists($property1,$class2_properties) || !array_key_exists($property2,$class2_properties))
|
| 334 |
{
|
| 335 |
$success = false;
|
| 336 |
$content = "$property1 not found OR $property2 not found in class $class_two";
|
| 337 |
}
|
| 338 |
|
| 339 |
//remove property 1 from class 1
|
| 340 |
$this->sonia->deletePropertyFromClass($class_one, $property1);
|
| 341 |
|
| 342 |
$class1_properties = $this->sonia->getAllClassProperties($count, $class_one);
|
| 343 |
//get all properties of each class
|
| 344 |
$class1_properties = $class1_properties['rdfs:domain']['subclasses'];
|
| 345 |
|
| 346 |
if (array_key_exists($property1,$class1_properties) || !array_key_exists($property2,$class1_properties))
|
| 347 |
{
|
| 348 |
$success = false;
|
| 349 |
$content = "$property1 *found* (and it should not be) OR $property2 not found. ";
|
| 350 |
$content .= array_key_exists($property1,$class1_properties). ' should be false.';
|
| 351 |
$content .= !array_key_exists($property2,$class1_properties). ' should be false.';
|
| 352 |
}
|
| 353 |
|
| 354 |
|
| 355 |
$classes_1 = $this->sonia->store->getAllClassesOfProperty($property1);
|
| 356 |
$classes_1 = $classes_1['http://www.w3.org/2000/01/rdf-schema#Class']['subclasses'];
|
| 357 |
$classes_2 = $this->sonia->store->getAllClassesOfProperty($property2);
|
| 358 |
$classes_2 = $classes_2['http://www.w3.org/2000/01/rdf-schema#Class']['subclasses'];
|
| 359 |
|
| 360 |
//get all classes of each property
|
| 361 |
//check count
|
| 362 |
if (array_key_exists($class_one,$classes_1) || !array_key_exists($class_two,$classes_1))
|
| 363 |
{
|
| 364 |
$success = false;
|
| 365 |
$content = "$class_one *found* (and it should not be) OR $class_two not found. ";
|
| 366 |
}
|
| 367 |
|
| 368 |
if (!array_key_exists($class_one,$classes_2) || !array_key_exists($class_two,$classes_2))
|
| 369 |
{
|
| 370 |
$success = false;
|
| 371 |
dbg($classes_2,'$classes_2');
|
| 372 |
$content = "$class_one not found OR $class_two not found. 3";
|
| 373 |
}
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
//update label
|
| 379 |
$new_label = 'This is the new label for property 1';
|
| 380 |
$this->sonia->updateLabel($property1, $new_label);
|
| 381 |
//$property_label_one_old = $property_label_one;
|
| 382 |
$property_label_one_r = $this->sonia->getLabel($property1);
|
| 383 |
//verify change was made
|
| 384 |
if ( $property_label_one_r != $new_label )
|
| 385 |
{
|
| 386 |
$success = false;
|
| 387 |
$content = "label was not updated properly - should be \"$new_label\"";
|
| 388 |
}
|
| 389 |
|
| 390 |
//delete property entirely
|
| 391 |
$this->sonia->deleteProperty($property1);
|
| 392 |
$class2_properties = $this->sonia->getAllClassProperties($count, $class_two);
|
| 393 |
//get all properties of each class
|
| 394 |
$class2_properties = $class2_properties['rdfs:domain']['subclasses'];
|
| 395 |
|
| 396 |
if (array_key_exists($property1,$class2_properties) || !array_key_exists($property2,$class2_properties))
|
| 397 |
{
|
| 398 |
$success = false;
|
| 399 |
$content = "$property1 *found* (and it should not be) OR $property2 not found. ";
|
| 400 |
}
|
| 401 |
|
| 402 |
//create same as class
|
| 403 |
if (!$success)
|
| 404 |
{
|
| 405 |
$this->total_success = false;
|
| 406 |
}
|
| 407 |
|
| 408 |
|
| 409 |
//add some more properties for later tests
|
| 410 |
for($i=0;$i<10;$i++)
|
| 411 |
{
|
| 412 |
$p{$i} = $this->sonia->createProperty("Label $i" );
|
| 413 |
$this->sonia->addPropertyToClass($class_two,$p{$i});
|
| 414 |
}
|
| 415 |
|
| 416 |
for($i=0;$i<$nc;$i++)
|
| 417 |
{
|
| 418 |
$p{$i} = $this->sonia->createProperty("Label $i" );
|
| 419 |
$class = $base_uri.$i;
|
| 420 |
$this->sonia->addPropertyToClass($class,$p{$i});
|
| 421 |
}
|
| 422 |
|
| 423 |
$this->sonia->deletePropertyFromClass($class_two, $property2);
|
| 424 |
|
| 425 |
$this->sonia->addPropertyToClass($class_one,$p{($i-1)});
|
| 426 |
|
| 427 |
$this->test_end('CRUD Class Properities ', 'Class Properties are added,
|
| 428 |
removed to classes, Searched for and deleted.', $content,$success);
|
| 429 |
}//end function
|
| 430 |
|
| 431 |
function create_objects($no,$nc)
|
| 432 |
{
|
| 433 |
$this->test_start();
|
| 434 |
$count = 0;
|
| 435 |
$content = 'All Passed';
|
| 436 |
$success = true;
|
| 437 |
$base_uri = $this->base_uri;
|
| 438 |
$original_class_label = 'My First Class';
|
| 439 |
$class_one = $base_uri.'0';
|
| 440 |
$class_two = $base_uri.'1';
|
| 441 |
$class_three = $base_uri.'2';
|
| 442 |
|
| 443 |
$object_one_name = 'OBJECT ONE';
|
| 444 |
$object_two_name = 'OBJECT TWO';
|
| 445 |
$object_three_name = 'OBJECT THREE';
|
| 446 |
$object_four_name = 'OBJECT FOUR';
|
| 447 |
|
| 448 |
$classes_one = array($class_one);
|
| 449 |
$classes_two = array($class_two,$class_three);
|
| 450 |
$classes_three = array($class_one,$class_three);
|
| 451 |
|
| 452 |
$class1_properties = $this->sonia->store->getAllClassPropertiesMultiple($count, $classes_one);
|
| 453 |
$class2_properties = $this->sonia->store->getAllClassPropertiesMultiple($count, $classes_two);
|
| 454 |
$class3_properties = $this->sonia->store->getAllClassPropertiesMultiple($count, $classes_three);
|
| 455 |
|
| 456 |
//what does this hack do?
|
| 457 |
$class1_properties = $class1_properties['rdfs:domain']['subclasses'];
|
| 458 |
$class2_properties = $class2_properties['rdfs:domain']['subclasses'];
|
| 459 |
$class3_properties = $class3_properties['rdfs:domain']['subclasses'];
|
| 460 |
|
| 461 |
srand(make_seed());
|
| 462 |
|
| 463 |
$object_create = ceil($no/$nc);
|
| 464 |
$total_created = $object_create * $nc;
|
| 465 |
//for each classes
|
| 466 |
for($i=0;$i<$nc;$i++)
|
| 467 |
{
|
| 468 |
$the_class = $base_uri.$i;
|
| 469 |
$props = $this->sonia->store->getAllClassPropertiesMultiple($count, $classes_one);
|
| 470 |
$props = $props['rdfs:domain']['subclasses'];
|
| 471 |
$count = 0;
|
| 472 |
$parameters = array();
|
| 473 |
|
| 474 |
foreach($props as $property => $label)
|
| 475 |
{
|
| 476 |
$randval = md5(rand(3,297824897025));
|
| 477 |
$parameters[$count]['uri'] = $property;
|
| 478 |
$parameters[$count]['value'] = $randval;
|
| 479 |
$count++;
|
| 480 |
|
| 481 |
}
|
| 482 |
|
| 483 |
for ($j =0;$j<=$object_create;$j++)
|
| 484 |
{
|
| 485 |
$object_name = 'OBJECT NAMED '.$i.':'.$j;
|
| 486 |
$object = $this->sonia->createObject(
|
| 487 |
$object_name, //TODO not needed?
|
| 488 |
$the_class,
|
| 489 |
$parameters
|
| 490 |
);
|
| 491 |
}
|
| 492 |
}
|
| 493 |
//get all it's properties
|
| 494 |
//create an object
|
| 495 |
dbg($object,'last $object created');
|
| 496 |
|
| 497 |
|
| 498 |
if (!$success)
|
| 499 |
{
|
| 500 |
$this->total_success = false;
|
| 501 |
}
|
| 502 |
|
| 503 |
// printTest('Created Objects - created '.$total_created.' in '.$total.' seconds',
|
| 504 |
// 'Objects are created...',$content,$success);
|
| 505 |
|
| 506 |
$this->test_end('Created Objects ', 'Objects are created...', $content,$success);
|
| 507 |
}
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
function search_classes($no,$nc)
|
| 513 |
{
|
| 514 |
|
| 515 |
|
| 516 |
$content = 'All Passed';
|
| 517 |
$success = true;
|
| 518 |
$base_uri = $this->base_uri;
|
| 519 |
$original_class_label = 'My First Class';
|
| 520 |
$class_one = $base_uri.'0';
|
| 521 |
$class_two = $base_uri.'1';
|
| 522 |
$class_three = $base_uri.'3';
|
| 523 |
|
| 524 |
//get all classes and their labels flat
|
| 525 |
//get count of related objects
|
| 526 |
//$result = $this->sonia->getAllClassesFlat();
|
| 527 |
//$all_classes_count = count($result);
|
| 528 |
|
| 529 |
//dbg($result,'$result $all_classes_count= '.$all_classes_count);
|
| 530 |
|
| 531 |
$this->test_start();
|
| 532 |
$result = $this->sonia->store->getAllCategoriesRecursive(); //this should work
|
| 533 |
$all_classes_count = count($all_classes_count);
|
| 534 |
if (empty($result) || $all_classes_count != 21)
|
| 535 |
{
|
| 536 |
$success = false;
|
| 537 |
$content = "getAllCategoriesRecursive() failed \$all_classes_count = $all_classes_count";
|
| 538 |
dbg($result,'$result = $this->sonia->getAllCategoriesRecursive();');
|
| 539 |
}
|
| 540 |
|
| 541 |
$this->test_end('Get All classes recursively as hierarchy', ' getAllCategoriesRecursive() ', "\$all_classes_count = $all_classes_count",$success);
|
| 542 |
|
| 543 |
//test format
|
| 544 |
$this->test_start();
|
| 545 |
$result = $this->sonia->classQuery(null);
|
| 546 |
$all_classes_count = count($result);
|
| 547 |
$this->test_end('Get All classes as list', ' one at a time ', "\$all_classes_count = $all_classes_count",$success);
|
| 548 |
|
| 549 |
$this->test_start();
|
| 550 |
$result = $this->sonia->propertyQuery();
|
| 551 |
$all_property_count = count($result);
|
| 552 |
$this->test_end('Get All Properties', ' $this->sonia->propertyQuery()', "\$all_property_count = $all_property_count" ,$success);
|
| 553 |
//dbg($result,'$result $all_property_count= '.$all_property_count);
|
| 554 |
//get all classes and their labels in hiearchy
|
| 555 |
//$result = $this->sonia->getAllCategoriesRecursive();
|
| 556 |
|
| 557 |
$base_uri = $this->base_uri;
|
| 558 |
|
| 559 |
$this->test_start();
|
| 560 |
for($i=0;$i<$no;$i++)
|
| 561 |
{
|
| 562 |
//get 100 objects one at a time
|
| 563 |
$object_uri = 'http://soniatest.org/ns/sonia_test/Object#id'.$i;
|
| 564 |
$object = $this->sonia->getObject($object_uri);
|
| 565 |
}
|
| 566 |
|
| 567 |
|
| 568 |
$this->test_end('Get All Objects', ' one at a time ', $object_uri,$success);
|
| 569 |
|
| 570 |
//get object labels
|
| 571 |
$this->test_start();
|
| 572 |
for($i=0;$i<$no;$i++)
|
| 573 |
{
|
| 574 |
//get 100 objects one at a time
|
| 575 |
$object_uri = 'http://soniatest.org/ns/sonia_test/Object#id'.$i;
|
| 576 |
$label = $this->sonia->getLabel($object_uri);
|
| 577 |
}
|
| 578 |
|
| 579 |
|
| 580 |
$this->test_end('Get All Objects Labels Only Sonia layer', ' one at a time ', $label,$success);
|
| 581 |
|
| 582 |
$this->test_start();
|
| 583 |
for($i=0;$i<$no;$i++)
|
| 584 |
{
|
| 585 |
//get 100 objects one at a time
|
| 586 |
$object_uri = 'http://soniatest.org/ns/sonia_test/Object#id'.$i;
|
| 587 |
$label = $this->sonia->store->getLabel($object_uri);
|
| 588 |
}
|
| 589 |
|
| 590 |
$this->test_end('Get All Objects Labels Only Store Layer', ' one at a time $this->sonia->store->getLabel($object_uri)', $label,$success);
|
| 591 |
|
| 592 |
|
| 593 |
$this->test_start();
|
| 594 |
for($i=0;$i<$no;$i++)
|
| 595 |
{
|
| 596 |
//get 100 objects one at a time
|
| 597 |
$object_uri = 'http://soniatest.org/ns/sonia_test/Object#id'.$i;
|
| 598 |
$classes = $this->sonia->getAllClassesOfObject($object_uri);
|
| 599 |
}
|
| 600 |
|
| 601 |
$this->test_end('Get All Classes of an object', 'TODO one at a time getAllClassesOfObject() ', $label,$success);
|
| 602 |
|
| 603 |
|
| 604 |
$this->test_start();
|
| 605 |
for($i=0;$i<$nc;$i++)
|
| 606 |
{
|
| 607 |
$sonia_search_array = null;
|
| 608 |
|
| 609 |
$class = $base_uri.$i;
|
| 610 |
$sonia_search_array[] = array (
|
| 611 |
'subject'=>null,
|
| 612 |
'predicate'=> SONIA_RDF_CREATE_TYPE,
|
| 613 |
'object'=>$class,
|
| 614 |
'literal_object'=>false,
|
| 615 |
'category_query'=>false);
|
| 616 |
|
| 617 |
$result = $this->sonia->query(0,$sonia_search_array,null,null,true,'','',true);
|
| 618 |
}
|
| 619 |
|
| 620 |
$this->test_end('Get All Objects of a class', 'one query per each class full query object', $label,$success);
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
$this->test_start();
|
| 625 |
for($i=0;$i<$nc;$i++)
|
| 626 |
{
|
| 627 |
$sonia_search_array = null;
|
| 628 |
|
| 629 |
$class = $base_uri.$i;
|
| 630 |
$sonia_search_array[] = array (
|
| 631 |
'subject'=>null,
|
| 632 |
'predicate'=> SONIA_RDF_CREATE_TYPE,
|
| 633 |
'object'=>$class,
|
| 634 |
'literal_object'=>false,
|
| 635 |
'category_query'=>false);
|
| 636 |
|
| 637 |
$class2 = $base_uri.($i+1);
|
| 638 |
$sonia_search_array[] = array (
|
| 639 |
'subject'=>null,
|
| 640 |
'predicate'=> SONIA_RDF_CREATE_TYPE,
|
| 641 |
'object'=>$class2,
|
| 642 |
'literal_object'=>false,
|
| 643 |
'category_query'=>false);
|
| 644 |
|
| 645 |
|
| 646 |
$result = $this->sonia->query(0,$sonia_search_array,null,null,true,'','',true);
|
| 647 |
}
|
| 648 |
|
| 649 |
$this->test_end('Get All Objects of TWO classes', 'one query per each class full query object', $label,$success);
|
| 650 |
|
| 651 |
$this->test_start();
|
| 652 |
for($i=0;$i<$nc;$i++)
|
| 653 |
{
|
| 654 |
$sonia_search_array = null;
|
| 655 |
|
| 656 |
$class = $base_uri.$i;
|
| 657 |
$sonia_search_array[] = array (
|
| 658 |
'subject'=>null,
|
| 659 |
'predicate'=> SONIA_RDF_CREATE_TYPE,
|
| 660 |
'object'=>$class,
|
| 661 |
'literal_object'=>false,
|
| 662 |
'category_query'=>false);
|
| 663 |
|
| 664 |
$class2 = $base_uri.($i+1);
|
| 665 |
$sonia_search_array[] = array (
|
| 666 |
'subject'=>null,
|
| 667 |
'predicate'=> SONIA_RDF_CREATE_TYPE,
|
| 668 |
'object'=>$class2,
|
| 669 |
'literal_object'=>false,
|
| 670 |
'category_query'=>false);
|
| 671 |
|
| 672 |
$class3 = $base_uri.($i+21);
|
| 673 |
$sonia_search_array[] = array (
|
| 674 |
'subject'=>null,
|
| 675 |
'predicate'=> SONIA_RDF_CREATE_TYPE,
|
| 676 |
'object'=>$class3,
|
| 677 |
'literal_object'=>false,
|
| 678 |
'category_query'=>false);
|
| 679 |
|
| 680 |
$result = $this->sonia->query(0,$sonia_search_array,null,null,true,'','',true);
|
| 681 |
}
|
| 682 |
|
| 683 |
$this->test_end('Get All Objects of THREE classes', 'one query per each class full query object', $label,$success);
|
| 684 |
|
| 685 |
|
| 686 |
///////////////////////////////////////////////////////////////////////////
|
| 687 |
$this->test_start();
|
| 688 |
|
| 689 |
$sonia_search_array[] = array (
|
| 690 |
'subject'=>null,
|
| 691 |
'predicate'=> SONIA_RDFS_CREATE_LABEL,
|
| 692 |
'object'=>'OBJECT',
|
| 693 |
'literal_object'=>true,
|
| 694 |
'category_query'=>false);
|
| 695 |
$result = $this->sonia->query(0,$sonia_search_array,null,null,true,'','',true);
|
| 696 |
$this->test_end('Get All Objects using FILTER - should succeed', 'one query ONLY!! one should have success, the other fail', $label,$success);
|
| 697 |
|
| 698 |
|
| 699 |
$this->test_start();
|
| 700 |
$sonia_search_array[] = array (
|
| 701 |
'subject'=>null,
|
| 702 |
'predicate'=> SONIA_RDFS_CREATE_LABEL,
|
| 703 |
'object'=>'YOU WONT FIND THIS..... ',
|
| 704 |
'literal_object'=>true,
|
| 705 |
'category_query'=>false);
|
| 706 |
$result = $this->sonia->query(0,$sonia_search_array,null,null,true,'','',true);
|
| 707 |
|
| 708 |
$this->test_end('Get All Objects using FILTER - should fail', 'one query ONLY!! one should have success, the other fail', $label,$success);
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
//give a class get objects and object labels
|
| 713 |
|
| 714 |
//give a class and get properies and labels
|
| 715 |
|
| 716 |
|
| 717 |
//give an object and get properties
|
| 718 |
|
| 719 |
//give and object and get classes and their labels
|
| 720 |
|
| 721 |
|
| 722 |
//give a property label and
|
| 723 |
|
| 724 |
|
| 725 |
//give a property ID and get classes which have it
|
| 726 |
|
| 727 |
//give a property ID and get objects which have it
|
| 728 |
|
| 729 |
|
| 730 |
//get all classes belonging to an object
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
$test_query =
|
| 735 |
'PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
| 736 |
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
| 737 |
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
| 738 |
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
|
| 739 |
PREFIX semantic_search: <http://semantic_search.civicactions.net/ns/semantic_search#>
|
| 740 |
PREFIX sonia: <http://sonia.civicactions.net/ns/sonia#>
|
| 741 |
PREFIX soniap: <http://fsearch.org/ns/sonia_test/Property#>
|
| 742 |
PREFIX carsf: <http://semantic_search.civicactions.net/ns/car-spacefinder#>
|
| 743 |
SELECT DISTINCT ?s ?p ?o
|
| 744 |
WHERE {
|
| 745 |
?s ?p ?o .
|
| 746 |
|
| 747 |
|
| 748 |
}';
|
| 749 |
|
| 750 |
//?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type .
|
| 751 |
//?type <http://www.w3.org/2000/01/rdf-schema#label> ?t_label .
|
| 752 |
|
| 753 |
//?p <http://www.w3.org/2000/01/rdf-schema#label> ?p_label .
|
| 754 |
//?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type .
|
| 755 |
//?type <http://www.w3.org/2000/01/rdf-schema#label> ?t_label .
|
| 756 |
|
| 757 |
/* PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
| 758 |
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
| 759 |
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
| 760 |
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
|
| 761 |
PREFIX semantic_search: <http://semantic_search.civicactions.net/ns/semantic_search#>
|
| 762 |
PREFIX sonia: <http://sonia.civicactions.net/ns/sonia#>
|
| 763 |
PREFIX soniap: <http://fsearch.org/ns/sonia_test/Property#>
|
| 764 |
PREFIX carsf: <http://semantic_search.civicactions.net/ns/car-spacefinder#>
|
| 765 |
SELECT DISTINCT ?s ?p ?p_label ?o ?t_label ?type
|
| 766 |
WHERE {
|
| 767 |
?s ?p ?o .
|
| 768 |
?p rdfs:label ?p_label .
|
| 769 |
?s rdf:type ?type .
|
| 770 |
?type rdfs:label ?t_label .
|
| 771 |
|
| 772 |
|
| 773 |
} */
|
| 774 |
//?p_label ?o ?t_label ?type
|
| 775 |
// ?p rdfs:label ?p_label .
|
| 776 |
//?s rdf:type ?type .
|
| 777 |
//?type rdfs:label ?t_label .
|
| 778 |
|
| 779 |
$this->test_start();
|
| 780 |
$results = $this->sonia->store->query($test_query, false, false);
|
| 781 |
if (!$success)
|
| 782 |
{
|
| 783 |
$this->total_success = false;
|
| 784 |
}
|
| 785 |
|
| 786 |
$this->test_end('Get All statements', ' ', $test_query,$success);
|
| 787 |
// print_r($results);
|
| 788 |
|
| 789 |
// if (array_key_exists($property1,$class2_properties) || !array_key_exists($property2,$class2_properties))
|
| 790 |
// {
|
| 791 |
// $success = false;
|
| 792 |
// $content = "$property1 *found* (and it should not be) OR $property2 not found. ";
|
| 793 |
// }
|
| 794 |
|
| 795 |
//get object, and it's params and labels by $uri
|
| 796 |
//get object, and it's params and labels by main label
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
//printTest('Search tests complete in '.$total.' seconds', 'Searches classes, objects and properties',$content,$success);
|
| 802 |
}
|
| 803 |
|
| 804 |
function add_properties_to_superclass()
|
| 805 |
{
|
| 806 |
$content = 'All Passed';
|
| 807 |
$success = true;
|
| 808 |
$base_uri = $this->base_uri;
|
| 809 |
$original_class_label = 'My First Class';
|
| 810 |
$class_one = $base_uri.'0';
|
| 811 |
$class_two = $base_uri.'1';
|
| 812 |
}
|
| 813 |
|
| 814 |
function test_subclass_properties()
|
| 815 |
{
|
| 816 |
$content = 'All Passed';
|
| 817 |
$success = true;
|
| 818 |
$base_uri = $this->base_uri;
|
| 819 |
$original_class_label = 'My First Class';
|
| 820 |
$class_one = $base_uri.'0';
|
| 821 |
$class_two = $base_uri.'1';
|
| 822 |
}
|
| 823 |
|
| 824 |
|
| 825 |
/**
|
| 826 |
* create classes with IDs provided, like drupal's Node ID
|
| 827 |
* */
|
| 828 |
function createClassesWithID($nc)
|
| 829 |
{
|
| 830 |
$success = false;
|
| 831 |
$content = '';
|
| 832 |
$class_amount = $nc;
|
| 833 |
$this->test_start();
|
| 834 |
|
| 835 |
$base_uri = 'http://mydrupalsite.com/node/';
|
| 836 |
for($i = 0; $i<$class_amount;$i++)
|
| 837 |
{
|
| 838 |
$uri = $this->sonia->createClass('My First Class '.$i,null,$base_uri.$i);
|
| 839 |
}
|
| 840 |
|
| 841 |
$exists = $this->sonia->classExists($uri) ;
|
| 842 |
|
| 843 |
//measure success by if the URIs match
|
| 844 |
$success = (($base_uri.($i-1) == $uri) && (SONIA_H :: is_IRI($uri)) && $exists);
|
| 845 |
if (!$success) $content .= "ERROR: $base_uri".($i-1)." == $uri ?";
|
| 846 |
$id1 = SONIA_H :: getIDFromURI($uri);
|
| 847 |
|
| 848 |
$class_with_given_id_with_underscore = $base_uri.'funny_name_is';
|
| 849 |
$uri = $this->sonia->createClass('My First Class',array(),$class_with_given_id_with_underscore);
|
| 850 |
$exists = $this->sonia->classExists($class_with_given_id_with_underscore) ;
|
| 851 |
|
| 852 |
if (!$exists)
|
| 853 |
{
|
| 854 |
$success = false;
|
| 855 |
$content = "ID was $class_with_given_id_with_underscore was not created";
|
| 856 |
}
|
| 857 |
|
| 858 |
|
| 859 |
if (!$success)
|
| 860 |
{
|
| 861 |
$this->total_success = false;
|
| 862 |
}
|
| 863 |
$this->test_end('Created GivenID classes ', 'An Identifeier is provided', $content,$success);
|
| 864 |
// printTest('Creating '.$class_amount.' ID included classes in '.$total.' seconds', 'Provides an ID in the form of a URI ',$content,$success);
|
| 865 |
//test to make sure duplicates are not allowed?
|
| 866 |
}
|
| 867 |
|
| 868 |
/**
|
| 869 |
* create classes that require an autoID
|
| 870 |
* */
|
| 871 |
function createClassesAutoID($nc)
|
| 872 |
{
|
| 873 |
|
| 874 |
$this->test_start();
|
| 875 |
$success = false;
|
| 876 |
$content = '';
|
| 877 |
$uri1 = $this->sonia->createClass('My First Class',null);
|
| 878 |
$id1 = SONIA_H :: getIDFromURI($uri1);
|
| 879 |
$content = "created class $uri1 with id <strong>$id1</strong>";
|
| 880 |
$success = SONIA_H :: is_IRI($uri1) && ($id1 == SONIA_AUTO_ID_PREFIX.'1') ;
|
| 881 |
if (!$success) $content = "Retrieved id ".$id1." from class $uri1";
|
| 882 |
printTest('Creating Standard Class 1', 'Requires the generation of an ID ',$content,$success);
|
| 883 |
|
| 884 |
|
| 885 |
//////////////////////////////////////////////////
|
| 886 |
//create 10 more
|
| 887 |
$created_classes = $nc;
|
| 888 |
|
| 889 |
for($i=0;$i<$created_classes;$i++)
|
| 890 |
{
|
| 891 |
$turi = $this->sonia->createClass('CLASS '.$i,null);
|
| 892 |
}
|
| 893 |
$tid = SONIA_H :: getIDFromURI($turi);
|
| 894 |
$success = SONIA_H :: is_IRI($turi) && ($tid == SONIA_AUTO_ID_PREFIX.($nc+1)) ;
|
| 895 |
$content = "created class $turi with id <strong>$tid</strong>";
|
| 896 |
if (!$success) $content = "Retrieved id ".$tid." from class ".SONIA_AUTO_ID_PREFIX.($nc-1);
|
| 897 |
if (!$success)
|
| 898 |
{
|
| 899 |
$this->total_success = false;
|
| 900 |
}
|
| 901 |
|
| 902 |
//printTest('Created '.$created_classes.' classes with Genderated IDs in '.$total.' seconds.', 'Requires the generation of an ID ',$content,$success);
|
| 903 |
|
| 904 |
$this->test_end('Created AutoID classes ', 'Requires Generation of an id', $content,$success);
|
| 905 |
////////////////////////////////////////////
|
| 906 |
}
|
| 907 |
|
| 908 |
|
| 909 |
//destroy ARC DB
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
///////////////////////////////////////////////////////////////////////////////
|
| 914 |
/// these functions shouldn't change
|
| 915 |
|
| 916 |
/**
|
| 917 |
* bootstrap order is very important :)
|
| 918 |
* */
|
| 919 |
function init()
|
| 920 |
{
|
| 921 |
global $tests;
|
| 922 |
|
| 923 |
$this->tests = $tests;
|
| 924 |
$this->test_count = count($tests);
|
| 925 |
|
| 926 |
printTestName('Starting Sonia Tests', 'Beggining '.$this->test_count.' tests of Sonia.
|
| 927 |
<br />PHP Version '. phpversion());
|
| 928 |
|
| 929 |
|
| 930 |
require SONIA_LOCATION.'/sonia.php';
|
| 931 |
//init sonia
|
| 932 |
|
| 933 |
$this->sonia = new SONIA(
|
| 934 |
SONIA_BACKEND_TYPE,
|
| 935 |
SONIA_FORM_ARRAY_PREFIX,
|
| 936 |
'drupal',
|
| 937 |
null,
|
| 938 |
null,
|
| 939 |
true //create a database
|
| 940 |
);
|
| 941 |
|
| 942 |
$port = ARC_DB_PORT;
|
| 943 |
if (!empty( $port ))
|
| 944 |
{
|
| 945 |
$port = ':' . $port;
|
| 946 |
}
|
| 947 |
|
| 948 |
|
| 949 |
$this->dbconn = new SONIA_TEST_MYSQL_DB(ARC_DB_NAME,ARC_DB_PW,ARC_DB_USER,ARC_DB_HOST.$port);
|
| 950 |
$sql = 'SELECT * FROM `'.SONIA_DB_PREFIX_NAME.'_id2val`';
|
| 951 |
$result = $this->dbconn->get_array($sql);
|
| 952 |
$content = 'Passed uneventfully.';
|
| 953 |
$success = (!empty($result[0]['id']));
|
| 954 |
if (!$success) $content = 'Test may have failed because the tables already exist. Change SONIA_TEST_CLEANUP in your config file';
|
| 955 |
printTest('Creating DB', 'Creates an Arc Database',$content,$success);
|
| 956 |
|
| 957 |
}
|
| 958 |
|
| 959 |
//Create ARC DB
|
| 960 |
function create_database()
|
| 961 |
{
|
| 962 |
if (!class_exists('SONIAARCStore'))
|
| 963 |
{
|
| 964 |
set_sonia_configs('sonia_arc_local','drupal');
|
| 965 |
}
|
| 966 |
|
| 967 |
$this->store = new SONIAARCStore(null);
|
| 968 |
//basic check
|
| 969 |
$success = $this->store instanceof SONIAStoreAPI;
|
| 970 |
$content = '';
|
| 971 |
|
| 972 |
printTest('Creating Store Object', 'Creates a SONIA store object.',$content,$success);
|
| 973 |
|
| 974 |
$content = 'Passed uneventfully.';
|
| 975 |
$table_names = $this->store->installBackend('sprintf');
|
| 976 |
//print_r($table_names);
|
| 977 |
$success = (!empty($table_names))? true : false;
|
| 978 |
|
| 979 |
|
| 980 |
}
|
| 981 |
|
| 982 |
|
| 983 |
function test_start()
|
| 984 |
{
|
| 985 |
$this->test_start_time = this_microtime();
|
| 986 |
}
|
| 987 |
|
| 988 |
|
| 989 |
function test_end($title,$sub, $content,$success)
|
| 990 |
{
|
| 991 |
|
| 992 |
printTest($title,$sub,$content,$success);
|
| 993 |
if (!$success) $this->total_success = false;
|
| 994 |
|
| 995 |
$memory = memory_get_usage();
|
| 996 |
$time = this_microtime() - $this->test_start_time;
|
| 997 |
$this->all_test_results[$title]['time'] = $time;
|
| 998 |
$this->all_test_results[$title]['subtitle'] = $sub;
|
| 999 |
$this->all_test_results[$title]['comments'] = $content;
|
| 1000 |
$this->all_test_results[$title]['memory'] = $memory;
|
| 1001 |
$this->all_test_results[$title]['success'] = $success;
|
| 1002 |
}
|
| 1003 |
|
| 1004 |
/**
|
| 1005 |
* @param string truncate or drop
|
| 1006 |
* */
|
| 1007 |
function testcleanup($action = 'DROP')
|
| 1008 |
{
|
| 1009 |
//`".SONIA_DB_PREFIX_NAME."_store_var`,
|
| 1010 |
//remove databases
|
| 1011 |
$content = '';
|
| 1012 |
$sql = "$action TABLE `".SONIA_DB_PREFIX_NAME."_id2val`, `".SONIA_DB_PREFIX_NAME."_triple`, `".SONIA_DB_PREFIX_NAME."_triple_dup`, `".SONIA_DB_PREFIX_NAME."_triple_all_wdup`;";
|
| 1013 |
$success = $this->dbconn->query($sql);
|
| 1014 |
if (!$success)
|
| 1015 |
{
|
| 1016 |
$this->total_success = false;
|
| 1017 |
$content = print_r($success,1);
|
| 1018 |
$content .= mysql_error();
|
| 1019 |
}
|
| 1020 |
printTest('Database Cleaned', ' The database has removed traces of the test ',$sql,$success);
|
| 1021 |
printTest('ALL TESTS STATUS', ' The status of all tests',$content, $this->total_success);
|
| 1022 |
}
|
| 1023 |
|
| 1024 |
} //end class
|
| 1025 |
?>
|