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 getDataSource( $xml ) {
13 return new ImportStringSource( $xml );
17 * @covers WikiImporter::handlePage
18 * @dataProvider getRedirectXML
20 * @param string|null $redirectTitle
22 public function testHandlePageContainsRedirect( $xml, $redirectTitle ) {
23 $source = $this->getDataSource( $xml );
26 $callback = function ( Title
$title, ForeignTitle
$foreignTitle, $revCount,
27 $sRevCount, $pageInfo ) use ( &$redirect ) {
28 if ( array_key_exists( 'redirect', $pageInfo ) ) {
29 $redirect = $pageInfo['redirect'];
33 $importer = new WikiImporter(
35 ConfigFactory
::getDefaultInstance()->makeConfig( 'main' )
37 $importer->setPageOutCallback( $callback );
38 $importer->doImport();
40 $this->assertEquals( $redirectTitle, $redirect );
43 public function getRedirectXML() {
44 // @codingStandardsIgnoreStart Generic.Files.LineLength
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
>
99 // @codingStandardsIgnoreEnd
103 * @covers WikiImporter::handleSiteInfo
104 * @dataProvider getSiteInfoXML
106 * @param array|null $namespaces
108 public function testSiteInfoContainsNamespaces( $xml, $namespaces ) {
109 $source = $this->getDataSource( $xml );
111 $importNamespaces = null;
112 $callback = function ( array $siteinfo, $innerImporter ) use ( &$importNamespaces ) {
113 $importNamespaces = $siteinfo['_namespaces'];
116 $importer = new WikiImporter(
118 ConfigFactory
::getDefaultInstance()->makeConfig( 'main' )
120 $importer->setSiteInfoCallback( $callback );
121 $importer->doImport();
123 $this->assertEquals( $importNamespaces, $namespaces );
126 public function getSiteInfoXML() {
127 // @codingStandardsIgnoreStart Generic.Files.LineLength
131 <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">
134 <namespace key
="-2" case="first-letter">Media
</namespace>
135 <namespace key
="-1" case="first-letter">Special
</namespace>
136 <namespace key
="0" case="first-letter" />
137 <namespace key
="1" case="first-letter">Talk
</namespace>
138 <namespace key
="2" case="first-letter">User
</namespace>
139 <namespace key
="3" case="first-letter">User talk
</namespace>
140 <namespace key
="100" case="first-letter">Portal
</namespace>
141 <namespace key
="101" case="first-letter">Portal talk
</namespace>
155 '101' => 'Portal talk',
159 // @codingStandardsIgnoreEnd