wiki.techinc.nl/tests/phpunit/includes/ExportTest.php
C. Scott Ananian 7f1ad7d984 Work around change in SimpleXMLElement behavior introduced in PHP 7.3.17
Upstream bug reports of the behavior change introduced in PHP 7.3.17 (and
applied to PHP 7.4 branch as well):
https://bugs.php.net/bug.php?id=79528
https://bugs.php.net/bug.php?id=79485

The reponsible commit in PHP was https://github.com/php/php-src/pull/5246

This was a "bug fix" in the sense that SimpleXML used to discard the
attributes on the namespace elements, which look like this:
     <namespace key="-2" case="first-letter">Media</namespace>
SimpleXML used to return this as a string "Media" instead of a
SimpleXMLElement... but ExportTest (inadvertently?) depended on that
behavior.

In any case, if we iterate over SimpleXMLElement::children() we always
get SimpleXMLElements, not "sometimes strings", and so our code will
correct correctly on PHP below 7.3.17 and above, regardless of how PHP
decides to handle this "bug".

Bug: T250568
Change-Id: I9c2cb6a86fd6e8023c1979ec6838071a87a7bcea
2020-04-30 18:27:15 -04:00

66 lines
1.5 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
/**
* Test class for Export methods.
*
* @group Database
*
* @author Isaac Hutt <mhutti1@gmail.com>
*/
class ExportTest extends MediaWikiLangTestCase {
protected function setUp() : void {
parent::setUp();
$this->setMwGlobals( [
'wgCapitalLinks' => true,
] );
}
/**
* @covers WikiExporter::pageByTitle
*/
public function testPageByTitle() {
$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
*/
foreach ( $xmlObject->siteinfo->namespaces->children() as $namespace ) {
// Get the text content of the SimpleXMLElement
$xmlNamespaces[] = (string)$namespace;
}
$xmlNamespaces = str_replace( ' ', '_', $xmlNamespaces );
$actualNamespaces = (array)MediaWikiServices::getInstance()->getContentLanguage()->
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] );
}
}