X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FRevisionDbTestBase.php;h=8bf87a23e270538ec7abc3eadca215f079e4b052;hb=d4a5e446abe1e529df7cc271f1eded35dbadf423;hp=ff4c198aeca86618af6646b30b2a80fce449a02c;hpb=fd08137ebf8b34cb1a9711c34d6c4d0357aea5b7;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/RevisionDbTestBase.php b/tests/phpunit/includes/RevisionDbTestBase.php index ff4c198aec..cfff088eed 100644 --- a/tests/phpunit/includes/RevisionDbTestBase.php +++ b/tests/phpunit/includes/RevisionDbTestBase.php @@ -1,8 +1,10 @@ setMwGlobals( 'wgContentHandlerUseDB', $this->getContentHandlerUseDB() ); - $this->setMwGlobals( - 'wgMultiContentRevisionSchemaMigrationStage', - $this->getMcrMigrationStage() - ); + $this->setMwGlobals( [ + 'wgMultiContentRevisionSchemaMigrationStage' => $this->getMcrMigrationStage(), + 'wgContentHandlerUseDB' => $this->getContentHandlerUseDB(), + 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW, + 'wgActorTableSchemaMigrationStage' => SCHEMA_COMPAT_OLD, + ] ); $this->overrideMwServices(); @@ -102,6 +105,30 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase { } } + /** + * @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(); private function makeRevisionWithProps( $props = null ) { @@ -232,7 +259,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase { // getTextId() must be an int! $this->assertInternalType( 'integer', $rev->getTextId() ); - $mainSlot = $rev->getRevisionRecord()->getSlot( 'main', RevisionRecord::RAW ); + $mainSlot = $rev->getRevisionRecord()->getSlot( SlotRecord::MAIN, RevisionRecord::RAW ); // we currently only support storage in the text table $textId = MediaWikiServices::getInstance() @@ -1452,14 +1479,14 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase { Revision::DELETED_TEXT, Revision::DELETED_TEXT, [ 'sysop' ], - Title::newFromText( __METHOD__ ), + __METHOD__, true, ]; yield [ Revision::DELETED_TEXT, Revision::DELETED_TEXT, [], - Title::newFromText( __METHOD__ ), + __METHOD__, false, ]; } @@ -1469,6 +1496,8 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase { * @covers Revision::userCanBitfield */ public function testUserCanBitfield( $bitField, $field, $userGroups, $title, $expected ) { + $title = Title::newFromText( $title ); + $this->setMwGlobals( 'wgGroupPermissions', [ @@ -1544,4 +1573,66 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase { ); } + 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' => SlotRecord::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() ); + } + + public function provideGetRevisionText() { + yield [ + [ 'text' ] + ]; + } + + /** + * @dataProvider provideGetRevisionText + * @covers Revision::getRevisionText + */ + public function testGetRevisionText( array $queryInfoOptions, array $queryInfoExtra = [] ) { + $rev = $this->testPage->getRevisionRecord(); + + $queryInfo = Revision::getQueryInfo( $queryInfoOptions ); + $queryInfo['tables'] = array_merge( $queryInfo['tables'], $queryInfoExtra['tables'] ?? [] ); + $queryInfo['fields'] = array_merge( $queryInfo['fields'], $queryInfoExtra['fields'] ?? [] ); + $queryInfo['joins'] = array_merge( $queryInfo['joins'], $queryInfoExtra['joins'] ?? [] ); + + $conds = [ 'rev_id' => $rev->getId() ]; + $row = $this->db->selectRow( + $queryInfo['tables'], + $queryInfo['fields'], + $conds, + __METHOD__, + [], + $queryInfo['joins'] + ); + + $expected = $rev->getContent( SlotRecord::MAIN )->serialize(); + + $this->hideDeprecated( 'Revision::getRevisionText (MCR without SCHEMA_COMPAT_WRITE_OLD)' ); + $this->assertSame( $expected, Revision::getRevisionText( $row ) ); + } + }