summaryrefslogtreecommitdiff
path: root/tests/phpunit/maintenance
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-06-04 07:31:04 +0200
committerPierre Schmitz <pierre@archlinux.de>2015-06-04 07:58:39 +0200
commitf6d65e533c62f6deb21342d4901ece24497b433e (patch)
treef28adf0362d14bcd448f7b65a7aaf38650f923aa /tests/phpunit/maintenance
parentc27b2e832fe25651ef2410fae85b41072aae7519 (diff)
Update to MediaWiki 1.25.1
Diffstat (limited to 'tests/phpunit/maintenance')
-rw-r--r--tests/phpunit/maintenance/DumpTestCase.php24
-rw-r--r--tests/phpunit/maintenance/backupTextPassTest.php126
2 files changed, 120 insertions, 30 deletions
diff --git a/tests/phpunit/maintenance/DumpTestCase.php b/tests/phpunit/maintenance/DumpTestCase.php
index 8b6aef53..8c763970 100644
--- a/tests/phpunit/maintenance/DumpTestCase.php
+++ b/tests/phpunit/maintenance/DumpTestCase.php
@@ -19,7 +19,7 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
protected $exceptionFromAddDBData = null;
/**
- * Holds the xmlreader used for analyzing an xml dump
+ * Holds the XMLReader used for analyzing an XML dump
*
* @var XMLReader|null
*/
@@ -30,13 +30,15 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
*
* @param Page $page Page to add the revision to
* @param string $text Revisions text
- * @param string $summary Revisions summare
- * @return array
+ * @param string $summary Revisions summary
+ * @param string $model The model ID (defaults to wikitext)
+ *
* @throws MWException
+ * @return array
*/
- protected function addRevision( Page $page, $text, $summary ) {
+ protected function addRevision( Page $page, $text, $summary, $model = CONTENT_MODEL_WIKITEXT ) {
$status = $page->doEditContent(
- ContentHandler::makeContent( $text, $page->getTitle() ),
+ ContentHandler::makeContent( $text, $page->getTitle(), $model ),
$summary
);
@@ -330,6 +332,12 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
$this->assertTextNode( "comment", $summary );
$this->skipWhitespace();
+ $this->assertTextNode( "model", $model );
+ $this->skipWhitespace();
+
+ $this->assertTextNode( "format", $format );
+ $this->skipWhitespace();
+
if ( $this->xml->name == "text" ) {
// note: <text> tag may occur here or at the very end.
$text_found = true;
@@ -340,12 +348,6 @@ abstract class DumpTestCase extends MediaWikiLangTestCase {
$this->assertTextNode( "sha1", $text_sha1 );
- $this->assertTextNode( "model", $model );
- $this->skipWhitespace();
-
- $this->assertTextNode( "format", $format );
- $this->skipWhitespace();
-
if ( !$text_found ) {
$this->assertText( $id, $text_id, $text_bytes, $text );
}
diff --git a/tests/phpunit/maintenance/backupTextPassTest.php b/tests/phpunit/maintenance/backupTextPassTest.php
index a37a97c7..a5ef7624 100644
--- a/tests/phpunit/maintenance/backupTextPassTest.php
+++ b/tests/phpunit/maintenance/backupTextPassTest.php
@@ -3,13 +3,13 @@
require_once __DIR__ . "/../../../maintenance/backupTextPass.inc";
/**
- * Tests for page dumps of BackupDumper
+ * Tests for TextPassDumper that rely on the database
*
* @group Database
* @group Dump
* @covers TextPassDumper
*/
-class TextPassDumperTest extends DumpTestCase {
+class TextPassDumperDatabaseTest extends DumpTestCase {
// We'll add several pages, revision and texts. The following variables hold the
// corresponding ids.
@@ -27,6 +27,10 @@ class TextPassDumperTest extends DumpTestCase {
$this->tablesUsed[] = 'revision';
$this->tablesUsed[] = 'text';
+ $this->mergeMwGlobalArrayValue( 'wgContentHandlers', array(
+ "BackupTextPassTestModel" => "BackupTextPassTestModelHandler"
+ ) );
+
$ns = $this->getDefaultWikitextNS();
try {
@@ -61,7 +65,8 @@ class TextPassDumperTest extends DumpTestCase {
$this->pageId3 = $page->getId();
$page->doDeleteArticle( "Testing ;)" );
- // Page from non-default namespace
+ // Page from non-default namespace and model.
+ // ExportTransform applies.
if ( $ns === NS_TALK ) {
// @todo work around this.
@@ -73,7 +78,8 @@ class TextPassDumperTest extends DumpTestCase {
$page = WikiPage::factory( $title );
list( $this->revId4_1, $this->textId4_1 ) = $this->addRevision( $page,
"Talk about BackupDumperTestP1 Text1",
- "Talk BackupDumperTestP1 Summary1" );
+ "Talk BackupDumperTestP1 Summary1",
+ "BackupTextPassTestModel" );
$this->pageId4 = $page->getId();
} catch ( Exception $e ) {
// We'd love to pass $e directly. However, ... see
@@ -141,7 +147,10 @@ class TextPassDumperTest extends DumpTestCase {
$this->assertPageStart( $this->pageId4, NS_TALK, "Talk:BackupDumperTestP1" );
$this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
$this->textId4_1, false, "nktofwzd0tl192k3zfepmlzxoax1lpe",
- "Talk about BackupDumperTestP1 Text1" );
+ "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
+ false,
+ "BackupTextPassTestModel",
+ "text/plain" );
$this->assertPageEnd();
$this->assertDumpEnd();
@@ -209,7 +218,10 @@ class TextPassDumperTest extends DumpTestCase {
$this->assertPageStart( $this->pageId4, NS_TALK, "Talk:BackupDumperTestP1" );
$this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
$this->textId4_1, false, "nktofwzd0tl192k3zfepmlzxoax1lpe",
- "Talk about BackupDumperTestP1 Text1" );
+ "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
+ false,
+ "BackupTextPassTestModel",
+ "text/plain" );
$this->assertPageEnd();
$this->assertDumpEnd();
@@ -232,7 +244,9 @@ class TextPassDumperTest extends DumpTestCase {
$this->fail( "Could not open stream for stderr" );
}
- $iterations = 32; // We'll start with that many iterations of revisions in stub
+ $iterations = 32; // We'll start with that many iterations of revisions
+ // in stub. Make sure that the generated volume is above the buffer size
+ // set below. Otherwise, the checkpointing does not trigger.
$lastDuration = 0;
$minDuration = 2; // We want the dump to take at least this many seconds
$checkpointAfter = 0.5; // Generate checkpoint after this many seconds
@@ -250,6 +264,7 @@ class TextPassDumperTest extends DumpTestCase {
$dumper = new TextPassDumper( array( "--stub=file:" . $nameStub,
"--output=" . $checkpointFormat . ":" . $nameOutputDir . "/full",
"--maxtime=1" /*This is in minutes. Fixup is below*/,
+ "--buffersize=32768", // The default of 32 iterations fill up 32KB about twice
"--checkpointfile=checkpoint-%s-%s.xml.gz" ) );
$dumper->setDb( $this->db );
$dumper->maxTimeAllowed = $checkpointAfter; // Patching maxTime from 1 minute
@@ -362,7 +377,10 @@ class TextPassDumperTest extends DumpTestCase {
$this->assertRevision( $this->revId4_1 + $i * self::$numOfRevs,
"Talk BackupDumperTestP1 Summary1",
$this->textId4_1, false, "nktofwzd0tl192k3zfepmlzxoax1lpe",
- "Talk about BackupDumperTestP1 Text1" );
+ "TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
+ false,
+ "BackupTextPassTestModel",
+ "text/plain" );
$this->assertPageEnd();
$lookingForPage = 1;
@@ -440,10 +458,10 @@ class TextPassDumperTest extends DumpTestCase {
if ( $fname === null ) {
$fname = $this->getNewTempFile();
}
- $header = '<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.7/" '
+ $header = '<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.7/ '
- . 'http://www.mediawiki.org/xml/export-0.7.xsd" version="0.7" xml:lang="en">
+ . '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>
<sitename>wikisvn</sitename>
<base>http://localhost/wiki-svn/index.php/Main_Page</base>
@@ -489,10 +507,10 @@ class TextPassDumperTest extends DumpTestCase {
<ip>127.0.0.1</ip>
</contributor>
<comment>BackupDumperTestP1Summary1</comment>
- <sha1>0bolhl6ol7i6x0e7yq91gxgaan39j87</sha1>
<model>wikitext</model>
<format>text/x-wiki</format>
<text id="' . $this->textId1_1 . '" bytes="23" />
+ <sha1>0bolhl6ol7i6x0e7yq91gxgaan39j87</sha1>
</revision>
</page>
';
@@ -507,10 +525,10 @@ class TextPassDumperTest extends DumpTestCase {
<ip>127.0.0.1</ip>
</contributor>
<comment>BackupDumperTestP2Summary1</comment>
- <sha1>jprywrymfhysqllua29tj3sc7z39dl2</sha1>
<model>wikitext</model>
<format>text/x-wiki</format>
<text id="' . $this->textId2_1 . '" bytes="23" />
+ <sha1>jprywrymfhysqllua29tj3sc7z39dl2</sha1>
</revision>
<revision>
<id>' . ( $this->revId2_2 + $i * self::$numOfRevs ) . '</id>
@@ -520,10 +538,10 @@ class TextPassDumperTest extends DumpTestCase {
<ip>127.0.0.1</ip>
</contributor>
<comment>BackupDumperTestP2Summary2</comment>
- <sha1>b7vj5ks32po5m1z1t1br4o7scdwwy95</sha1>
<model>wikitext</model>
<format>text/x-wiki</format>
<text id="' . $this->textId2_2 . '" bytes="23" />
+ <sha1>b7vj5ks32po5m1z1t1br4o7scdwwy95</sha1>
</revision>
<revision>
<id>' . ( $this->revId2_3 + $i * self::$numOfRevs ) . '</id>
@@ -533,10 +551,10 @@ class TextPassDumperTest extends DumpTestCase {
<ip>127.0.0.1</ip>
</contributor>
<comment>BackupDumperTestP2Summary3</comment>
- <sha1>jfunqmh1ssfb8rs43r19w98k28gg56r</sha1>
<model>wikitext</model>
<format>text/x-wiki</format>
<text id="' . $this->textId2_3 . '" bytes="23" />
+ <sha1>jfunqmh1ssfb8rs43r19w98k28gg56r</sha1>
</revision>
<revision>
<id>' . ( $this->revId2_4 + $i * self::$numOfRevs ) . '</id>
@@ -546,10 +564,10 @@ class TextPassDumperTest extends DumpTestCase {
<ip>127.0.0.1</ip>
</contributor>
<comment>BackupDumperTestP2Summary4 extra</comment>
- <sha1>6o1ciaxa6pybnqprmungwofc4lv00wv</sha1>
<model>wikitext</model>
<format>text/x-wiki</format>
<text id="' . $this->textId2_4 . '" bytes="44" />
+ <sha1>6o1ciaxa6pybnqprmungwofc4lv00wv</sha1>
</revision>
</page>
';
@@ -566,10 +584,10 @@ class TextPassDumperTest extends DumpTestCase {
<ip>127.0.0.1</ip>
</contributor>
<comment>Talk BackupDumperTestP1 Summary1</comment>
- <sha1>nktofwzd0tl192k3zfepmlzxoax1lpe</sha1>
- <model>wikitext</model>
- <format>text/x-wiki</format>
+ <model>BackupTextPassTestModel</model>
+ <format>text/plain</format>
<text id="' . $this->textId4_1 . '" bytes="35" />
+ <sha1>nktofwzd0tl192k3zfepmlzxoax1lpe</sha1>
</revision>
</page>
';
@@ -582,3 +600,73 @@ class TextPassDumperTest extends DumpTestCase {
return $fname;
}
}
+
+class BackupTextPassTestModelHandler extends TextContentHandler {
+
+ public function __construct() {
+ parent::__construct( 'BackupTextPassTestModel' );
+ }
+
+ public function exportTransform( $text, $format = null ) {
+ return strtoupper( $text );
+ }
+
+}
+
+/**
+ * Tests for TextPassDumper that do not rely on the database
+ *
+ * (As the Database group is only detected at class level (not method level), we
+ * cannot bring this test case's tests into the above main test case.)
+ *
+ * @group Dump
+ * @covers TextPassDumper
+ */
+class TextPassDumperDatabaselessTest extends MediaWikiLangTestCase {
+ /**
+ * Ensures that setting the buffer size is effective.
+ *
+ * @dataProvider bufferSizeProvider
+ */
+ function testBufferSizeSetting( $expected, $size, $msg ) {
+ $dumper = new TextPassDumperAccessor( array( "--buffersize=" . $size ) );
+ $this->assertEquals( $expected, $dumper->getBufferSize(), $msg);
+ }
+
+ /**
+ * Ensures that setting the buffer size is effective.
+ *
+ * @dataProvider bufferSizeProvider
+ */
+ function bufferSizeProvider() {
+ // expected, bufferSize to initialize with, message
+ return array(
+ array( 512 * 1024, 512 * 1024, "Setting 512KB is not effective" ),
+ array( 8192, 8192, "Setting 8KB is not effective" ),
+ array( 4096, 2048, "Could set buffer size below lower bound" )
+ );
+ }
+}
+
+/**
+ * Accessor for internal state of TextPassDumper
+ *
+ * Do not warrentless add getters here.
+ */
+class TextPassDumperAccessor extends TextPassDumper {
+ /**
+ * Gets the bufferSize.
+ *
+ * If bufferSize setting does not work correctly, testCheckpoint... tests
+ * fail and point in the wrong direction. To aid in troubleshooting when
+ * testCheckpoint... tests break at some point in the future, we test the
+ * bufferSize setting, hence need this accessor.
+ *
+ * (Yes, bufferSize is internal state of the TextPassDumper, but aiding
+ * debugging of testCheckpoint... in the future seems to be worth testing
+ * against it nonetheless.)
+ */
+ public function getBufferSize() {
+ return $this->bufferSize;
+ }
+}