source: php/trunk/unittest/rdftestcases/unittest.php@ 56

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

rdfint

  • added export or original and parsed data of failing unittests related to W3C 'RDF Test Cases'

(Finding: failing 'positive parser tests' cannot be properly compared by current unittest code:
blank nodes have different identifiers, so the string compare will always fail.
Except for 'xml-canon/test001', all other test cases do not fail with ARC2!)

  • Property svn:eol-style set to native
File size: 3.2 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 static protected $baseuri;
27 private $testcase;
28 const BASEURI = 'http://www.w3.org/2000/10/rdf-tests/rdfcore';
29
30 // --------------------------------------------------------
31
32 public static function setUpBeforeClass() {
33 $testcase = trim( getenv( 'TESTCASE'));
34 echo "Executing RDF testcase: $testcase\n\n";
35 }
36
37 // --------------------------------------------------------
38
39 protected function setUp() {
40 }
41
42 // --------------------------------------------------------
43
44 private function _writeErrorData( $testcase,
45 $source, $sourceuri,
46 $result, $resulturi) {
47 if (!is_dir( $testcase))
48 mkdir( $testcase, NULL, true);
49
50 $orgsource = file_get_contents( $sourceuri);
51 file_put_contents ( "$testcase/org_source.txt" , $orgsource);
52
53 $orgresult = file_get_contents( $resulturi);
54 file_put_contents ( "$testcase/org_result.txt" , $orgresult);
55
56 file_put_contents ( "$testcase/parsed_source.txt" , $source);
57 file_put_contents ( "$testcase/parsed_result.txt" , $result);
58 }
59
60 // --------------------------------------------------------
61
62 private function _getSerializedData( $uri) {
63
64 $rdfaData = new \rdfa\Data();
65 $this->assertInstanceOf( '\rdfa\Data', $rdfaData);
66 $rdfaData->parse( $uri);
67 return $rdfaData->_serialize( 'n3');
68
69 } // private function _getSerializedData
70
71 // --------------------------------------------------------
72
73 public function test() {
74
75 // get testcase name again in object context
76 $testcase = trim( getenv( 'TESTCASE'));
77 $this->assertGreaterThan( 0, strlen( $testcase));
78
79 // read source data
80 $sourceuri = self::BASEURI."/$testcase.rdf";
81 $source = $this->_getSerializedData( $sourceuri);
82 $this->assertEquals( ($source !== false), true);
83
84 // read target data
85 $resulturi = self::BASEURI."/$testcase.nt";
86 $result = $this->_getSerializedData( $resulturi);
87 $this->assertEquals( ($result !== false), true);
88
89 // check if results are equal
90 $success = ($source == $result);
91
92 // in case of error, write serialized data to subdirectory
93 if (!$success)
94 $this->_writeErrorData( $testcase,
95 $source, $sourceuri,
96 $result, $resulturi);
97
98 // compare source and target data
99 $this->assertEquals( $success, true);
100
101
102 } // public function test_parse_sparql()
103
104} // class UnitTest
105
106
Note: See TracBrowser for help on using the repository browser.