1<?php 2require_once('stratatest.inc.php'); 3 4/** 5 * Tests storage. 6 * 7 * @group plugin_strata_storage 8 * @group plugin_strata 9 * @group plugins 10 */ 11class storage_test extends Strata_UnitTestCase { 12 13 function testAdd() { 14 $OK = $this->_triples->addTriple('Bob', 'knows', 'Alice', 'wiki'); 15 $this->assertTrue($OK); 16 $data = $this->_triples->fetchTriples(); 17 $expected = array( 18 array('subject' => 'Bob', 'predicate' => 'knows', 'object' => 'Alice', 'graph' => 'wiki') 19 ); 20 $this->assertEquals($data, $expected); 21 } 22 23 function testAddArray() { 24 $OK = $this->_triples->addTriples(array(array('subject' => 'Bob', 'predicate' => 'knows', 'object' => 'Alice')), 'wiki'); 25 $this->assertTrue($OK); 26 $data = $this->_triples->fetchTriples(); 27 $expected = array( 28 array('subject' => 'Bob', 'predicate' => 'knows', 'object' => 'Alice', 'graph' => 'wiki') 29 ); 30 $this->assertEquals($data, $expected); 31 } 32 33 function testAddMulti() { 34 $OK = $this->_triples->addTriple('Bob', 'knows', 'Alice', 'wiki'); 35 $this->assertTrue($OK); 36 $OK =$this->_triples->addTriple('Alice', 'knows', 'Carol', 'wiki'); 37 $this->assertTrue($OK); 38 $data = $this->_triples->fetchTriples(); 39 $expected = array( 40 array('subject' => 'Bob', 'predicate' => 'knows', 'object' => 'Alice', 'graph' => 'wiki'), 41 array('subject' => 'Alice', 'predicate' => 'knows', 'object' => 'Carol', 'graph' => 'wiki') 42 ); 43 $this->assertEquals($data, $expected); 44 } 45 46 function testSpecialChars() { 47 $OK = $this->_triples->addTriple('*', 'select', '%', 'wiki'); 48 $this->assertTrue($OK); 49 $OK =$this->_triples->addTriple('_', '(', '`', 'wiki'); 50 $this->assertTrue($OK); 51 $OK =$this->_triples->addTriple(';', '\'', '"', 'wiki'); 52 $this->assertTrue($OK); 53 $data = $this->_triples->fetchTriples(); 54 $expected = array( 55 array('subject' => '*', 'predicate' => 'select', 'object' => '%', 'graph' => 'wiki'), 56 array('subject' => '_', 'predicate' => '(', 'object' => '`', 'graph' => 'wiki'), 57 array('subject' => ';', 'predicate' => '\'', 'object' => '"', 'graph' => 'wiki') 58 ); 59 $this->assertEquals($data, $expected); 60 } 61} 62 63