4 * Test class for Import methods.
8 * @author Sebastian Brückner < sebastian.brueckner@student.hpi.uni-potsdam.de >
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
;
22 * @covers WikiImporter::handlePage
23 * @dataProvider getRedirectXML
25 * @param string|null $redirectTitle
27 public function testHandlePageContainsRedirect( $xml, $redirectTitle ) {
28 $source = $this->getInputStreamSource( $xml );
31 $callback = function ( $title, $origTitle, $revCount, $sRevCount, $pageInfo ) use ( &$redirect ) {
32 if ( array_key_exists( 'redirect', $pageInfo ) ) {
33 $redirect = $pageInfo['redirect'];
37 $importer = new WikiImporter( $source, ConfigFactory
::getDefaultInstance()->makeConfig( 'main' ) );
38 $importer->setPageOutCallback( $callback );
39 $importer->doImport();
41 $this->assertEquals( $redirectTitle, $redirect );
44 public function getRedirectXML() {
48 <mediawiki xmlns
="http://www.mediawiki.org/xml/export-0.10/" xmlns
:xsi
="http://www.w3.org/2001/XMLSchema-instance" xsi
:schemaLocation
="http://www.mediawiki.org/xml/export-0.10/ http://www.mediawiki.org/xml/export-0.10.xsd" version
="0.10" xml
:lang
="en">
53 <redirect title
="Test22"/>
56 <timestamp
>2014-05-27T10
:00:00Z
</timestamp
>
58 <username
>Admin
</username
>
61 <comment
>Admin moved page
[[Test
]] to
[[Test22
]]</comment
>
62 <model
>wikitext
</model
>
63 <format
>text
/x
-wiki
</format
>
64 <text xml
:space
="preserve" bytes
="20">#REDIRECT [[Test22]]</text>
65 <sha1
>tq456o9x3abm7r9ozi6km8yrbbc56o6
</sha1
>
75 <mediawiki xmlns
="http://www.mediawiki.org/xml/export-0.9/" xmlns
:xsi
="http://www.w3.org/2001/XMLSchema-instance" xsi
:schemaLocation
="http://www.mediawiki.org/xml/export-0.9/ http://www.mediawiki.org/xml/export-0.9.xsd" version
="0.9" xml
:lang
="en">
82 <timestamp
>2014-05-27T11
:00:00Z
</timestamp
>
84 <username
>Admin
</username
>
87 <text xml
:space
="preserve" bytes
="4">Abcd
</text
>
88 <sha1
>n7uomjq96szt60fy5w3x7ahf7q8m8rh
</sha1
>
89 <model
>wikitext
</model
>
90 <format
>text
/x
-wiki
</format
>