| 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 | define( 'FDEBUG_SESSION_NAME', 'RDF Test Cases Unittest');
|
|---|
| 23 | require_once( RDFINT.'/rdfa.php');
|
|---|
| 24 | require_once( 'rdftestcases.php');
|
|---|
| 25 |
|
|---|
| 26 | class UnitTest extends PHPUnit_Framework_TestCase {
|
|---|
| 27 |
|
|---|
| 28 | static protected $manifest;
|
|---|
| 29 |
|
|---|
| 30 | // --------------------------------------------------------
|
|---|
| 31 |
|
|---|
| 32 | // rune once initializer
|
|---|
| 33 | public static function setUpBeforeClass() {
|
|---|
| 34 | self::$manifest = new RDFTestCasesManifest;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | // --------------------------------------------------------
|
|---|
| 38 |
|
|---|
| 39 | // helper: adjusts serialization results so that comparison can work
|
|---|
| 40 | // - make all blank node identifiers unique
|
|---|
| 41 | // - sort the n-triple lines
|
|---|
| 42 | private function _refineResult( $data) {
|
|---|
| 43 | // replace all blank nodes by one ID
|
|---|
| 44 | // NOTE: thi sis not accurate, but not much better
|
|---|
| 45 | // possible without access to the triple data
|
|---|
| 46 | $data = preg_replace( '/_:[^ ]*/', '_:a', $data);
|
|---|
| 47 |
|
|---|
| 48 | // sort the data
|
|---|
| 49 | $adata = explode( "\n", $data);
|
|---|
| 50 | sort( &$adata);
|
|---|
| 51 | $data = implode( "\n", $adata);
|
|---|
| 52 |
|
|---|
| 53 | return $data;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | // --------------------------------------------------------
|
|---|
| 57 | // helper: write input and output data to new output
|
|---|
| 58 | // directory for manual examination
|
|---|
| 59 | private function _writeErrorData( $testcase,
|
|---|
| 60 | $source, $sourceuri,
|
|---|
| 61 | $result, $resulturi) {
|
|---|
| 62 | if (!is_dir( $testcase))
|
|---|
| 63 | mkdir( $testcase, NULL, true);
|
|---|
| 64 |
|
|---|
| 65 | $orgsource = file_get_contents( $sourceuri);
|
|---|
| 66 | file_put_contents ( "$testcase/org_source.txt" , $orgsource);
|
|---|
| 67 |
|
|---|
| 68 | $orgresult = file_get_contents( $resulturi);
|
|---|
| 69 | file_put_contents ( "$testcase/org_result.txt" , $orgresult);
|
|---|
| 70 |
|
|---|
| 71 | file_put_contents ( "$testcase/parsed_source.txt" , $source);
|
|---|
| 72 | file_put_contents ( "$testcase/parsed_result.txt" , $result);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | // --------------------------------------------------------
|
|---|
| 76 |
|
|---|
| 77 | // helper: serialize data from URI to N3
|
|---|
| 78 | private function _getSerializedData( $uri) {
|
|---|
| 79 |
|
|---|
| 80 | $rdfaData = new \rdfa\Data();
|
|---|
| 81 | $this->assertInstanceOf( '\rdfa\Data', $rdfaData);
|
|---|
| 82 | $rdfaData->parse( $uri);
|
|---|
| 83 | return $rdfaData->_serialize( 'n3');
|
|---|
| 84 |
|
|---|
| 85 | } // private function _getSerializedData
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | // --------------------------------------------------------
|
|---|
| 89 |
|
|---|
| 90 | public function test() {
|
|---|
| 91 |
|
|---|
| 92 | $type = trim( getenv( 'CATEGORY'));
|
|---|
| 93 | if ($type == '')
|
|---|
| 94 | $types = self::$manifest->getCategories();
|
|---|
| 95 | else
|
|---|
| 96 | $types = array( $type);
|
|---|
| 97 |
|
|---|
| 98 | foreach ($types as $type) {
|
|---|
| 99 | echo "\nExecuting RDF Test Cases of category: $type\n\n";
|
|---|
| 100 |
|
|---|
| 101 | $testcases = self::$manifest->getParserTests( $type);
|
|---|
| 102 |
|
|---|
| 103 | foreach ($testcases as $testcase) {
|
|---|
| 104 | echo " Executing: " . $testcase->name . "\n";
|
|---|
| 105 | $this->assertEquals( 0, 0);
|
|---|
| 106 | }
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | } // public function test
|
|---|
| 110 |
|
|---|
| 111 | // --------------------------------------------------------
|
|---|
| 112 |
|
|---|
| 113 | public function disabled_test() {
|
|---|
| 114 |
|
|---|
| 115 | // get testcase name again in object context
|
|---|
| 116 | $testcase = trim( getenv( 'TESTCASE'));
|
|---|
| 117 | $this->assertGreaterThan( 0, strlen( $testcase));
|
|---|
| 118 |
|
|---|
| 119 | // read source data
|
|---|
| 120 | $sourceuri = self::BASEURI."/$testcase.rdf";
|
|---|
| 121 | $source = $this->_getSerializedData( $sourceuri);
|
|---|
| 122 | $this->assertEquals( ($source !== false), true);
|
|---|
| 123 |
|
|---|
| 124 | // read target data
|
|---|
| 125 | $resulturi = self::BASEURI."/$testcase.nt";
|
|---|
| 126 | $result = $this->_getSerializedData( $resulturi);
|
|---|
| 127 | $this->assertEquals( ($result !== false), true);
|
|---|
| 128 |
|
|---|
| 129 | // resolve problems with blnak node identifiers
|
|---|
| 130 | // and different sorting of triples
|
|---|
| 131 | $source = $this->_refineResult( $source);
|
|---|
| 132 | $result = $this->_refineResult( $result);
|
|---|
| 133 |
|
|---|
| 134 | // check if results are equal
|
|---|
| 135 | $success = ($source == $result);
|
|---|
| 136 |
|
|---|
| 137 | // in case of error, write serialized data to subdirectory
|
|---|
| 138 | if (!$success)
|
|---|
| 139 | $this->_writeErrorData( $testcase,
|
|---|
| 140 | $source, $sourceuri,
|
|---|
| 141 | $result, $resulturi);
|
|---|
| 142 |
|
|---|
| 143 | // compare source and target data
|
|---|
| 144 | $this->assertEquals( $success, true);
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 | } // public function test_parse_sparql()
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 | // --------------------------------------------------------
|
|---|
| 151 |
|
|---|
| 152 | public function _dumpTestcaseInfo( $testcases) {
|
|---|
| 153 | foreach ($testcases as $testcase) {
|
|---|
| 154 | echo "=====================================================================\n";
|
|---|
| 155 | echo 'URI: ' . $testcase->getSubject() . "\n";
|
|---|
| 156 | echo 'Input: ' . $testcase->input . "\n";
|
|---|
| 157 | echo 'Output: ' . $testcase->output . "\n";
|
|---|
| 158 | echo 'Concluision: ' . $testcase->conclusion . "\n";
|
|---|
| 159 | }
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 | } // class UnitTest
|
|---|
| 164 |
|
|---|
| 165 |
|
|---|