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
18 * @dataProvider getUnknownTagsXML
21 * @param string $title
23 public function testUnknownXMLTags( $xml, $text, $title ) {
24 $source = $this->getDataSource( $xml );
26 $importer = new WikiImporter(
28 ConfigFactory
::getDefaultInstance()->makeConfig( 'main' )
31 $importer->doImport();
32 $title = Title
::newFromText( $title );
33 $this->assertTrue( $title->exists() );
35 $this->assertEquals( WikiPage
::factory( $title )->getContent()->getNativeData(), $text );
38 public function getUnknownTagsXML() {
39 // @codingStandardsIgnoreStart Generic.Files.LineLength
43 <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">
44 <page unknown
="123" dontknow
="533">
45 <title
>TestImportPage
</title
>
46 <unknowntag
>Should be ignored
</unknowntag
>
48 <id unknown
="123" dontknow
="533">14</id
>
50 <id unknown
="123" dontknow
="533">15</id
>
51 <unknowntag
>Should be ignored
</unknowntag
>
52 <timestamp
>2016-01-03T11
:18:43Z
</timestamp
>
54 <unknowntag
>Should be ignored
</unknowntag
>
55 <username unknown
="123" dontknow
="533">Admin
</username
>
58 <model
>wikitext
</model
>
59 <format
>text
/x
-wiki
</format
>
60 <text xml
:space
="preserve" bytes
="0">noitazinagro tseb eht si ikiWaideM
</text
>
61 <sha1
>phoiac9h4m842xq45sp7s6u21eteeq1
</sha1
>
62 <unknowntag
>Should be ignored
</unknowntag
>
65 <unknowntag
>Should be ignored
</unknowntag
>
69 'noitazinagro tseb eht si ikiWaideM',
73 // @codingStandardsIgnoreEnd
77 * @covers WikiImporter::handlePage
78 * @dataProvider getRedirectXML
80 * @param string|null $redirectTitle
82 public function testHandlePageContainsRedirect( $xml, $redirectTitle ) {
83 $source = $this->getDataSource( $xml );
86 $callback = function ( Title
$title, ForeignTitle
$foreignTitle, $revCount,
87 $sRevCount, $pageInfo ) use ( &$redirect ) {
88 if ( array_key_exists( 'redirect', $pageInfo ) ) {
89 $redirect = $pageInfo['redirect'];
93 $importer = new WikiImporter(
95 ConfigFactory
::getDefaultInstance()->makeConfig( 'main' )
97 $importer->setPageOutCallback( $callback );
98 $importer->doImport();
100 $this->assertEquals( $redirectTitle, $redirect );
103 public function getRedirectXML() {
104 // @codingStandardsIgnoreStart Generic.Files.LineLength
108 <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">
113 <redirect title
="Test22"/>
116 <timestamp
>2014-05-27T10
:00:00Z
</timestamp
>
118 <username
>Admin
</username
>
121 <comment
>Admin moved page
[[Test
]] to
[[Test22
]]</comment
>
122 <model
>wikitext
</model
>
123 <format
>text
/x
-wiki
</format
>
124 <text xml
:space
="preserve" bytes
="20">#REDIRECT [[Test22]]</text>
125 <sha1
>tq456o9x3abm7r9ozi6km8yrbbc56o6
</sha1
>
135 <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">
142 <timestamp
>2014-05-27T11
:00:00Z
</timestamp
>
144 <username
>Admin
</username
>
147 <text xml
:space
="preserve" bytes
="4">Abcd
</text
>
148 <sha1
>n7uomjq96szt60fy5w3x7ahf7q8m8rh
</sha1
>
149 <model
>wikitext
</model
>
150 <format
>text
/x
-wiki
</format
>
159 // @codingStandardsIgnoreEnd
163 * @covers WikiImporter::handleSiteInfo
164 * @dataProvider getSiteInfoXML
166 * @param array|null $namespaces
168 public function testSiteInfoContainsNamespaces( $xml, $namespaces ) {
169 $source = $this->getDataSource( $xml );
171 $importNamespaces = null;
172 $callback = function ( array $siteinfo, $innerImporter ) use ( &$importNamespaces ) {
173 $importNamespaces = $siteinfo['_namespaces'];
176 $importer = new WikiImporter(
178 ConfigFactory
::getDefaultInstance()->makeConfig( 'main' )
180 $importer->setSiteInfoCallback( $callback );
181 $importer->doImport();
183 $this->assertEquals( $importNamespaces, $namespaces );
186 public function getSiteInfoXML() {
187 // @codingStandardsIgnoreStart Generic.Files.LineLength
191 <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">
194 <namespace key
="-2" case="first-letter">Media
</namespace>
195 <namespace key
="-1" case="first-letter">Special
</namespace>
196 <namespace key
="0" case="first-letter" />
197 <namespace key
="1" case="first-letter">Talk
</namespace>
198 <namespace key
="2" case="first-letter">User
</namespace>
199 <namespace key
="3" case="first-letter">User talk
</namespace>
200 <namespace key
="100" case="first-letter">Portal
</namespace>
201 <namespace key
="101" case="first-letter">Portal talk
</namespace>
215 '101' => 'Portal talk',
219 // @codingStandardsIgnoreEnd