source: php/trunk/unittest/rdfa_simple_api/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: 3.1 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_getSubjects( ) {
61
62 $aExpectedSubjects = array( 'resource:12345',
63 'resource:67890',
64 'resource:13579');
65
66 $aUriPersons = $this->rdfaData->getSubjects( 'rdf:type', 'foaf:Person');
67 $this->assertEquals( $aUriPersons, $aExpectedSubjects);
68
69 } // public function test_getSubjects()
70
71 // --------------------------------------------------------
72
73 public function test_getPersonDetails() {
74
75 // get uri of first subject
76 $aUriPersons = $this->rdfaData->getSubjects( 'rdf:type', 'foaf:Person');
77 $uriPerson = $aUriPersons[ 0];
78
79 // retrieve name
80 $litName = $this->rdfaData->_getFirstValue( $uriPerson, 'foaf:name');
81 $this->assertInternalType( 'string', $litName);
82 $this->assertGreaterThan( 0, strlen( $litName));
83
84 // get blank node uri for work data
85 $aUriWork = $this->rdfaData->getValues( $uriPerson, 'foaf:work');
86 $this->assertInternalType( 'array', $aUriWork);
87 $this->assertEquals( 1, count( $aUriWork));
88
89 // retrieve city name
90 $litCity = $this->rdfaData->_getFirstValue( $aUriWork[ 0], 'foaf:city');
91 $this->assertInternalType( 'string', $litCity);
92 $this->assertGreaterThan( 0, strlen( $litCity));
93
94 } // public function test_getPersonDetails()
95
96} // class UnitTest
97
98
Note: See TracBrowser for help on using the repository browser.