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 | $turtlefile = "unittest.ttl";
|
---|
40 | $aNamespace = array( 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
|
---|
41 | 'foaf' => 'http://xmlns.com/foaf/0.1/',
|
---|
42 | 'resource' => 'http://data.uduvudu.org/resource/');
|
---|
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 | // parse data
|
---|
54 | $this->rdfaData->parse( $turtlefile);
|
---|
55 |
|
---|
56 | }
|
---|
57 |
|
---|
58 | // --------------------------------------------------------
|
---|
59 |
|
---|
60 | public function test_getPersonDetails() {
|
---|
61 |
|
---|
62 | $searchedName = 'Adrian Gschwend';
|
---|
63 |
|
---|
64 | $aTemplatePerson = array( 'name' => 'foaf:name',
|
---|
65 | 'uri_work' => 'foaf:work');
|
---|
66 | $aTemplateWorkAdress = array( 'city' => 'foaf:city');
|
---|
67 |
|
---|
68 | $aQueryPerson = array( 'rdf:type' => 'foaf:Person',
|
---|
69 | 'foaf:name' => $searchedName);
|
---|
70 |
|
---|
71 | // get first object
|
---|
72 | $aPersons = $this->rdfaData->query( $aQueryPerson, $aTemplatePerson);
|
---|
73 | $this->assertEquals( 1, count( $aPersons));
|
---|
74 | $person = $aPersons[ 0];
|
---|
75 | $this->assertInstanceOf( '\rdfa\Projection', $person);
|
---|
76 |
|
---|
77 | // retrieve name
|
---|
78 | $litName = $person->name;
|
---|
79 | $this->assertInternalType( 'string', $litName);
|
---|
80 | $this->assertGreaterThan( 0, strlen( $litName));
|
---|
81 |
|
---|
82 | // get blank node uri for work data
|
---|
83 | $work = $this->rdfaData->getProjection( $person->uri_work, $aTemplateWorkAdress);
|
---|
84 | $this->assertInstanceOf( '\rdfa\Projection', $work);
|
---|
85 |
|
---|
86 | // retrieve city name
|
---|
87 | $litCity = $work->city;
|
---|
88 | $this->assertInternalType( 'string', $litCity);
|
---|
89 | $this->assertGreaterThan( 0, strlen( $litCity));
|
---|
90 |
|
---|
91 | } // public function test_getPersonDetails()
|
---|
92 |
|
---|
93 | } // class UnitTest
|
---|
94 |
|
---|
95 |
|
---|