From f6d65e533c62f6deb21342d4901ece24497b433e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 4 Jun 2015 07:31:04 +0200 Subject: Update to MediaWiki 1.25.1 --- tests/phpunit/maintenance/DumpTestCase.php | 24 +++-- tests/phpunit/maintenance/backupTextPassTest.php | 126 +++++++++++++++++++---- 2 files changed, 120 insertions(+), 30 deletions(-) (limited to 'tests/phpunit/maintenance') 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: 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 = ' + . '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"> wikisvn http://localhost/wiki-svn/index.php/Main_Page @@ -489,10 +507,10 @@ class TextPassDumperTest extends DumpTestCase { 127.0.0.1 BackupDumperTestP1Summary1 - 0bolhl6ol7i6x0e7yq91gxgaan39j87 wikitext text/x-wiki + 0bolhl6ol7i6x0e7yq91gxgaan39j87 '; @@ -507,10 +525,10 @@ class TextPassDumperTest extends DumpTestCase { 127.0.0.1 BackupDumperTestP2Summary1 - jprywrymfhysqllua29tj3sc7z39dl2 wikitext text/x-wiki + jprywrymfhysqllua29tj3sc7z39dl2 ' . ( $this->revId2_2 + $i * self::$numOfRevs ) . ' @@ -520,10 +538,10 @@ class TextPassDumperTest extends DumpTestCase { 127.0.0.1 BackupDumperTestP2Summary2 - b7vj5ks32po5m1z1t1br4o7scdwwy95 wikitext text/x-wiki + b7vj5ks32po5m1z1t1br4o7scdwwy95 ' . ( $this->revId2_3 + $i * self::$numOfRevs ) . ' @@ -533,10 +551,10 @@ class TextPassDumperTest extends DumpTestCase { 127.0.0.1 BackupDumperTestP2Summary3 - jfunqmh1ssfb8rs43r19w98k28gg56r wikitext text/x-wiki + jfunqmh1ssfb8rs43r19w98k28gg56r ' . ( $this->revId2_4 + $i * self::$numOfRevs ) . ' @@ -546,10 +564,10 @@ class TextPassDumperTest extends DumpTestCase { 127.0.0.1 BackupDumperTestP2Summary4 extra - 6o1ciaxa6pybnqprmungwofc4lv00wv wikitext text/x-wiki + 6o1ciaxa6pybnqprmungwofc4lv00wv '; @@ -566,10 +584,10 @@ class TextPassDumperTest extends DumpTestCase { 127.0.0.1 Talk BackupDumperTestP1 Summary1 - nktofwzd0tl192k3zfepmlzxoax1lpe - wikitext - text/x-wiki + BackupTextPassTestModel + text/plain + nktofwzd0tl192k3zfepmlzxoax1lpe '; @@ -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; + } +} -- cgit v1.2.2