1<?php
2require_once('stratatest.inc.php');
3
4/**
5 * Tests storage removing.
6 *
7 * @group plugin_strata_storage
8 * @group plugin_strata
9 * @group plugins
10 */
11class storage_removes_test extends Strata_UnitTestCase {
12
13	function setup() {
14		parent::setup();
15		// Fill database
16		$OK = $this->_triples->addTriple('Bob', 'knows', 'Alice', 'wiki');
17		$this->assertTrue($OK);
18		$OK =$this->_triples->addTriple('Alice', 'knows', 'Carol', 'wiki');
19		$this->assertTrue($OK);
20		$OK =$this->_triples->addTriple('Alice', 'dislikes', 'Carol', 'wiki');
21		$this->assertTrue($OK);
22
23		$this->expected1 = array('subject' => 'Bob', 'predicate' => 'knows', 'object' => 'Alice', 'graph' => 'wiki');
24		$this->expected2 = array('subject' => 'Alice', 'predicate' => 'knows', 'object' => 'Carol', 'graph' => 'wiki');
25		$this->expected3 = array('subject' => 'Alice', 'predicate' => 'dislikes', 'object' => 'Carol', 'graph' => 'wiki');
26
27		$data = $this->_triples->fetchTriples();
28		$this->assertEquals($data, array($this->expected1, $this->expected2, $this->expected3));
29	}
30
31	function testRemove() {
32		// Remove all
33		$this->_triples->removeTriples();
34		$data = $this->_triples->fetchTriples();
35                $this->assertEquals($data, array());
36	}
37
38	function testRemoveBySubject() {
39		$this->_triples->removeTriples('Bob');
40		$data = $this->_triples->fetchTriples();
41                $this->assertEquals($data, array($this->expected2, $this->expected3));
42
43		$this->_triples->removeTriples('Alice');
44		$data = $this->_triples->fetchTriples();
45                $this->assertEquals($data, array());
46	}
47
48	function testRemoveByPredicate() {
49		$this->_triples->removeTriples(null, 'knows');
50		$data = $this->_triples->fetchTriples();
51                $this->assertEquals($data, array($this->expected3));
52
53		$this->_triples->removeTriples(null, 'dislikes');
54		$data = $this->_triples->fetchTriples();
55                $this->assertEquals($data, array());
56	}
57
58	function testRemoveByObject() {
59		$this->_triples->removeTriples(null, null, 'Alice');
60		$data = $this->_triples->fetchTriples();
61                $this->assertEquals($data, array($this->expected2, $this->expected3));
62
63		$this->_triples->removeTriples(null, null, 'Carol');
64		$data = $this->_triples->fetchTriples();
65                $this->assertEquals($data, array());
66	}
67
68	function testRemoveBySubjectAndPredicate() {
69		$this->_triples->removeTriples('Alice', 'knows');
70		$data = $this->_triples->fetchTriples();
71                $this->assertEquals($data, array($this->expected1, $this->expected3));
72	}
73
74	function testRemoveByPredicateAndObject() {
75		$this->_triples->removeTriples(null, 'knows', 'Carol');
76		$data = $this->_triples->fetchTriples();
77                $this->assertEquals($data, array($this->expected1, $this->expected3));
78	}
79
80	function testRemoveCaseInsensitive() {
81		$this->_triples->removeTriples('bob');
82		$data = $this->_triples->fetchTriples();
83                $this->assertEquals($data, array($this->expected2, $this->expected3));
84
85		$this->_triples->removeTriples(null, 'Knows');
86		$data = $this->_triples->fetchTriples();
87                $this->assertEquals($data, array($this->expected3));
88
89		$this->_triples->removeTriples(null, null, 'carol');
90		$data = $this->_triples->fetchTriples();
91                $this->assertEquals($data, array());
92	}
93}
94
95