Added a simple smoke test for export
authormhutti1 <mhutti1@gmail.com>
Fri, 25 Dec 2015 20:14:02 +0000 (21:14 +0100)
committerReedy <reedy@wikimedia.org>
Sun, 27 Dec 2015 22:22:06 +0000 (22:22 +0000)
Added ExportTest.php to check that exported xml is valid.

Bug: T116883
Change-Id: I76151a6ab4f88ab1904627ad1d00ed487d0ab606

tests/phpunit/includes/ExportTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/includes/ExportTest.php b/tests/phpunit/includes/ExportTest.php
new file mode 100644 (file)
index 0000000..2026030
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * Test class for Export methods.
+ *
+ * @group Database
+ *
+ * @author Isaac Hutt <mhutti1@gmail.com>
+ */
+class ExportTest extends MediaWikiLangTestCase {
+
+       protected function setUp() {
+               parent::setUp();
+               $this->setMwGlobals( array(
+                       'wgContLang' => Language::factory( 'en' ),
+                       'wgLanguageCode' => 'en',
+                       'wgCapitalLinks' => true,
+               ) );
+       }
+
+       /**
+        * @covers WikiExporter::pageByTitle
+        */
+       public function testPageByTitle() {
+               global $wgContLang;
+               $pageTitle = 'UTPage';
+
+               $exporter = new WikiExporter(
+                       $this->db,
+                       WikiExporter::FULL
+               );
+
+               $title = Title::newFromText( $pageTitle );
+
+               ob_start();
+               $exporter->openStream();
+               $exporter->pageByTitle( $title );
+               $exporter->closeStream();
+               $xmlString = ob_get_clean();
+
+               // This throws error if invalid xml output
+               $xmlObject = simplexml_load_string( $xmlString );
+
+               /**
+                * Check namespaces match xml
+                * FIXME: PHP 5.3 support. When we don't support PHP 5.3,
+                * add ->namespace to object and remove from array
+                */
+               $xmlNamespaces = (array) $xmlObject->siteinfo->namespaces;
+               $xmlNamespaces = str_replace( ' ', '_', $xmlNamespaces['namespace'] );
+               unset ( $xmlNamespaces[ '@attributes' ] );
+               foreach ( $xmlNamespaces as &$namespaceObject ) {
+                       if ( is_object( $namespaceObject ) ) {
+                               $namespaceObject = '';
+                       }
+               }
+
+               $actualNamespaces = (array) $wgContLang->getNamespaces();
+               $actualNamespaces = array_values( $actualNamespaces );
+               $this->assertEquals( $actualNamespaces, $xmlNamespaces );
+
+               // Check xml page title correct
+               $xmlTitle = (array) $xmlObject->page->title;
+               $this->assertEquals( $pageTitle, $xmlTitle[0] );
+
+               // Check xml page text is not empty
+               $text = (array) $xmlObject->page->revision->text;
+               $this->assertNotEquals( '', $text[0] );
+       }
+
+}