wiki.techinc.nl/tests/phpunit/includes/ExportTest.php
Kevin Israel 81d5d8adc2 ApiQuery: Don't mess with PHP output buffering
Specifically, it is not necessary to use output buffering functions
to capture XML generated by the export code because it is already
possible to set the "output sink" object to be used.

* Created a DumpStringOutput class, which appends all output to a
  string property rather than printing output immediately.
* Used that class, instead of ob_start() and ob_get_clean(), in
  ApiQuery and ExportTest.

Change-Id: I238f5d5ec7fd442c845b25cb59ef81ac3285099f
2016-07-08 18:30:55 -04:00

68 lines
1.6 KiB
PHP

<?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( [
'wgCapitalLinks' => true,
] );
}
/**
* @covers WikiExporter::pageByTitle
*/
public function testPageByTitle() {
global $wgContLang;
$pageTitle = 'UTPage';
$exporter = new WikiExporter(
$this->db,
WikiExporter::FULL
);
$title = Title::newFromText( $pageTitle );
$sink = new DumpStringOutput;
$exporter->setOutputSink( $sink );
$exporter->openStream();
$exporter->pageByTitle( $title );
$exporter->closeStream();
$xmlString = $sink->getOutput();
// This throws error if invalid xml output
$xmlObject = simplexml_load_string( $xmlString );
/**
* Check namespaces match xml
*/
$xmlNamespaces = (array)$xmlObject->siteinfo->namespaces->namespace;
$xmlNamespaces = str_replace( ' ', '_', $xmlNamespaces );
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] );
}
}