| 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 | $FirstTurtlefile = "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( $FirstTurtlefile);
|
|---|
| 55 | $aUriPersons = $this->rdfaData->getSubjects( 'rdf:type', 'foaf:Person');
|
|---|
| 56 | $this->assertEquals( count( $aUriPersons), 2);
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | // --------------------------------------------------------
|
|---|
| 60 |
|
|---|
| 61 | public function test_merge() {
|
|---|
| 62 |
|
|---|
| 63 | $SecondTurtlefile = "unittest2.ttl";
|
|---|
| 64 | $uriPerson = 'resource:67890';
|
|---|
| 65 |
|
|---|
| 66 | // merge 2nd graph
|
|---|
| 67 | $this->rdfaData->parse( $SecondTurtlefile);
|
|---|
| 68 |
|
|---|
| 69 | // make sure 2nd person is merged properly
|
|---|
| 70 | $aUriPersons = $this->rdfaData->getSubjects( 'rdf:type', 'foaf:Person');
|
|---|
| 71 | $this->assertEquals( count( $aUriPersons), 3);
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 | // CURRENTLY NOT SOLVED :::
|
|---|
| 75 | // make sure that the blank node for the duplicate person is merged
|
|---|
| 76 | // properly as well: this blank node may exist only once in the merged data
|
|---|
| 77 | // $aUriDuplicateBlankNodes = $this->rdfaData->getValues( $uriPerson, 'foaf:work');
|
|---|
| 78 | // $this->assertEquals( count( $aUriDuplicateBlankNodes), 1);
|
|---|
| 79 |
|
|---|
| 80 | } // public function test_merge()
|
|---|
| 81 |
|
|---|
| 82 | } // class UnitTest
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|