<?php
-require_once __DIR__ . "/../../../maintenance/dumpTextPass.php";
+namespace MediaWiki\Tests\Maintenance;
+
+use Exception;
+use MediaWikiLangTestCase;
+use MWException;
+use TextContentHandler;
+use TextPassDumper;
+use Title;
+use WikiExporter;
+use WikiPage;
/**
* Tests for TextPassDumper that rely on the database
$this->tablesUsed[] = 'text';
$this->mergeMwGlobalArrayValue( 'wgContentHandlers', [
- "BackupTextPassTestModel" => "BackupTextPassTestModelHandler"
+ "BackupTextPassTestModel" => BackupTextPassTestModelHandler::class,
] );
$ns = $this->getDefaultWikitextNS();
$dumper->dump( WikiExporter::FULL, WikiExporter::TEXT );
// Checking for correctness of the dumped data
- $this->assertDumpStart( $nameFull );
+ $asserter = $this->getDumpAsserter();
+ $asserter->assertDumpStart( $nameFull );
// Page 1
- $this->assertPageStart( $this->pageId1, NS_MAIN, "BackupDumperTestP1" );
- $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
+ $asserter->assertPageStart( $this->pageId1, NS_MAIN, "BackupDumperTestP1" );
+ $asserter->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
$this->textId1_1, false, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
"BackupDumperTestP1Text1" );
- $this->assertPageEnd();
+ $asserter->assertPageEnd();
// Page 2
- $this->assertPageStart( $this->pageId2, NS_MAIN, "BackupDumperTestP2" );
- $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
+ $asserter->assertPageStart( $this->pageId2, NS_MAIN, "BackupDumperTestP2" );
+ $asserter->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
$this->textId2_1, false, "jprywrymfhysqllua29tj3sc7z39dl2",
"BackupDumperTestP2Text1" );
- $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
+ $asserter->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
$this->textId2_2, false, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
"BackupDumperTestP2Text2", $this->revId2_1 );
- $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
+ $asserter->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
$this->textId2_3, false, "jfunqmh1ssfb8rs43r19w98k28gg56r",
"BackupDumperTestP2Text3", $this->revId2_2 );
- $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
+ $asserter->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
$this->textId2_4, false, "6o1ciaxa6pybnqprmungwofc4lv00wv",
"BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
- $this->assertPageEnd();
+ $asserter->assertPageEnd();
// Page 3
// -> Page is marked deleted. Hence not visible
// Page 4
- $this->assertPageStart( $this->pageId4, NS_TALK, "Talk:BackupDumperTestP1" );
- $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
+ $asserter->assertPageStart( $this->pageId4, NS_TALK, "Talk:BackupDumperTestP1" );
+ $asserter->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
$this->textId4_1, false, "nktofwzd0tl192k3zfepmlzxoax1lpe",
"TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
false,
"BackupTextPassTestModel",
"text/plain" );
- $this->assertPageEnd();
+ $asserter->assertPageEnd();
- $this->assertDumpEnd();
+ $asserter->assertDumpEnd();
}
function testPrefetchPlain() {
];
// The mock itself
- $prefetchMock = $this->getMockBuilder( 'BaseDump' )
+ $prefetchMock = $this->getMockBuilder( BaseDump::class )
->setMethods( [ 'prefetch' ] )
->disableOriginalConstructor()
->getMock();
$dumper->dump( WikiExporter::FULL, WikiExporter::TEXT );
// Checking for correctness of the dumped data
- $this->assertDumpStart( $nameFull );
+ $asserter = $this->getDumpAsserter();
+ $asserter->assertDumpStart( $nameFull );
// Page 1
- $this->assertPageStart( $this->pageId1, NS_MAIN, "BackupDumperTestP1" );
+ $asserter->assertPageStart( $this->pageId1, NS_MAIN, "BackupDumperTestP1" );
// Prefetch kicks in. This is still the SHA-1 of the original text,
// But the actual text (with different SHA-1) comes from prefetch.
- $this->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
+ $asserter->assertRevision( $this->revId1_1, "BackupDumperTestP1Summary1",
$this->textId1_1, false, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
"Prefetch_________1Text1" );
- $this->assertPageEnd();
+ $asserter->assertPageEnd();
// Page 2
- $this->assertPageStart( $this->pageId2, NS_MAIN, "BackupDumperTestP2" );
- $this->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
+ $asserter->assertPageStart( $this->pageId2, NS_MAIN, "BackupDumperTestP2" );
+ $asserter->assertRevision( $this->revId2_1, "BackupDumperTestP2Summary1",
$this->textId2_1, false, "jprywrymfhysqllua29tj3sc7z39dl2",
"BackupDumperTestP2Text1" );
- $this->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
+ $asserter->assertRevision( $this->revId2_2, "BackupDumperTestP2Summary2",
$this->textId2_2, false, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
"BackupDumperTestP2Text2", $this->revId2_1 );
// Prefetch kicks in. This is still the SHA-1 of the original text,
// But the actual text (with different SHA-1) comes from prefetch.
- $this->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
+ $asserter->assertRevision( $this->revId2_3, "BackupDumperTestP2Summary3",
$this->textId2_3, false, "jfunqmh1ssfb8rs43r19w98k28gg56r",
"Prefetch_________2Text3", $this->revId2_2 );
- $this->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
+ $asserter->assertRevision( $this->revId2_4, "BackupDumperTestP2Summary4 extra",
$this->textId2_4, false, "6o1ciaxa6pybnqprmungwofc4lv00wv",
"BackupDumperTestP2Text4 some additional Text", $this->revId2_3 );
- $this->assertPageEnd();
+ $asserter->assertPageEnd();
// Page 3
// -> Page is marked deleted. Hence not visible
// Page 4
- $this->assertPageStart( $this->pageId4, NS_TALK, "Talk:BackupDumperTestP1" );
- $this->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
+ $asserter->assertPageStart( $this->pageId4, NS_TALK, "Talk:BackupDumperTestP1" );
+ $asserter->assertRevision( $this->revId4_1, "Talk BackupDumperTestP1 Summary1",
$this->textId4_1, false, "nktofwzd0tl192k3zfepmlzxoax1lpe",
"TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
false,
"BackupTextPassTestModel",
"text/plain" );
- $this->assertPageEnd();
+ $asserter->assertPageEnd();
- $this->assertDumpEnd();
+ $asserter->assertDumpEnd();
}
/**
$lookingForPage = 1;
$checkpointFiles = 0;
+ $asserter = $this->getDumpAsserter();
+
// Each run of the following loop body tries to handle exactly 1 /page/ (not
// iteration of stub content). $i is only increased after having treated page 4.
for ( $i = 0; $i < $iterations; ) {
if ( $checkpointFormat == "gzip" ) {
$this->gunzip( $nameOutputDir . "/" . $fname );
}
- $this->assertDumpStart( $nameOutputDir . "/" . $fname );
+ $asserter->assertDumpStart( $nameOutputDir . "/" . $fname );
$fileOpened = true;
$checkpointFiles++;
}
switch ( $lookingForPage ) {
case 1:
// Page 1
- $this->assertPageStart( $this->pageId1 + $i * self::$numOfPages, NS_MAIN,
- "BackupDumperTestP1" );
- $this->assertRevision( $this->revId1_1 + $i * self::$numOfRevs, "BackupDumperTestP1Summary1",
- $this->textId1_1, false, "0bolhl6ol7i6x0e7yq91gxgaan39j87",
- "BackupDumperTestP1Text1" );
- $this->assertPageEnd();
+ $asserter->assertPageStart(
+ $this->pageId1 + $i * self::$numOfPages,
+ NS_MAIN,
+ "BackupDumperTestP1"
+ );
+ $asserter->assertRevision(
+ $this->revId1_1 + $i * self::$numOfRevs,
+ "BackupDumperTestP1Summary1",
+ $this->textId1_1,
+ false,
+ "0bolhl6ol7i6x0e7yq91gxgaan39j87",
+ "BackupDumperTestP1Text1"
+ );
+ $asserter->assertPageEnd();
$lookingForPage = 2;
break;
case 2:
// Page 2
- $this->assertPageStart( $this->pageId2 + $i * self::$numOfPages, NS_MAIN,
- "BackupDumperTestP2" );
- $this->assertRevision( $this->revId2_1 + $i * self::$numOfRevs, "BackupDumperTestP2Summary1",
- $this->textId2_1, false, "jprywrymfhysqllua29tj3sc7z39dl2",
- "BackupDumperTestP2Text1" );
- $this->assertRevision( $this->revId2_2 + $i * self::$numOfRevs, "BackupDumperTestP2Summary2",
- $this->textId2_2, false, "b7vj5ks32po5m1z1t1br4o7scdwwy95",
- "BackupDumperTestP2Text2", $this->revId2_1 + $i * self::$numOfRevs );
- $this->assertRevision( $this->revId2_3 + $i * self::$numOfRevs, "BackupDumperTestP2Summary3",
- $this->textId2_3, false, "jfunqmh1ssfb8rs43r19w98k28gg56r",
- "BackupDumperTestP2Text3", $this->revId2_2 + $i * self::$numOfRevs );
- $this->assertRevision( $this->revId2_4 + $i * self::$numOfRevs,
+ $asserter->assertPageStart(
+ $this->pageId2 + $i * self::$numOfPages,
+ NS_MAIN,
+ "BackupDumperTestP2"
+ );
+ $asserter->assertRevision(
+ $this->revId2_1 + $i * self::$numOfRevs,
+ "BackupDumperTestP2Summary1",
+ $this->textId2_1,
+ false,
+ "jprywrymfhysqllua29tj3sc7z39dl2",
+ "BackupDumperTestP2Text1"
+ );
+ $asserter->assertRevision(
+ $this->revId2_2 + $i * self::$numOfRevs,
+ "BackupDumperTestP2Summary2",
+ $this->textId2_2,
+ false,
+ "b7vj5ks32po5m1z1t1br4o7scdwwy95",
+ "BackupDumperTestP2Text2",
+ $this->revId2_1 + $i * self::$numOfRevs
+ );
+ $asserter->assertRevision(
+ $this->revId2_3 + $i * self::$numOfRevs,
+ "BackupDumperTestP2Summary3",
+ $this->textId2_3,
+ false,
+ "jfunqmh1ssfb8rs43r19w98k28gg56r",
+ "BackupDumperTestP2Text3",
+ $this->revId2_2 + $i * self::$numOfRevs
+ );
+ $asserter->assertRevision(
+ $this->revId2_4 + $i * self::$numOfRevs,
"BackupDumperTestP2Summary4 extra",
- $this->textId2_4, false, "6o1ciaxa6pybnqprmungwofc4lv00wv",
+ $this->textId2_4,
+ false,
+ "6o1ciaxa6pybnqprmungwofc4lv00wv",
"BackupDumperTestP2Text4 some additional Text",
- $this->revId2_3 + $i * self::$numOfRevs );
- $this->assertPageEnd();
+ $this->revId2_3 + $i * self::$numOfRevs
+ );
+ $asserter->assertPageEnd();
$lookingForPage = 4;
break;
case 4:
// Page 4
- $this->assertPageStart( $this->pageId4 + $i * self::$numOfPages, NS_TALK,
- "Talk:BackupDumperTestP1" );
- $this->assertRevision( $this->revId4_1 + $i * self::$numOfRevs,
+ $asserter->assertPageStart(
+ $this->pageId4 + $i * self::$numOfPages,
+ NS_TALK,
+ "Talk:BackupDumperTestP1"
+ );
+ $asserter->assertRevision(
+ $this->revId4_1 + $i * self::$numOfRevs,
"Talk BackupDumperTestP1 Summary1",
- $this->textId4_1, false, "nktofwzd0tl192k3zfepmlzxoax1lpe",
+ $this->textId4_1,
+ false,
+ "nktofwzd0tl192k3zfepmlzxoax1lpe",
"TALK ABOUT BACKUPDUMPERTESTP1 TEXT1",
false,
"BackupTextPassTestModel",
- "text/plain" );
- $this->assertPageEnd();
+ "text/plain"
+ );
+ $asserter->assertPageEnd();
$lookingForPage = 1;
if ( $this->xml->nodeType == XMLReader::END_ELEMENT
&& $this->xml->name == "mediawiki"
) {
- $this->assertDumpEnd();
+ $asserter->assertDumpEnd();
$fileOpened = false;
}
}
$content = $header;
$iterations = intval( $iterations );
+ $username = $this->getTestUser()->getUser()->getName();
+ $userid = $this->getTestUser()->getUser()->getId();
for ( $i = 0; $i < $iterations; $i++ ) {
$page1 = ' <page>
<title>BackupDumperTestP1</title>
<id>' . ( $this->revId1_1 + $i * self::$numOfRevs ) . '</id>
<timestamp>2012-04-01T16:46:05Z</timestamp>
<contributor>
- <ip>127.0.0.1</ip>
+ <username>' . $username . '</username>
+ <id>' . $userid . '</id>
</contributor>
<comment>BackupDumperTestP1Summary1</comment>
<model>wikitext</model>
<id>' . ( $this->revId2_1 + $i * self::$numOfRevs ) . '</id>
<timestamp>2012-04-01T16:46:05Z</timestamp>
<contributor>
- <ip>127.0.0.1</ip>
+ <username>' . $username . '</username>
+ <id>' . $userid . '</id>
</contributor>
<comment>BackupDumperTestP2Summary1</comment>
<model>wikitext</model>
<parentid>' . ( $this->revId2_1 + $i * self::$numOfRevs ) . '</parentid>
<timestamp>2012-04-01T16:46:05Z</timestamp>
<contributor>
- <ip>127.0.0.1</ip>
+ <username>' . $username . '</username>
+ <id>' . $userid . '</id>
</contributor>
<comment>BackupDumperTestP2Summary2</comment>
<model>wikitext</model>
<parentid>' . ( $this->revId2_2 + $i * self::$numOfRevs ) . '</parentid>
<timestamp>2012-04-01T16:46:05Z</timestamp>
<contributor>
- <ip>127.0.0.1</ip>
+ <username>' . $username . '</username>
+ <id>' . $userid . '</id>
</contributor>
<comment>BackupDumperTestP2Summary3</comment>
<model>wikitext</model>
<parentid>' . ( $this->revId2_3 + $i * self::$numOfRevs ) . '</parentid>
<timestamp>2012-04-01T16:46:05Z</timestamp>
<contributor>
- <ip>127.0.0.1</ip>
+ <username>' . $username . '</username>
+ <id>' . $userid . '</id>
</contributor>
<comment>BackupDumperTestP2Summary4 extra</comment>
<model>wikitext</model>
<id>' . ( $this->revId4_1 + $i * self::$numOfRevs ) . '</id>
<timestamp>2012-04-01T16:46:05Z</timestamp>
<contributor>
- <ip>127.0.0.1</ip>
+ <username>' . $username . '</username>
+ <id>' . $userid . '</id>
</contributor>
<comment>Talk BackupDumperTestP1 Summary1</comment>
<model>BackupTextPassTestModel</model>