Limit test leakage, $wgCapitalLinks expected to be true
[mediawiki.git] / tests / phpunit / includes / ImportTest.php
blob889540381a9dafc840de8de496e2c3fcedd36b01
1 <?php
3 /**
4 * Test class for Import methods.
6 * @group Database
8 * @author Sebastian Brückner < sebastian.brueckner@student.hpi.uni-potsdam.de >
9 */
10 class ImportTest extends MediaWikiLangTestCase {
12 private function getInputStreamSource( $xml ) {
13 $file = 'data:application/xml,' . $xml;
14 $status = ImportStreamSource::newFromFile( $file );
15 if ( !$status->isGood() ) {
16 throw new MWException( "Cannot create InputStreamSource." );
18 return $status->value;
21 /**
22 * @covers WikiImporter::handlePage
23 * @dataProvider getRedirectXML
24 * @param string $xml
26 public function testHandlePageContainsRedirect( $xml, $redirectTitle ) {
27 $source = $this->getInputStreamSource( $xml );
29 $redirect = NULL;
30 $callback = function( $title, $origTitle, $revCount, $sRevCount, $pageInfo ) use ( &$redirect ) {
31 if ( array_key_exists( 'redirect', $pageInfo ) ) {
32 $redirect = $pageInfo['redirect'];
36 $importer = new WikiImporter( $source );
37 $importer->setPageOutCallback( $callback );
38 $importer->doImport();
40 $this->assertEquals( $redirectTitle, $redirect );
43 public function getRedirectXML() {
44 return array(
45 array(
46 <<< EOF
47 <mediawiki>
48 <page>
49 <title>Test</title>
50 <ns>0</ns>
51 <id>21</id>
52 <redirect title="Test22"/>
53 <revision>
54 <id>20</id>
55 <timestamp>2014-05-27T10:00:00Z</timestamp>
56 <contributor>
57 <username>Admin</username>
58 <id>10</id>
59 </contributor>
60 <comment>Admin moved page [[Test]] to [[Test22]]</comment>
61 <text xml:space="preserve" bytes="20">#REDIRECT [[Test22]]</text>
62 <sha1>tq456o9x3abm7r9ozi6km8yrbbc56o6</sha1>
63 <model>wikitext</model>
64 <format>text/x-wiki</format>
65 </revision>
66 </page>
67 </mediawiki>
68 EOF
70 'Test22'
72 array(
73 <<< EOF
74 <mediawiki>
75 <page>
76 <title>Test</title>
77 <ns>0</ns>
78 <id>42</id>
79 <revision>
80 <id>421</id>
81 <timestamp>2014-05-27T11:00:00Z</timestamp>
82 <contributor>
83 <username>Admin</username>
84 <id>10</id>
85 </contributor>
86 <text xml:space="preserve" bytes="4">Abcd</text>
87 <sha1>n7uomjq96szt60fy5w3x7ahf7q8m8rh</sha1>
88 <model>wikitext</model>
89 <format>text/x-wiki</format>
90 </revision>
91 </page>
92 </mediawiki>
93 EOF
95 NULL