From: umherirrender Date: Sat, 30 Jun 2012 08:06:35 +0000 (+0200) Subject: (bug 37249) validate export-demo.xml against current export.xsd X-Git-Tag: 1.31.0-rc.0~23017^2 X-Git-Url: http://git.cyclocoop.org/%22.%24h.%22?a=commitdiff_plain;h=4f7f226299fdec29a4613820cbae30a6a56e117c;p=lhc%2Fweb%2Fwiklou.git (bug 37249) validate export-demo.xml against current export.xsd Change-Id: I9031a1b3338fe69b8860caf9cac59a66e0e09fc1 --- diff --git a/includes/Export.php b/includes/Export.php index 2bef114ed1..f01fb23732 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -58,6 +58,14 @@ class WikiExporter { */ var $sink; + /** + * Returns the export schema version. + * @return string + */ + public static function schemaVersion() { + return "0.7"; + } + /** * If using WikiExporter::STREAM to stream a large amount of data, * provide a database connection which is not managed by @@ -465,10 +473,12 @@ class WikiExporter { class XmlDumpWriter { /** * Returns the export schema version. + * @deprecated in 1.20; use WikiExporter::schemaVersion() instead * @return string */ function schemaVersion() { - return "0.7"; + wfDeprecated( __METHOD__, '1.20' ); + return WikiExporter::schemaVersion(); } /** @@ -483,7 +493,7 @@ class XmlDumpWriter { */ function openStream() { global $wgLanguageCode; - $ver = $this->schemaVersion(); + $ver = WikiExporter::schemaVersion(); return Xml::element( 'mediawiki', array( 'xmlns' => "http://www.mediawiki.org/xml/export-$ver/", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", diff --git a/tests/phpunit/docs/ExportDemoTest.php b/tests/phpunit/docs/ExportDemoTest.php new file mode 100644 index 0000000000..ce65d494b5 --- /dev/null +++ b/tests/phpunit/docs/ExportDemoTest.php @@ -0,0 +1,36 @@ +validateXmlFileAgainstXsd( "../../docs/export-demo.xml" ); + } + + /** + * Validates a xml file against the xsd. + * + * The validation is slow, because php has to read the xsd on each call. + * + * @param $fname string: name of file to validate + */ + protected function validateXmlFileAgainstXsd( $fname ) { + $version = WikiExporter::schemaVersion(); + + $dom = new DomDocument(); + $dom->load( $fname ); + + try { + $this->assertTrue( $dom->schemaValidate( "../../docs/export-" . $version . ".xsd" ), + "schemaValidate has found an error" ); + } catch( Exception $e ) { + $this->fail( "xml not valid against xsd: " . $e->getMessage() ); + } + } +}