blob: da0b82e040c50d18348b5b77ed3ae30b9ea4b62a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
<?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
*/
$xmlNamespaces = (array)$xmlObject->siteinfo->namespaces->namespace;
$xmlNamespaces = str_replace( ' ', '_', $xmlNamespaces );
unset( $xmlNamespaces[ '@attributes' ] );
foreach ( $xmlNamespaces as &$namespaceObject ) {
if ( is_object( $namespaceObject ) ) {
$namespaceObject = '';
}
}
$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] );
}
}
|