MediaWiki
REL1_24
|
00001 <?php 00002 00010 class ImportTest extends MediaWikiLangTestCase { 00011 00012 private function getInputStreamSource( $xml ) { 00013 $file = 'data:application/xml,' . $xml; 00014 $status = ImportStreamSource::newFromFile( $file ); 00015 if ( !$status->isGood() ) { 00016 throw new MWException( "Cannot create InputStreamSource." ); 00017 } 00018 return $status->value; 00019 } 00020 00027 public function testHandlePageContainsRedirect( $xml, $redirectTitle ) { 00028 $source = $this->getInputStreamSource( $xml ); 00029 00030 $redirect = null; 00031 $callback = function ( $title, $origTitle, $revCount, $sRevCount, $pageInfo ) use ( &$redirect ) { 00032 if ( array_key_exists( 'redirect', $pageInfo ) ) { 00033 $redirect = $pageInfo['redirect']; 00034 } 00035 }; 00036 00037 $importer = new WikiImporter( $source ); 00038 $importer->setPageOutCallback( $callback ); 00039 $importer->doImport(); 00040 00041 $this->assertEquals( $redirectTitle, $redirect ); 00042 } 00043 00044 public function getRedirectXML() { 00045 return array( 00046 array( 00047 <<< EOF 00048 <mediawiki> 00049 <page> 00050 <title>Test</title> 00051 <ns>0</ns> 00052 <id>21</id> 00053 <redirect title="Test22"/> 00054 <revision> 00055 <id>20</id> 00056 <timestamp>2014-05-27T10:00:00Z</timestamp> 00057 <contributor> 00058 <username>Admin</username> 00059 <id>10</id> 00060 </contributor> 00061 <comment>Admin moved page [[Test]] to [[Test22]]</comment> 00062 <text xml:space="preserve" bytes="20">#REDIRECT [[Test22]]</text> 00063 <sha1>tq456o9x3abm7r9ozi6km8yrbbc56o6</sha1> 00064 <model>wikitext</model> 00065 <format>text/x-wiki</format> 00066 </revision> 00067 </page> 00068 </mediawiki> 00069 EOF 00070 , 00071 'Test22' 00072 ), 00073 array( 00074 <<< EOF 00075 <mediawiki> 00076 <page> 00077 <title>Test</title> 00078 <ns>0</ns> 00079 <id>42</id> 00080 <revision> 00081 <id>421</id> 00082 <timestamp>2014-05-27T11:00:00Z</timestamp> 00083 <contributor> 00084 <username>Admin</username> 00085 <id>10</id> 00086 </contributor> 00087 <text xml:space="preserve" bytes="4">Abcd</text> 00088 <sha1>n7uomjq96szt60fy5w3x7ahf7q8m8rh</sha1> 00089 <model>wikitext</model> 00090 <format>text/x-wiki</format> 00091 </revision> 00092 </page> 00093 </mediawiki> 00094 EOF 00095 , 00096 null 00097 ), 00098 ); 00099 } 00100 00101 }