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
26 public function testHandlePageContainsRedirect( $xml, $redirectTitle ) {
27 $source = $this->getInputStreamSource( $xml );
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() {
52 <redirect title
="Test22"/>
55 <timestamp
>2014-05-27T10
:00:00Z
</timestamp
>
57 <username
>Admin
</username
>
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
>
81 <timestamp
>2014-05-27T11
:00:00Z
</timestamp
>
83 <username
>Admin
</username
>
86 <text xml
:space
="preserve" bytes
="4">Abcd
</text
>
87 <sha1
>n7uomjq96szt60fy5w3x7ahf7q8m8rh
</sha1
>
88 <model
>wikitext
</model
>
89 <format
>text
/x
-wiki
</format
>