<?php
use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\MutableRevisionRecord;
use MediaWiki\Storage\RevisionStore;
use MediaWiki\Storage\IncompleteRevisionException;
use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
/**
* RevisionDbTestBase contains test cases for the Revision class that have Database interactions.
abstract protected function getMcrTablesToReset();
protected function setUp() {
- global $wgContLang;
-
$this->tablesUsed += $this->getMcrTablesToReset();
parent::setUp();
]
);
- $this->setMwGlobals( 'wgContentHandlerUseDB', $this->getContentHandlerUseDB() );
- $this->setMwGlobals(
- 'wgMultiContentRevisionSchemaMigrationStage',
- $this->getMcrMigrationStage()
- );
-
- MWNamespace::clearCaches();
- // Reset namespace cache
- $wgContLang->resetNamespaces();
+ $this->setMwGlobals( [
+ 'wgMultiContentRevisionSchemaMigrationStage' => $this->getMcrMigrationStage(),
+ 'wgContentHandlerUseDB' => $this->getContentHandlerUseDB(),
+ 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
+ 'wgActorTableSchemaMigrationStage' => MIGRATION_OLD,
+ ] );
$this->overrideMwServices();
}
}
- protected function tearDown() {
- global $wgContLang;
-
- parent::tearDown();
-
- MWNamespace::clearCaches();
- // Reset namespace cache
- $wgContLang->resetNamespaces();
+ /**
+ * @param string $model
+ * @return Title
+ */
+ protected function getMockTitle() {
+ $mock = $this->getMockBuilder( Title::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mock->expects( $this->any() )
+ ->method( 'getNamespace' )
+ ->will( $this->returnValue( $this->getDefaultWikitextNS() ) );
+ $mock->expects( $this->any() )
+ ->method( 'getPrefixedText' )
+ ->will( $this->returnValue( __CLASS__ ) );
+ $mock->expects( $this->any() )
+ ->method( 'getDBkey' )
+ ->will( $this->returnValue( __CLASS__ ) );
+ $mock->expects( $this->any() )
+ ->method( 'getArticleID' )
+ ->will( $this->returnValue( 23 ) );
+
+ return $mock;
}
abstract protected function getContentHandlerUseDB();
*/
public function testNewKnownCurrent() {
// Setup the services
- $this->resetGlobalServices();
+ $this->overrideMwServices();
$cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
$this->setService( 'MainWANObjectCache', $cache );
$db = wfGetDB( DB_MASTER );
Revision::DELETED_TEXT,
Revision::DELETED_TEXT,
[ 'sysop' ],
- Title::newFromText( __METHOD__ ),
+ __METHOD__,
true,
];
yield [
Revision::DELETED_TEXT,
Revision::DELETED_TEXT,
[],
- Title::newFromText( __METHOD__ ),
+ __METHOD__,
false,
];
}
* @covers Revision::userCanBitfield
*/
public function testUserCanBitfield( $bitField, $field, $userGroups, $title, $expected ) {
+ $title = Title::newFromText( $title );
+
$this->setMwGlobals(
'wgGroupPermissions',
[
);
}
+ public function provideGetTextId() {
+ yield [ [], null ];
+
+ $slot = new SlotRecord( (object)[
+ 'slot_revision_id' => 42,
+ 'slot_content_id' => 1,
+ 'content_address' => 'tt:789',
+ 'model_name' => CONTENT_MODEL_WIKITEXT,
+ 'role_name' => 'main',
+ 'slot_origin' => 1,
+ ], new WikitextContent( 'Test' ) );
+
+ $rec = new MutableRevisionRecord( $this->testPage->getTitle() );
+ $rec->setId( 42 );
+ $rec->setSlot( $slot );
+
+ yield [ $rec, 789 ];
+ }
+
+ /**
+ * @dataProvider provideGetTextId
+ * @covers Revision::getTextId()
+ */
+ public function testGetTextId( $spec, $expected ) {
+ $rev = new Revision( $spec, 0, $this->testPage->getTitle() );
+ $this->assertSame( $expected, $rev->getTextId() );
+ }
+
}