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 | public function test_serialize() {
|
---|
60 |
|
---|
61 | $validTypes = array( 'application/rdf+xml',
|
---|
62 | 'application/rdfxml',
|
---|
63 | 'text/turtle',
|
---|
64 | 'application/x-turtle',
|
---|
65 | 'text/n3',
|
---|
66 | 'application/json');
|
---|
67 |
|
---|
68 |
|
---|
69 | // this call must fail , returning false
|
---|
70 | $doc = $this->rdfaData->_serialize( 'dummy');
|
---|
71 | $this->assertEquals( ($doc === false), true);
|
---|
72 |
|
---|
73 | // these call must return a proper serialization
|
---|
74 | foreach ( $validTypes as $type) {
|
---|
75 | $doc = $this->rdfaData->_serialize( $type);
|
---|
76 | $this->assertEquals( ($doc !== false), true);
|
---|
77 | $this->assertEquals( (strlen($doc) > 0), true);
|
---|
78 | }
|
---|
79 |
|
---|
80 | } // public function test_serialize()
|
---|
81 |
|
---|
82 | } // class UnitTest
|
---|
83 |
|
---|
84 |
|
---|