Merge "Making missing old files not try to render a thumbnail"
[lhc/web/wiklou.git] / tests / phpunit / includes / ImportTest.php
1 <?php
2
3 /**
4 * Test class for Import methods.
5 *
6 * @group Database
7 *
8 * @author Sebastian Brückner < sebastian.brueckner@student.hpi.uni-potsdam.de >
9 */
10 class ImportTest extends MediaWikiLangTestCase {
11
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." );
17 }
18 return $status->value;
19 }
20
21 /**
22 * @covers WikiImporter::handlePage
23 * @dataProvider getRedirectXML
24 * @param string $xml
25 * @param string|null $redirectTitle
26 */
27 public function testHandlePageContainsRedirect( $xml, $redirectTitle ) {
28 $source = $this->getInputStreamSource( $xml );
29
30 $redirect = null;
31 $callback = function ( $title, $origTitle, $revCount, $sRevCount, $pageInfo ) use ( &$redirect ) {
32 if ( array_key_exists( 'redirect', $pageInfo ) ) {
33 $redirect = $pageInfo['redirect'];
34 }
35 };
36
37 $importer = new WikiImporter( $source );
38 $importer->setPageOutCallback( $callback );
39 $importer->doImport();
40
41 $this->assertEquals( $redirectTitle, $redirect );
42 }
43
44 public function getRedirectXML() {
45 return array(
46 array(
47 <<< EOF
48 <mediawiki>
49 <page>
50 <title>Test</title>
51 <ns>0</ns>
52 <id>21</id>
53 <redirect title="Test22"/>
54 <revision>
55 <id>20</id>
56 <timestamp>2014-05-27T10:00:00Z</timestamp>
57 <contributor>
58 <username>Admin</username>
59 <id>10</id>
60 </contributor>
61 <comment>Admin moved page [[Test]] to [[Test22]]</comment>
62 <text xml:space="preserve" bytes="20">#REDIRECT [[Test22]]</text>
63 <sha1>tq456o9x3abm7r9ozi6km8yrbbc56o6</sha1>
64 <model>wikitext</model>
65 <format>text/x-wiki</format>
66 </revision>
67 </page>
68 </mediawiki>
69 EOF
70 ,
71 'Test22'
72 ),
73 array(
74 <<< EOF
75 <mediawiki>
76 <page>
77 <title>Test</title>
78 <ns>0</ns>
79 <id>42</id>
80 <revision>
81 <id>421</id>
82 <timestamp>2014-05-27T11:00:00Z</timestamp>
83 <contributor>
84 <username>Admin</username>
85 <id>10</id>
86 </contributor>
87 <text xml:space="preserve" bytes="4">Abcd</text>
88 <sha1>n7uomjq96szt60fy5w3x7ahf7q8m8rh</sha1>
89 <model>wikitext</model>
90 <format>text/x-wiki</format>
91 </revision>
92 </page>
93 </mediawiki>
94 EOF
95 ,
96 null
97 ),
98 );
99 }
100
101 }