Work around change in SimpleXMLElement behavior introduced in PHP 7.3.17
[lhc/web/wiklou.git] / tests / phpunit / includes / ExportTest.php
1 <?php
2
3 /**
4 * Test class for Export methods.
5 *
6 * @group Database
7 *
8 * @author Isaac Hutt <mhutti1@gmail.com>
9 */
10 class ExportTest extends MediaWikiLangTestCase {
11
12 protected function setUp() {
13 parent::setUp();
14 $this->setMwGlobals( [
15 'wgCapitalLinks' => true,
16 ] );
17 }
18
19 /**
20 * @covers WikiExporter::pageByTitle
21 */
22 public function testPageByTitle() {
23 global $wgContLang;
24 $pageTitle = 'UTPage';
25
26 $exporter = new WikiExporter(
27 $this->db,
28 WikiExporter::FULL
29 );
30
31 $title = Title::newFromText( $pageTitle );
32
33 $sink = new DumpStringOutput;
34 $exporter->setOutputSink( $sink );
35 $exporter->openStream();
36 $exporter->pageByTitle( $title );
37 $exporter->closeStream();
38
39 // This throws error if invalid xml output
40 $xmlObject = simplexml_load_string( $sink );
41
42 /**
43 * Check namespaces match xml
44 */
45 foreach ( $xmlObject->siteinfo->namespaces->children() as $namespace ) {
46 // Get the text content of the SimpleXMLElement
47 $xmlNamespaces[] = (string)$namespace;
48 }
49 $xmlNamespaces = str_replace( ' ', '_', $xmlNamespaces );
50
51 $actualNamespaces = (array)$wgContLang->getNamespaces();
52 $actualNamespaces = array_values( $actualNamespaces );
53 $this->assertEquals( $actualNamespaces, $xmlNamespaces );
54
55 // Check xml page title correct
56 $xmlTitle = (array)$xmlObject->page->title;
57 $this->assertEquals( $pageTitle, $xmlTitle[0] );
58
59 // Check xml page text is not empty
60 $text = (array)$xmlObject->page->revision->text;
61 $this->assertNotEquals( '', $text[0] );
62 }
63
64 }