TableDiffFormatter: Don't repeatedly call array_shift()
[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 'wgContLang' => Language::factory( 'en' ),
16 'wgLanguageCode' => 'en',
17 'wgCapitalLinks' => true,
18 ] );
19 }
20
21 /**
22 * @covers WikiExporter::pageByTitle
23 */
24 public function testPageByTitle() {
25 global $wgContLang;
26 $pageTitle = 'UTPage';
27
28 $exporter = new WikiExporter(
29 $this->db,
30 WikiExporter::FULL
31 );
32
33 $title = Title::newFromText( $pageTitle );
34
35 ob_start();
36 $exporter->openStream();
37 $exporter->pageByTitle( $title );
38 $exporter->closeStream();
39 $xmlString = ob_get_clean();
40
41 // This throws error if invalid xml output
42 $xmlObject = simplexml_load_string( $xmlString );
43
44 /**
45 * Check namespaces match xml
46 */
47 $xmlNamespaces = (array)$xmlObject->siteinfo->namespaces->namespace;
48 $xmlNamespaces = str_replace( ' ', '_', $xmlNamespaces );
49 unset( $xmlNamespaces[ '@attributes' ] );
50 foreach ( $xmlNamespaces as &$namespaceObject ) {
51 if ( is_object( $namespaceObject ) ) {
52 $namespaceObject = '';
53 }
54 }
55
56 $actualNamespaces = (array)$wgContLang->getNamespaces();
57 $actualNamespaces = array_values( $actualNamespaces );
58 $this->assertEquals( $actualNamespaces, $xmlNamespaces );
59
60 // Check xml page title correct
61 $xmlTitle = (array)$xmlObject->page->title;
62 $this->assertEquals( $pageTitle, $xmlTitle[0] );
63
64 // Check xml page text is not empty
65 $text = (array)$xmlObject->page->revision->text;
66 $this->assertNotEquals( '', $text[0] );
67 }
68
69 }