|
1 <?php |
|
2 |
|
3 use CorpusParole\Libraries\Sparql\SparqlQueryAnalyser; |
|
4 |
|
5 class SparqlQueryAnalyserTest extends TestCase |
|
6 { |
|
7 const QUERIES = [ |
|
8 "BASE" => "base.sparql", |
|
9 "ASK" => "ask.sparql", |
|
10 "GRAPH" => "graph.sparql", |
|
11 "LIMIT_OFFSET" => "limit_offset.sparql", |
|
12 "PREFIXES" => "prefixes.sparql", |
|
13 "SELECT" => "select.sparql", |
|
14 "UNKNOWN" => "unknown.sparql", |
|
15 ]; |
|
16 |
|
17 |
|
18 public function getTestQuery($key) { |
|
19 return file_get_contents(__DIR__.'/files/SparqlQueryAnalyserTest/'.self::QUERIES[$key]); |
|
20 } |
|
21 /** |
|
22 * A basic test jsut test object creation. |
|
23 * |
|
24 * @return void |
|
25 */ |
|
26 public function testCreation() { |
|
27 $analyser = new SparqlQueryAnalyser($this->getTestQuery("BASE")); |
|
28 $this->assertNotNull($analyser); |
|
29 } |
|
30 |
|
31 public function testQuerySelect() { |
|
32 $analyser = new SparqlQueryAnalyser($this->getTestQuery("SELECT")); |
|
33 $this->assertEquals(SparqlQueryAnalyser::SELECT_QUERY, $analyser->getQueryType()); |
|
34 } |
|
35 |
|
36 public function testQueryGraph() { |
|
37 $analyser = new SparqlQueryAnalyser($this->getTestQuery("GRAPH")); |
|
38 $this->assertEquals(SparqlQueryAnalyser::GRAPH_QUERY, $analyser->getQueryType()); |
|
39 } |
|
40 |
|
41 public function testQueryAsk() { |
|
42 $analyser = new SparqlQueryAnalyser($this->getTestQuery("ASK")); |
|
43 $this->assertEquals(SparqlQueryAnalyser::ASK_QUERY, $analyser->getQueryType()); |
|
44 } |
|
45 |
|
46 public function testQueryUnkown() { |
|
47 $analyser = new SparqlQueryAnalyser($this->getTestQuery("UNKNOWN")); |
|
48 $this->assertEquals(SparqlQueryAnalyser::UNKNOWN_QUERY, $analyser->getQueryType()); |
|
49 } |
|
50 |
|
51 public function testLimitOffset() { |
|
52 $analyser = new SparqlQueryAnalyser($this->getTestQuery("LIMIT_OFFSET")); |
|
53 $this->assertEquals(20, $analyser->getOffset()); |
|
54 $this->assertEquals(10, $analyser->getLimit()); |
|
55 } |
|
56 |
|
57 public function testPrefixes() { |
|
58 $analyser = new SparqlQueryAnalyser($this->getTestQuery("PREFIXES")); |
|
59 $this->assertCount(5, $analyser->getPrefixes()); |
|
60 $this->assertEquals([ |
|
61 "" => "http://www.google.com/", |
|
62 "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", |
|
63 "rdfs" => "http://www.w3.org/2000/01/rdf-schema#", |
|
64 "foaf" => "http://xmlns.com/foaf/0.1/", |
|
65 "dbpedia-owl" => "http://dbpedia.org/ontology/" |
|
66 ], $analyser->getPrefixes()); |
|
67 } |
|
68 |
|
69 public function testRawPrefixes() { |
|
70 $analyser = new SparqlQueryAnalyser($this->getTestQuery("PREFIXES")); |
|
71 $this->assertCount(5, $analyser->getRawPrefixes()); |
|
72 $this->assertEquals([ |
|
73 "BASE <http://www.google.com/>", |
|
74 "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>", |
|
75 "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>", |
|
76 "prefix foaf: <http://xmlns.com/foaf/0.1/>", |
|
77 "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>" |
|
78 ], $analyser->getRawPrefixes()); |
|
79 } |
|
80 |
|
81 } |