Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / ExportTest.php
blob202603030b2ac356313a2fd0e8b306817f369eb2
1 <?php
3 /**
4 * Test class for Export methods.
6 * @group Database
8 * @author Isaac Hutt <mhutti1@gmail.com>
9 */
10 class ExportTest extends MediaWikiLangTestCase {
12 protected function setUp() {
13 parent::setUp();
14 $this->setMwGlobals( array(
15 'wgContLang' => Language::factory( 'en' ),
16 'wgLanguageCode' => 'en',
17 'wgCapitalLinks' => true,
18 ) );
21 /**
22 * @covers WikiExporter::pageByTitle
24 public function testPageByTitle() {
25 global $wgContLang;
26 $pageTitle = 'UTPage';
28 $exporter = new WikiExporter(
29 $this->db,
30 WikiExporter::FULL
33 $title = Title::newFromText( $pageTitle );
35 ob_start();
36 $exporter->openStream();
37 $exporter->pageByTitle( $title );
38 $exporter->closeStream();
39 $xmlString = ob_get_clean();
41 // This throws error if invalid xml output
42 $xmlObject = simplexml_load_string( $xmlString );
44 /**
45 * Check namespaces match xml
46 * FIXME: PHP 5.3 support. When we don't support PHP 5.3,
47 * add ->namespace to object and remove from array
49 $xmlNamespaces = (array) $xmlObject->siteinfo->namespaces;
50 $xmlNamespaces = str_replace( ' ', '_', $xmlNamespaces['namespace'] );
51 unset ( $xmlNamespaces[ '@attributes' ] );
52 foreach ( $xmlNamespaces as &$namespaceObject ) {
53 if ( is_object( $namespaceObject ) ) {
54 $namespaceObject = '';
58 $actualNamespaces = (array) $wgContLang->getNamespaces();
59 $actualNamespaces = array_values( $actualNamespaces );
60 $this->assertEquals( $actualNamespaces, $xmlNamespaces );
62 // Check xml page title correct
63 $xmlTitle = (array) $xmlObject->page->title;
64 $this->assertEquals( $pageTitle, $xmlTitle[0] );
66 // Check xml page text is not empty
67 $text = (array) $xmlObject->page->revision->text;
68 $this->assertNotEquals( '', $text[0] );