source: php/trunk/unittest/rdfa_set/unittest.php

Last change on this file was 37, checked in by ktk, 14 years ago

rdfint

  • fixes for unittest
  • Property svn:eol-style set to native
File size: 3.5 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_BasicApi_Set() {
61
62 $uriPerson = 'resource:12345';
63 $uriMailbox = 'mailto:cla@clanganke.de';
64 $aTemplatePerson = array( 'mbox' => 'foaf:mbox');
65
66 // use basic API to write new property value
67 $result = $this->rdfaData->_setValue( $uriPerson, 'foaf:mbox', $uriMailbox, 'URI');
68 $this->assertEquals( $result, true);
69
70 // use invalid value type - must fail
71 $result = $this->rdfaData->_setValue( $uriPerson, 'foaf:mbox', $uriMailbox, 'wrongtype');
72 $this->assertEquals( $result, false);
73
74 // read new value with a projection
75 $person = $this->rdfaData->getProjection( $uriPerson, $aTemplatePerson);
76 $this->assertInstanceOf( '\rdfa\Projection', $person);
77 $this->assertEquals( $uriMailbox, $person->mbox);
78
79 } // public function function test_BasicApi_Set()
80
81 // --------------------------------------------------------
82
83 public function test_Projection_Set() {
84
85 $uriPerson = 'resource:67890';
86 $uriMailbox = 'mailto:ktk@netlabs.org';
87 $aTemplatePerson = array( 'mbox' => 'foaf:mbox');
88
89 // use projection to write new property value
90 $person = $this->rdfaData->getProjection( $uriPerson, $aTemplatePerson);
91 $this->assertInstanceOf( '\rdfa\Projection', $person);
92 $result = $person->set( 'foaf:mbox', $uriMailbox, 'URI');
93 $this->assertInstanceOf( '\rdfa\Projection', $result);
94
95 // use invalid value type - must fail
96 $result = $person->set( 'foaf:mbox', $uriMailbox, 'wrongtype');
97 $this->assertEquals( $result, false);
98
99 // read new value with the basic API
100 $newmbox = $this->rdfaData->_getFirstValue( $uriPerson, 'foaf:mbox');
101 $this->assertEquals( $uriMailbox, $newmbox);
102
103 } // public function test_Projection_Set()
104
105} // class UnitTest
106
107
Note: See TracBrowser for help on using the repository browser.