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