source: php/trunk/unittest/rdfa_projections/unittest.php

Last change on this file was 27, checked in by cla, 14 years ago

rdfint

  • reworked library setup for samples and unittests
  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
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
21define( 'RDFINT', getenv( 'PHP_LIBROOT_RDFINT'));
22require_once( RDFINT.'/rdfa.php');
23
24class 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 $aTemplatePerson = array( 'name' => 'foaf:name',
63 'uri_work' => 'foaf:work');
64 $aTemplateWorkAdress = array( 'city' => 'foaf:city');
65
66 // get first object
67 $aPersons = $this->rdfaData->getProjections( 'rdf:type', 'foaf:Person', $aTemplatePerson);
68 $this->assertEquals( 3, count( $aPersons));
69 $person = $aPersons[ 0];
70 $this->assertInstanceOf( '\rdfa\Projection', $aPersons[ 0]);
71
72 // retrieve name
73 $litName = $person->name;
74 $this->assertInternalType( 'string', $litName);
75 $this->assertGreaterThan( 0, strlen( $litName));
76
77 // get blank node uri for work data
78 $work = $this->rdfaData->getProjection( $person->uri_work, $aTemplateWorkAdress);
79 $this->assertInstanceOf( '\rdfa\Projection', $work);
80
81 // retrieve city name
82 $litCity = $work->city;
83 $this->assertInternalType( 'string', $litCity);
84 $this->assertGreaterThan( 0, strlen( $litCity));
85
86 } // public function test_getPersonDetails()
87
88} // class UnitTest
89
90
Note: See TracBrowser for help on using the repository browser.