1 | <?PHP
|
---|
2 |
|
---|
3 | /* RDFInt.php - RDF Interfaces for PHP
|
---|
4 | * Copyright 2011 netlabs.org
|
---|
5 | * Author: Christian Langanke, Adrian Gschwend
|
---|
6 | *
|
---|
7 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
8 | * you may not use this file except in compliance with the License.
|
---|
9 | * You may obtain a copy of the License at
|
---|
10 | *
|
---|
11 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
12 | *
|
---|
13 | * Unless required by applicable law or agreed to in writing, software
|
---|
14 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
16 | * See the License for the specific language governing permissions and
|
---|
17 | * limitations under the License.
|
---|
18 | */
|
---|
19 |
|
---|
20 | // load library setup
|
---|
21 | define( 'RDFINT', getenv( 'PHP_LIBROOT_RDFINT'));
|
---|
22 | require_once( RDFINT.'/rdfa.php');
|
---|
23 |
|
---|
24 | class UnitTest extends PHPUnit_Framework_TestCase
|
---|
25 | {
|
---|
26 | protected $rdfaData;
|
---|
27 |
|
---|
28 | // --------------------------------------------------------
|
---|
29 |
|
---|
30 | public static function setUpBeforeClass() {
|
---|
31 | $testcase = basename( getcwd());
|
---|
32 | echo "Executing library testcase: $testcase\n\n";
|
---|
33 | }
|
---|
34 |
|
---|
35 | // --------------------------------------------------------
|
---|
36 |
|
---|
37 | protected function setUp() {
|
---|
38 |
|
---|
39 | $aNamespace = array( 'dbo' => 'http://dbpedia.org/ontology/',
|
---|
40 | 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
|
---|
41 | 'dcterms' => 'http://purl.org/dc/terms/'
|
---|
42 | );
|
---|
43 |
|
---|
44 | // setup data RDF object
|
---|
45 | $this->rdfaData = new \rdfa\Data();
|
---|
46 | $this->assertInstanceOf( '\rdfa\Data', $this->rdfaData);
|
---|
47 |
|
---|
48 | // setup namespace mappings
|
---|
49 | foreach ( $aNamespace as $prefix => $uriNamespace) {
|
---|
50 | $this->rdfaData->setMapping( $prefix, $uriNamespace);
|
---|
51 | }
|
---|
52 |
|
---|
53 | }
|
---|
54 |
|
---|
55 | // --------------------------------------------------------
|
---|
56 |
|
---|
57 | public function test_parse_sparql() {
|
---|
58 |
|
---|
59 | $uriCityToSearch = 'http://dbpedia.org/resource/Biel/Bienne';
|
---|
60 |
|
---|
61 | $config = array(
|
---|
62 | 'remote_store_endpoint' => 'http://dbpedia.org/sparql',
|
---|
63 | 'reader_timeout' => 30
|
---|
64 | );
|
---|
65 |
|
---|
66 | $statement = '
|
---|
67 | PREFIX dbo: <http://dbpedia.org/ontology/>
|
---|
68 | PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
---|
69 | PREFIX dcterms: <http://purl.org/dc/terms/>
|
---|
70 |
|
---|
71 | CONSTRUCT
|
---|
72 | {
|
---|
73 | ?s rdfs:label ?city_name .
|
---|
74 | }
|
---|
75 | WHERE {
|
---|
76 | ?s dcterms:subject <http://dbpedia.org/resource/Category:Cities_in_Switzerland> .
|
---|
77 | ?s rdfs:label ?city_name FILTER (LANG(?city_name) = "en")
|
---|
78 | }
|
---|
79 | ';
|
---|
80 |
|
---|
81 | // create endpoint configuration object
|
---|
82 | $endpoint = new \rdfa\SparqlEndpoint( $config);
|
---|
83 | $this->assertInstanceOf( '\rdfa\SparqlEndpoint', $endpoint);
|
---|
84 |
|
---|
85 | // create SPARQL eury object
|
---|
86 | $query = new \rdfa\SparqlQuery( $endpoint, $statement);
|
---|
87 | $this->assertInstanceOf( '\rdfa\SparqlQuery', $query);
|
---|
88 |
|
---|
89 | // test sparql query directly
|
---|
90 | $rdfdata = $query->run();
|
---|
91 | $this->assertEquals( ($rdfdata !== false), true);
|
---|
92 |
|
---|
93 | // let the parse method execute the query to
|
---|
94 | $result = $this->rdfaData->parse( $query);
|
---|
95 | $this->assertEquals( ($result !== false), true);
|
---|
96 |
|
---|
97 | $aSubject = $this->rdfaData->getSubjects();
|
---|
98 | $this->assertGreaterThan( 0, count( $aSubject));
|
---|
99 | $this->assertContains( $uriCityToSearch, $aSubject);
|
---|
100 |
|
---|
101 | } // public function test_parse_sparql()
|
---|
102 |
|
---|
103 | } // class UnitTest
|
---|
104 |
|
---|
105 |
|
---|