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
$title, ForeignTitle
$foreignTitle, $revCount,
32 $sRevCount, $pageInfo ) use ( &$redirect ) {
33 if ( array_key_exists( 'redirect', $pageInfo ) ) {
34 $redirect = $pageInfo['redirect'];
38 $importer = new WikiImporter( $source, ConfigFactory
::getDefaultInstance()->makeConfig( 'main' ) );
39 $importer->setPageOutCallback( $callback );
40 $importer->doImport();
42 $this->assertEquals( $redirectTitle, $redirect );
45 public function getRedirectXML() {
49 <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">
54 <redirect title
="Test22"/>
57 <timestamp
>2014-05-27T10
:00:00Z
</timestamp
>
59 <username
>Admin
</username
>
62 <comment
>Admin moved page
[[Test
]] to
[[Test22
]]</comment
>
63 <model
>wikitext
</model
>
64 <format
>text
/x
-wiki
</format
>
65 <text xml
:space
="preserve" bytes
="20">#REDIRECT [[Test22]]</text>
66 <sha1
>tq456o9x3abm7r9ozi6km8yrbbc56o6
</sha1
>
76 <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">
83 <timestamp
>2014-05-27T11
:00:00Z
</timestamp
>
85 <username
>Admin
</username
>
88 <text xml
:space
="preserve" bytes
="4">Abcd
</text
>
89 <sha1
>n7uomjq96szt60fy5w3x7ahf7q8m8rh
</sha1
>
90 <model
>wikitext
</model
>
91 <format
>text
/x
-wiki
</format
>
103 * @covers WikiImporter::handleSiteInfo
104 * @dataProvider getSiteInfoXML
106 * @param array|null $namespaces
108 public function testSiteInfoContainsNamespaces( $xml, $namespaces ) {
109 $source = $this->getInputStreamSource( $xml );
111 $importNamespaces = null;
112 $callback = function ( array $siteinfo, $innerImporter ) use ( &$importNamespaces ) {
113 $importNamespaces = $siteinfo['_namespaces'];
116 $importer = new WikiImporter( $source, ConfigFactory
::getDefaultInstance()->makeConfig( 'main' ) );
117 $importer->setSiteInfoCallback( $callback );
118 $importer->doImport();
120 $this->assertEquals( $importNamespaces, $namespaces );
123 public function getSiteInfoXML() {
127 <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">
130 <namespace key
="-2" case="first-letter">Media
</namespace>
131 <namespace key
="-1" case="first-letter">Special
</namespace>
132 <namespace key
="0" case="first-letter" />
133 <namespace key
="1" case="first-letter">Talk
</namespace>
134 <namespace key
="2" case="first-letter">User
</namespace>
135 <namespace key
="3" case="first-letter">User talk
</namespace>
136 <namespace key
="100" case="first-letter">Portal
</namespace>
137 <namespace key
="101" case="first-letter">Portal talk
</namespace>
151 '101' => 'Portal talk',