wiki.techinc.nl/tests/phpunit/includes/ExportTest.php
Reedy 64ea1577e3 Explicitly wrap some XML calls in libxml_disable_entity_loader()
As per https://www.php.net/manual/en/function.libxml-disable-entity-loader.php
this is technically unnecessary.

>However, as of libxml 2.9.0 entity substitution is disabled by default,
>so there is no need to disable the loading of external entities.

See also https://github.com/php/php-src/pull/5867

>Since the release of libxml 2.9.0 in 2012 external entity loading is
>disabled in libxml by default. This means that using
>libxml_disable_entity_loader() is no longer needed.

Hopefully helps prevent false positive reports from security scanning tools.

Change-Id: I8a09d62a9920fd0bf4a388baa5544a02323bb541
2020-09-20 15:57:14 +00:00

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