2014-05-19 12:23:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test class for Import methods.
|
|
|
|
|
*
|
|
|
|
|
* @group Database
|
|
|
|
|
*
|
|
|
|
|
* @author Sebastian Brückner < sebastian.brueckner@student.hpi.uni-potsdam.de >
|
|
|
|
|
*/
|
|
|
|
|
class ImportTest extends MediaWikiLangTestCase {
|
|
|
|
|
|
2014-11-14 00:56:47 +00:00
|
|
|
private function getDataSource( $xml ) {
|
|
|
|
|
return new ImportStringSource( $xml );
|
2014-05-19 12:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-05 12:02:03 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiImporter
|
|
|
|
|
* @dataProvider getUnknownTagsXML
|
|
|
|
|
* @param string $xml
|
|
|
|
|
* @param string $text
|
|
|
|
|
* @param string $title
|
|
|
|
|
*/
|
|
|
|
|
public function testUnknownXMLTags( $xml, $text, $title ) {
|
|
|
|
|
$source = $this->getDataSource( $xml );
|
|
|
|
|
|
|
|
|
|
$importer = new WikiImporter(
|
|
|
|
|
$source,
|
|
|
|
|
ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$importer->doImport();
|
|
|
|
|
$title = Title::newFromText( $title );
|
|
|
|
|
$this->assertTrue( $title->exists() );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( WikiPage::factory( $title )->getContent()->getNativeData(), $text );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getUnknownTagsXML() {
|
|
|
|
|
// @codingStandardsIgnoreStart Generic.Files.LineLength
|
|
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
<<< EOF
|
|
|
|
|
<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">
|
|
|
|
|
<page unknown="123" dontknow="533">
|
|
|
|
|
<title>TestImportPage</title>
|
|
|
|
|
<unknowntag>Should be ignored</unknowntag>
|
|
|
|
|
<ns>0</ns>
|
|
|
|
|
<id unknown="123" dontknow="533">14</id>
|
|
|
|
|
<revision>
|
|
|
|
|
<id unknown="123" dontknow="533">15</id>
|
|
|
|
|
<unknowntag>Should be ignored</unknowntag>
|
|
|
|
|
<timestamp>2016-01-03T11:18:43Z</timestamp>
|
|
|
|
|
<contributor>
|
|
|
|
|
<unknowntag>Should be ignored</unknowntag>
|
|
|
|
|
<username unknown="123" dontknow="533">Admin</username>
|
|
|
|
|
<id>1</id>
|
|
|
|
|
</contributor>
|
|
|
|
|
<model>wikitext</model>
|
|
|
|
|
<format>text/x-wiki</format>
|
|
|
|
|
<text xml:space="preserve" bytes="0">noitazinagro tseb eht si ikiWaideM</text>
|
|
|
|
|
<sha1>phoiac9h4m842xq45sp7s6u21eteeq1</sha1>
|
|
|
|
|
<unknowntag>Should be ignored</unknowntag>
|
|
|
|
|
</revision>
|
|
|
|
|
</page>
|
|
|
|
|
<unknowntag>Should be ignored</unknowntag>
|
|
|
|
|
</mediawiki>
|
|
|
|
|
EOF
|
|
|
|
|
,
|
|
|
|
|
'noitazinagro tseb eht si ikiWaideM',
|
|
|
|
|
'TestImportPage'
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
// @codingStandardsIgnoreEnd
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-19 12:23:32 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiImporter::handlePage
|
|
|
|
|
* @dataProvider getRedirectXML
|
|
|
|
|
* @param string $xml
|
2014-08-15 16:22:34 +00:00
|
|
|
* @param string|null $redirectTitle
|
2014-05-19 12:23:32 +00:00
|
|
|
*/
|
|
|
|
|
public function testHandlePageContainsRedirect( $xml, $redirectTitle ) {
|
2014-11-14 00:56:47 +00:00
|
|
|
$source = $this->getDataSource( $xml );
|
2014-05-19 12:23:32 +00:00
|
|
|
|
2014-07-19 21:12:10 +00:00
|
|
|
$redirect = null;
|
2014-12-10 11:24:47 +00:00
|
|
|
$callback = function ( Title $title, ForeignTitle $foreignTitle, $revCount,
|
|
|
|
|
$sRevCount, $pageInfo ) use ( &$redirect ) {
|
2014-05-19 12:23:32 +00:00
|
|
|
if ( array_key_exists( 'redirect', $pageInfo ) ) {
|
|
|
|
|
$redirect = $pageInfo['redirect'];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-10-03 13:04:51 +00:00
|
|
|
$importer = new WikiImporter(
|
|
|
|
|
$source,
|
|
|
|
|
ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
|
|
|
|
|
);
|
2014-05-19 12:23:32 +00:00
|
|
|
$importer->setPageOutCallback( $callback );
|
|
|
|
|
$importer->doImport();
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $redirectTitle, $redirect );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getRedirectXML() {
|
2015-10-03 13:04:51 +00:00
|
|
|
// @codingStandardsIgnoreStart Generic.Files.LineLength
|
2014-05-19 12:23:32 +00:00
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
<<< EOF
|
2014-10-24 13:48:20 +00:00
|
|
|
<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">
|
2014-05-19 12:23:32 +00:00
|
|
|
<page>
|
|
|
|
|
<title>Test</title>
|
|
|
|
|
<ns>0</ns>
|
|
|
|
|
<id>21</id>
|
|
|
|
|
<redirect title="Test22"/>
|
|
|
|
|
<revision>
|
|
|
|
|
<id>20</id>
|
|
|
|
|
<timestamp>2014-05-27T10:00:00Z</timestamp>
|
|
|
|
|
<contributor>
|
|
|
|
|
<username>Admin</username>
|
|
|
|
|
<id>10</id>
|
|
|
|
|
</contributor>
|
|
|
|
|
<comment>Admin moved page [[Test]] to [[Test22]]</comment>
|
|
|
|
|
<model>wikitext</model>
|
|
|
|
|
<format>text/x-wiki</format>
|
2014-10-24 13:48:20 +00:00
|
|
|
<text xml:space="preserve" bytes="20">#REDIRECT [[Test22]]</text>
|
|
|
|
|
<sha1>tq456o9x3abm7r9ozi6km8yrbbc56o6</sha1>
|
2014-05-19 12:23:32 +00:00
|
|
|
</revision>
|
|
|
|
|
</page>
|
|
|
|
|
</mediawiki>
|
|
|
|
|
EOF
|
|
|
|
|
,
|
|
|
|
|
'Test22'
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
<<< EOF
|
2014-10-24 13:48:20 +00:00
|
|
|
<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">
|
2014-05-19 12:23:32 +00:00
|
|
|
<page>
|
|
|
|
|
<title>Test</title>
|
|
|
|
|
<ns>0</ns>
|
|
|
|
|
<id>42</id>
|
|
|
|
|
<revision>
|
|
|
|
|
<id>421</id>
|
|
|
|
|
<timestamp>2014-05-27T11:00:00Z</timestamp>
|
|
|
|
|
<contributor>
|
|
|
|
|
<username>Admin</username>
|
|
|
|
|
<id>10</id>
|
|
|
|
|
</contributor>
|
|
|
|
|
<text xml:space="preserve" bytes="4">Abcd</text>
|
|
|
|
|
<sha1>n7uomjq96szt60fy5w3x7ahf7q8m8rh</sha1>
|
|
|
|
|
<model>wikitext</model>
|
|
|
|
|
<format>text/x-wiki</format>
|
|
|
|
|
</revision>
|
|
|
|
|
</page>
|
|
|
|
|
</mediawiki>
|
|
|
|
|
EOF
|
|
|
|
|
,
|
2014-07-19 21:12:10 +00:00
|
|
|
null
|
2014-05-19 12:23:32 +00:00
|
|
|
),
|
|
|
|
|
);
|
2015-10-03 13:04:51 +00:00
|
|
|
// @codingStandardsIgnoreEnd
|
2014-05-19 12:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-10 11:24:47 +00:00
|
|
|
/**
|
|
|
|
|
* @covers WikiImporter::handleSiteInfo
|
|
|
|
|
* @dataProvider getSiteInfoXML
|
|
|
|
|
* @param string $xml
|
|
|
|
|
* @param array|null $namespaces
|
|
|
|
|
*/
|
|
|
|
|
public function testSiteInfoContainsNamespaces( $xml, $namespaces ) {
|
2014-11-14 00:56:47 +00:00
|
|
|
$source = $this->getDataSource( $xml );
|
2014-12-10 11:24:47 +00:00
|
|
|
|
|
|
|
|
$importNamespaces = null;
|
|
|
|
|
$callback = function ( array $siteinfo, $innerImporter ) use ( &$importNamespaces ) {
|
|
|
|
|
$importNamespaces = $siteinfo['_namespaces'];
|
|
|
|
|
};
|
|
|
|
|
|
2015-10-03 13:04:51 +00:00
|
|
|
$importer = new WikiImporter(
|
|
|
|
|
$source,
|
|
|
|
|
ConfigFactory::getDefaultInstance()->makeConfig( 'main' )
|
|
|
|
|
);
|
2014-12-10 11:24:47 +00:00
|
|
|
$importer->setSiteInfoCallback( $callback );
|
|
|
|
|
$importer->doImport();
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $importNamespaces, $namespaces );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getSiteInfoXML() {
|
2015-10-03 13:04:51 +00:00
|
|
|
// @codingStandardsIgnoreStart Generic.Files.LineLength
|
2014-12-10 11:24:47 +00:00
|
|
|
return array(
|
|
|
|
|
array(
|
|
|
|
|
<<< EOF
|
|
|
|
|
<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">
|
|
|
|
|
<siteinfo>
|
|
|
|
|
<namespaces>
|
|
|
|
|
<namespace key="-2" case="first-letter">Media</namespace>
|
|
|
|
|
<namespace key="-1" case="first-letter">Special</namespace>
|
|
|
|
|
<namespace key="0" case="first-letter" />
|
|
|
|
|
<namespace key="1" case="first-letter">Talk</namespace>
|
|
|
|
|
<namespace key="2" case="first-letter">User</namespace>
|
|
|
|
|
<namespace key="3" case="first-letter">User talk</namespace>
|
|
|
|
|
<namespace key="100" case="first-letter">Portal</namespace>
|
|
|
|
|
<namespace key="101" case="first-letter">Portal talk</namespace>
|
|
|
|
|
</namespaces>
|
|
|
|
|
</siteinfo>
|
|
|
|
|
</mediawiki>
|
|
|
|
|
EOF
|
|
|
|
|
,
|
|
|
|
|
array(
|
|
|
|
|
'-2' => 'Media',
|
|
|
|
|
'-1' => 'Special',
|
|
|
|
|
'0' => '',
|
|
|
|
|
'1' => 'Talk',
|
|
|
|
|
'2' => 'User',
|
|
|
|
|
'3' => 'User talk',
|
|
|
|
|
'100' => 'Portal',
|
|
|
|
|
'101' => 'Portal talk',
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
);
|
2015-10-03 13:04:51 +00:00
|
|
|
// @codingStandardsIgnoreEnd
|
2014-12-10 11:24:47 +00:00
|
|
|
}
|
|
|
|
|
|
2014-05-19 12:23:32 +00:00
|
|
|
}
|