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 if ( ini_get( 'allow_url_fopen' ) != 1 ) {
14 $this->markTestSkipped( 'bug 73283: this test needs allow_url_fopen to be enabled' );
16 $file = 'data:application/xml,' . $xml;
17 $status = ImportStreamSource
::newFromFile( $file );
18 if ( !$status->isGood() ) {
19 throw new MWException( "Cannot create InputStreamSource." );
21 return $status->value
;
25 * @covers WikiImporter::handlePage
26 * @dataProvider getRedirectXML
28 * @param string|null $redirectTitle
30 public function testHandlePageContainsRedirect( $xml, $redirectTitle ) {
31 $source = $this->getInputStreamSource( $xml );
34 $callback = function ( Title
$title, ForeignTitle
$foreignTitle, $revCount,
35 $sRevCount, $pageInfo ) use ( &$redirect ) {
36 if ( array_key_exists( 'redirect', $pageInfo ) ) {
37 $redirect = $pageInfo['redirect'];
41 $importer = new WikiImporter( $source, ConfigFactory
::getDefaultInstance()->makeConfig( 'main' ) );
42 $importer->setPageOutCallback( $callback );
43 $importer->doImport();
45 $this->assertEquals( $redirectTitle, $redirect );
48 public function getRedirectXML() {
52 <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">
57 <redirect title
="Test22"/>
60 <timestamp
>2014-05-27T10
:00:00Z
</timestamp
>
62 <username
>Admin
</username
>
65 <comment
>Admin moved page
[[Test
]] to
[[Test22
]]</comment
>
66 <model
>wikitext
</model
>
67 <format
>text
/x
-wiki
</format
>
68 <text xml
:space
="preserve" bytes
="20">#REDIRECT [[Test22]]</text>
69 <sha1
>tq456o9x3abm7r9ozi6km8yrbbc56o6
</sha1
>
79 <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">
86 <timestamp
>2014-05-27T11
:00:00Z
</timestamp
>
88 <username
>Admin
</username
>
91 <text xml
:space
="preserve" bytes
="4">Abcd
</text
>
92 <sha1
>n7uomjq96szt60fy5w3x7ahf7q8m8rh
</sha1
>
93 <model
>wikitext
</model
>
94 <format
>text
/x
-wiki
</format
>
106 * @covers WikiImporter::handleSiteInfo
107 * @dataProvider getSiteInfoXML
109 * @param array|null $namespaces
111 public function testSiteInfoContainsNamespaces( $xml, $namespaces ) {
112 $source = $this->getInputStreamSource( $xml );
114 $importNamespaces = null;
115 $callback = function ( array $siteinfo, $innerImporter ) use ( &$importNamespaces ) {
116 $importNamespaces = $siteinfo['_namespaces'];
119 $importer = new WikiImporter( $source, ConfigFactory
::getDefaultInstance()->makeConfig( 'main' ) );
120 $importer->setSiteInfoCallback( $callback );
121 $importer->doImport();
123 $this->assertEquals( $importNamespaces, $namespaces );
126 public function getSiteInfoXML() {
130 <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">
133 <namespace key
="-2" case="first-letter">Media
</namespace>
134 <namespace key
="-1" case="first-letter">Special
</namespace>
135 <namespace key
="0" case="first-letter" />
136 <namespace key
="1" case="first-letter">Talk
</namespace>
137 <namespace key
="2" case="first-letter">User
</namespace>
138 <namespace key
="3" case="first-letter">User talk
</namespace>
139 <namespace key
="100" case="first-letter">Portal
</namespace>
140 <namespace key
="101" case="first-letter">Portal talk
</namespace>
154 '101' => 'Portal talk',