wiki.techinc.nl/tests/phpunit/includes/ExportTest.php
Kevin Israel be46ffa771 DumpStringOutput: Rename getOutput() to __toString()
Though getOutput() is what first came to mind, I do not particularly
like the name, partly because it is used in many, many places as a
method that returns an OutputPage object.

* Renamed the method to __toString(). This is appropriate because
  each instance, at any given time, corresponds to a single string
  value (and exceptions cannot occur during this conversion).
* Removed unnecessary variables from ApiQuery and ExportTest. In
  these and most other cases, it should no longer be necessary to
  call getOutput() explicitly.

Change-Id: Icf202743d1f332f8981338f42eb6e3e5a04abdf1
2016-07-14 06:28:16 -04:00

67 lines
1.5 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();
// This throws error if invalid xml output
$xmlObject = simplexml_load_string( $sink );
/**
* 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] );
}
}