4 * Test class for Export methods.
8 * @author Isaac Hutt <mhutti1@gmail.com>
10 class ExportTest
extends MediaWikiLangTestCase
{
12 protected function setUp() {
14 $this->setMwGlobals( [
15 'wgContLang' => Language
::factory( 'en' ),
16 'wgLanguageCode' => 'en',
17 'wgCapitalLinks' => true,
22 * @covers WikiExporter::pageByTitle
24 public function testPageByTitle() {
26 $pageTitle = 'UTPage';
28 $exporter = new WikiExporter(
33 $title = Title
::newFromText( $pageTitle );
36 $exporter->openStream();
37 $exporter->pageByTitle( $title );
38 $exporter->closeStream();
39 $xmlString = ob_get_clean();
41 // This throws error if invalid xml output
42 $xmlObject = simplexml_load_string( $xmlString );
45 * Check namespaces match xml
47 $xmlNamespaces = (array)$xmlObject->siteinfo
->namespaces
->namespace;
48 $xmlNamespaces = str_replace( ' ', '_', $xmlNamespaces );
49 unset( $xmlNamespaces[ '@attributes' ] );
50 foreach ( $xmlNamespaces as &$namespaceObject ) {
51 if ( is_object( $namespaceObject ) ) {
52 $namespaceObject = '';
56 $actualNamespaces = (array)$wgContLang->getNamespaces();
57 $actualNamespaces = array_values( $actualNamespaces );
58 $this->assertEquals( $actualNamespaces, $xmlNamespaces );
60 // Check xml page title correct
61 $xmlTitle = (array)$xmlObject->page
->title
;
62 $this->assertEquals( $pageTitle, $xmlTitle[0] );
64 // Check xml page text is not empty
65 $text = (array)$xmlObject->page
->revision
->text
;
66 $this->assertNotEquals( '', $text[0] );