(bug 37249) validate export-demo.xml against current export.xsd
authorumherirrender <umherirrender_de.wp@web.de>
Sat, 30 Jun 2012 08:06:35 +0000 (10:06 +0200)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 13 Jul 2012 19:34:38 +0000 (19:34 +0000)
Change-Id: I9031a1b3338fe69b8860caf9cac59a66e0e09fc1

includes/Export.php
tests/phpunit/docs/ExportDemoTest.php [new file with mode: 0644]

index 2bef114..f01fb23 100644 (file)
@@ -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 (file)
index 0000000..ce65d49
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Test for the demo xml
+ *
+ * @group Dump
+ */
+class ExportDemoTest extends DumpTestCase {
+
+       /**
+        * @group large
+        */
+       function testExportDemo() {
+               $this->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() );
+               }
+       }
+}