2017-11-15 12:02:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
2018-09-20 17:29:04 +00:00
|
|
|
namespace MediaWiki\Tests\Revision;
|
2017-11-15 12:02:40 +00:00
|
|
|
|
2018-01-29 15:54:02 +00:00
|
|
|
use CommentStore;
|
2018-01-12 14:40:47 +00:00
|
|
|
use HashBagOStuff;
|
2018-01-29 15:54:02 +00:00
|
|
|
use InvalidArgumentException;
|
2018-01-12 14:40:47 +00:00
|
|
|
use Language;
|
2018-01-29 14:25:49 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\RevisionAccessException;
|
|
|
|
|
use MediaWiki\Revision\RevisionStore;
|
2018-11-19 11:39:56 +00:00
|
|
|
use MediaWiki\Revision\SlotRoleRegistry;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2017-11-15 12:02:40 +00:00
|
|
|
use MediaWiki\Storage\SqlBlobStore;
|
|
|
|
|
use MediaWikiTestCase;
|
2018-01-29 15:54:02 +00:00
|
|
|
use MWException;
|
2018-01-12 14:40:47 +00:00
|
|
|
use Title;
|
2017-11-15 12:02:40 +00:00
|
|
|
use WANObjectCache;
|
2018-01-11 16:56:29 +00:00
|
|
|
use Wikimedia\Rdbms\Database;
|
2017-11-15 12:02:40 +00:00
|
|
|
use Wikimedia\Rdbms\LoadBalancer;
|
2018-01-29 15:54:02 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
2018-07-04 13:39:24 +00:00
|
|
|
use WikitextContent;
|
2017-11-15 12:02:40 +00:00
|
|
|
|
|
|
|
|
class RevisionStoreTest extends MediaWikiTestCase {
|
|
|
|
|
|
2018-07-04 13:39:24 +00:00
|
|
|
private function useTextId() {
|
|
|
|
|
global $wgMultiContentRevisionSchemaMigrationStage;
|
|
|
|
|
|
|
|
|
|
return (bool)( $wgMultiContentRevisionSchemaMigrationStage & SCHEMA_COMPAT_READ_OLD );
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 12:02:40 +00:00
|
|
|
/**
|
|
|
|
|
* @param LoadBalancer $loadBalancer
|
|
|
|
|
* @param SqlBlobStore $blobStore
|
|
|
|
|
* @param WANObjectCache $WANObjectCache
|
|
|
|
|
*
|
|
|
|
|
* @return RevisionStore
|
|
|
|
|
*/
|
|
|
|
|
private function getRevisionStore(
|
|
|
|
|
$loadBalancer = null,
|
|
|
|
|
$blobStore = null,
|
|
|
|
|
$WANObjectCache = null
|
|
|
|
|
) {
|
2018-01-29 15:54:02 +00:00
|
|
|
global $wgMultiContentRevisionSchemaMigrationStage;
|
|
|
|
|
// the migration stage should be irrelevant, since all the tests that interact with
|
|
|
|
|
// the database are in RevisionStoreDbTest, not here.
|
|
|
|
|
|
2017-11-15 12:02:40 +00:00
|
|
|
return new RevisionStore(
|
2018-06-11 09:16:48 +00:00
|
|
|
$loadBalancer ?: $this->getMockLoadBalancer(),
|
|
|
|
|
$blobStore ?: $this->getMockSqlBlobStore(),
|
|
|
|
|
$WANObjectCache ?: $this->getHashWANObjectCache(),
|
2017-09-12 17:12:29 +00:00
|
|
|
MediaWikiServices::getInstance()->getCommentStore(),
|
2018-01-29 15:54:02 +00:00
|
|
|
MediaWikiServices::getInstance()->getContentModelStore(),
|
|
|
|
|
MediaWikiServices::getInstance()->getSlotRoleStore(),
|
2018-11-19 11:39:56 +00:00
|
|
|
MediaWikiServices::getInstance()->getSlotRoleRegistry(),
|
2018-01-29 15:54:02 +00:00
|
|
|
$wgMultiContentRevisionSchemaMigrationStage,
|
2017-09-12 17:12:29 +00:00
|
|
|
MediaWikiServices::getInstance()->getActorMigration()
|
2017-11-15 12:02:40 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|LoadBalancer
|
|
|
|
|
*/
|
|
|
|
|
private function getMockLoadBalancer() {
|
|
|
|
|
return $this->getMockBuilder( LoadBalancer::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 16:56:29 +00:00
|
|
|
/**
|
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|Database
|
|
|
|
|
*/
|
|
|
|
|
private function getMockDatabase() {
|
|
|
|
|
return $this->getMockBuilder( Database::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 12:02:40 +00:00
|
|
|
/**
|
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|SqlBlobStore
|
|
|
|
|
*/
|
|
|
|
|
private function getMockSqlBlobStore() {
|
|
|
|
|
return $this->getMockBuilder( SqlBlobStore::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-01-29 15:54:02 +00:00
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|CommentStore
|
2017-11-15 12:02:40 +00:00
|
|
|
*/
|
2018-01-29 15:54:02 +00:00
|
|
|
private function getMockCommentStore() {
|
|
|
|
|
return $this->getMockBuilder( CommentStore::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
2017-11-15 12:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
2018-11-19 11:39:56 +00:00
|
|
|
/**
|
|
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|SlotRoleRegistry
|
|
|
|
|
*/
|
|
|
|
|
private function getMockSlotRoleRegistry() {
|
|
|
|
|
return $this->getMockBuilder( SlotRoleRegistry::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 15:54:02 +00:00
|
|
|
private function getHashWANObjectCache() {
|
|
|
|
|
return new WANObjectCache( [ 'cache' => new \HashBagOStuff() ] );
|
2017-09-12 17:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-29 15:54:02 +00:00
|
|
|
public function provideSetContentHandlerUseDB() {
|
2017-11-15 12:02:40 +00:00
|
|
|
return [
|
2018-06-26 17:26:33 +00:00
|
|
|
// ContentHandlerUseDB can be true of false pre migration.
|
|
|
|
|
[ false, SCHEMA_COMPAT_OLD, false ],
|
|
|
|
|
[ true, SCHEMA_COMPAT_OLD, false ],
|
|
|
|
|
// During and after migration it can not be false...
|
|
|
|
|
[ false, SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, true ],
|
|
|
|
|
[ false, SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, true ],
|
|
|
|
|
[ false, SCHEMA_COMPAT_NEW, true ],
|
|
|
|
|
// ...but it can be true.
|
|
|
|
|
[ true, SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, false ],
|
|
|
|
|
[ true, SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, false ],
|
|
|
|
|
[ true, SCHEMA_COMPAT_NEW, false ],
|
2017-11-15 12:02:40 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-01-29 15:54:02 +00:00
|
|
|
* @dataProvider provideSetContentHandlerUseDB
|
2018-09-20 17:29:04 +00:00
|
|
|
* @covers \MediaWiki\Revision\RevisionStore::getContentHandlerUseDB
|
|
|
|
|
* @covers \MediaWiki\Revision\RevisionStore::setContentHandlerUseDB
|
2017-11-15 12:02:40 +00:00
|
|
|
*/
|
2018-01-29 15:54:02 +00:00
|
|
|
public function testSetContentHandlerUseDB( $contentHandlerDb, $migrationMode, $expectedFail ) {
|
|
|
|
|
if ( $expectedFail ) {
|
|
|
|
|
$this->setExpectedException( MWException::class );
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-04 01:59:03 +00:00
|
|
|
$nameTables = MediaWikiServices::getInstance()->getNameTableStoreFactory();
|
|
|
|
|
|
2018-01-29 15:54:02 +00:00
|
|
|
$store = new RevisionStore(
|
|
|
|
|
$this->getMockLoadBalancer(),
|
|
|
|
|
$this->getMockSqlBlobStore(),
|
|
|
|
|
$this->getHashWANObjectCache(),
|
|
|
|
|
$this->getMockCommentStore(),
|
2018-09-04 01:59:03 +00:00
|
|
|
$nameTables->getContentModels(),
|
|
|
|
|
$nameTables->getSlotRoles(),
|
2018-11-19 11:39:56 +00:00
|
|
|
$this->getMockSlotRoleRegistry(),
|
2018-01-29 15:54:02 +00:00
|
|
|
$migrationMode,
|
|
|
|
|
MediaWikiServices::getInstance()->getActorMigration()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$store->setContentHandlerUseDB( $contentHandlerDb );
|
|
|
|
|
$this->assertSame( $contentHandlerDb, $store->getContentHandlerUseDB() );
|
2017-11-15 12:02:40 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-11 16:56:29 +00:00
|
|
|
public function testGetTitle_successFromPageId() {
|
|
|
|
|
$mockLoadBalancer = $this->getMockLoadBalancer();
|
|
|
|
|
// Title calls wfGetDB() so we have to set the main service
|
|
|
|
|
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
|
|
|
|
|
|
|
|
|
|
$db = $this->getMockDatabase();
|
|
|
|
|
// Title calls wfGetDB() which uses a regular Connection
|
|
|
|
|
$mockLoadBalancer->expects( $this->atLeastOnce() )
|
|
|
|
|
->method( 'getConnection' )
|
|
|
|
|
->willReturn( $db );
|
|
|
|
|
|
|
|
|
|
// First call to Title::newFromID, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 0 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( (object)[
|
|
|
|
|
'page_namespace' => '1',
|
|
|
|
|
'page_title' => 'Food',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$store = $this->getRevisionStore( $mockLoadBalancer );
|
|
|
|
|
$title = $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( 1, $title->getNamespace() );
|
|
|
|
|
$this->assertSame( 'Food', $title->getDBkey() );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 16:05:46 +00:00
|
|
|
public function testGetTitle_successFromPageIdOnFallback() {
|
|
|
|
|
$mockLoadBalancer = $this->getMockLoadBalancer();
|
|
|
|
|
// Title calls wfGetDB() so we have to set the main service
|
|
|
|
|
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
|
|
|
|
|
|
|
|
|
|
$db = $this->getMockDatabase();
|
|
|
|
|
// Title calls wfGetDB() which uses a regular Connection
|
|
|
|
|
// Assert that the first call uses a REPLICA and the second falls back to master
|
|
|
|
|
$mockLoadBalancer->expects( $this->exactly( 2 ) )
|
|
|
|
|
->method( 'getConnection' )
|
|
|
|
|
->willReturn( $db );
|
|
|
|
|
// RevisionStore getTitle uses a ConnectionRef
|
|
|
|
|
$mockLoadBalancer->expects( $this->atLeastOnce() )
|
|
|
|
|
->method( 'getConnectionRef' )
|
|
|
|
|
->willReturn( $db );
|
|
|
|
|
|
|
|
|
|
// First call to Title::newFromID, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 0 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
|
|
// First select using rev_id, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 1 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
[ 'revision', 'page' ],
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'rev_id' => 2 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
|
|
// Second call to Title::newFromID, no result
|
|
|
|
|
$db->expects( $this->at( 2 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( (object)[
|
|
|
|
|
'page_namespace' => '2',
|
|
|
|
|
'page_title' => 'Foodey',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$store = $this->getRevisionStore( $mockLoadBalancer );
|
|
|
|
|
$title = $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( 2, $title->getNamespace() );
|
|
|
|
|
$this->assertSame( 'Foodey', $title->getDBkey() );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 16:56:29 +00:00
|
|
|
public function testGetTitle_successFromRevId() {
|
|
|
|
|
$mockLoadBalancer = $this->getMockLoadBalancer();
|
|
|
|
|
// Title calls wfGetDB() so we have to set the main service
|
|
|
|
|
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
|
|
|
|
|
|
|
|
|
|
$db = $this->getMockDatabase();
|
|
|
|
|
// Title calls wfGetDB() which uses a regular Connection
|
|
|
|
|
$mockLoadBalancer->expects( $this->atLeastOnce() )
|
|
|
|
|
->method( 'getConnection' )
|
|
|
|
|
->willReturn( $db );
|
|
|
|
|
// RevisionStore getTitle uses a ConnectionRef
|
|
|
|
|
$mockLoadBalancer->expects( $this->atLeastOnce() )
|
|
|
|
|
->method( 'getConnectionRef' )
|
|
|
|
|
->willReturn( $db );
|
|
|
|
|
|
|
|
|
|
// First call to Title::newFromID, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 0 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
|
|
// First select using rev_id, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 1 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
[ 'revision', 'page' ],
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'rev_id' => 2 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( (object)[
|
|
|
|
|
'page_namespace' => '1',
|
|
|
|
|
'page_title' => 'Food2',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$store = $this->getRevisionStore( $mockLoadBalancer );
|
|
|
|
|
$title = $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( 1, $title->getNamespace() );
|
|
|
|
|
$this->assertSame( 'Food2', $title->getDBkey() );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 16:05:46 +00:00
|
|
|
public function testGetTitle_successFromRevIdOnFallback() {
|
2018-01-11 16:56:29 +00:00
|
|
|
$mockLoadBalancer = $this->getMockLoadBalancer();
|
|
|
|
|
// Title calls wfGetDB() so we have to set the main service
|
|
|
|
|
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
|
|
|
|
|
|
|
|
|
|
$db = $this->getMockDatabase();
|
|
|
|
|
// Title calls wfGetDB() which uses a regular Connection
|
2018-01-10 16:05:46 +00:00
|
|
|
// Assert that the first call uses a REPLICA and the second falls back to master
|
|
|
|
|
$mockLoadBalancer->expects( $this->exactly( 2 ) )
|
2018-01-11 16:56:29 +00:00
|
|
|
->method( 'getConnection' )
|
|
|
|
|
->willReturn( $db );
|
|
|
|
|
// RevisionStore getTitle uses a ConnectionRef
|
|
|
|
|
$mockLoadBalancer->expects( $this->atLeastOnce() )
|
|
|
|
|
->method( 'getConnectionRef' )
|
|
|
|
|
->willReturn( $db );
|
|
|
|
|
|
|
|
|
|
// First call to Title::newFromID, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 0 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
|
|
// First select using rev_id, faking no result (db lag?)
|
|
|
|
|
$db->expects( $this->at( 1 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
[ 'revision', 'page' ],
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'rev_id' => 2 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
2018-01-10 16:05:46 +00:00
|
|
|
// Second call to Title::newFromID, no result
|
|
|
|
|
$db->expects( $this->at( 2 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
|
|
|
|
|
// Second select using rev_id, result
|
|
|
|
|
$db->expects( $this->at( 3 ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
[ 'revision', 'page' ],
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'rev_id' => 2 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( (object)[
|
|
|
|
|
'page_namespace' => '2',
|
|
|
|
|
'page_title' => 'Foodey',
|
|
|
|
|
] );
|
|
|
|
|
|
|
|
|
|
$store = $this->getRevisionStore( $mockLoadBalancer );
|
|
|
|
|
$title = $store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
|
|
|
|
|
|
|
|
|
|
$this->assertSame( 2, $title->getNamespace() );
|
|
|
|
|
$this->assertSame( 'Foodey', $title->getDBkey() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-09-20 17:29:04 +00:00
|
|
|
* @covers \MediaWiki\Revision\RevisionStore::getTitle
|
2018-01-10 16:05:46 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetTitle_correctFallbackAndthrowsExceptionAfterFallbacks() {
|
|
|
|
|
$mockLoadBalancer = $this->getMockLoadBalancer();
|
|
|
|
|
// Title calls wfGetDB() so we have to set the main service
|
|
|
|
|
$this->setService( 'DBLoadBalancer', $mockLoadBalancer );
|
|
|
|
|
|
|
|
|
|
$db = $this->getMockDatabase();
|
|
|
|
|
// Title calls wfGetDB() which uses a regular Connection
|
|
|
|
|
// Assert that the first call uses a REPLICA and the second falls back to master
|
|
|
|
|
|
|
|
|
|
// RevisionStore getTitle uses getConnectionRef
|
|
|
|
|
// Title::newFromID uses getConnection
|
|
|
|
|
foreach ( [ 'getConnection', 'getConnectionRef' ] as $method ) {
|
|
|
|
|
$mockLoadBalancer->expects( $this->exactly( 2 ) )
|
|
|
|
|
->method( $method )
|
|
|
|
|
->willReturnCallback( function ( $masterOrReplica ) use ( $db ) {
|
|
|
|
|
static $callCounter = 0;
|
|
|
|
|
$callCounter++;
|
|
|
|
|
// The first call should be to a REPLICA, and the second a MASTER.
|
|
|
|
|
if ( $callCounter === 1 ) {
|
|
|
|
|
$this->assertSame( DB_REPLICA, $masterOrReplica );
|
|
|
|
|
} elseif ( $callCounter === 2 ) {
|
|
|
|
|
$this->assertSame( DB_MASTER, $masterOrReplica );
|
|
|
|
|
}
|
|
|
|
|
return $db;
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
// First and third call to Title::newFromID, faking no result
|
|
|
|
|
foreach ( [ 0, 2 ] as $counter ) {
|
|
|
|
|
$db->expects( $this->at( $counter ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
'page',
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'page_id' => 1 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( [ 1, 3 ] as $counter ) {
|
|
|
|
|
$db->expects( $this->at( $counter ) )
|
|
|
|
|
->method( 'selectRow' )
|
|
|
|
|
->with(
|
|
|
|
|
[ 'revision', 'page' ],
|
|
|
|
|
$this->anything(),
|
|
|
|
|
[ 'rev_id' => 2 ]
|
|
|
|
|
)
|
|
|
|
|
->willReturn( false );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-11 16:56:29 +00:00
|
|
|
$store = $this->getRevisionStore( $mockLoadBalancer );
|
|
|
|
|
|
|
|
|
|
$this->setExpectedException( RevisionAccessException::class );
|
|
|
|
|
$store->getTitle( 1, 2, RevisionStore::READ_NORMAL );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-12 14:40:47 +00:00
|
|
|
public function provideNewRevisionFromRow_legacyEncoding_applied() {
|
|
|
|
|
yield 'windows-1252, old_flags is empty' => [
|
|
|
|
|
'windows-1252',
|
|
|
|
|
'en',
|
|
|
|
|
[
|
|
|
|
|
'old_flags' => '',
|
|
|
|
|
'old_text' => "S\xF6me Content",
|
|
|
|
|
],
|
|
|
|
|
'Söme Content'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'windows-1252, old_flags is null' => [
|
|
|
|
|
'windows-1252',
|
|
|
|
|
'en',
|
|
|
|
|
[
|
|
|
|
|
'old_flags' => null,
|
|
|
|
|
'old_text' => "S\xF6me Content",
|
|
|
|
|
],
|
|
|
|
|
'Söme Content'
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideNewRevisionFromRow_legacyEncoding_applied
|
|
|
|
|
*
|
2018-09-20 17:29:04 +00:00
|
|
|
* @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRow
|
2018-01-12 14:40:47 +00:00
|
|
|
*/
|
|
|
|
|
public function testNewRevisionFromRow_legacyEncoding_applied( $encoding, $locale, $row, $text ) {
|
2018-07-04 13:39:24 +00:00
|
|
|
if ( !$this->useTextId() ) {
|
|
|
|
|
$this->markTestSkipped( 'No longer applicable with MCR schema' );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-12 14:40:47 +00:00
|
|
|
$cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
|
2018-05-02 20:12:12 +00:00
|
|
|
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
2018-01-12 14:40:47 +00:00
|
|
|
|
2018-05-02 20:12:12 +00:00
|
|
|
$blobStore = new SqlBlobStore( $lb, $cache );
|
2018-01-12 14:40:47 +00:00
|
|
|
$blobStore->setLegacyEncoding( $encoding, Language::factory( $locale ) );
|
|
|
|
|
|
2018-05-02 20:12:12 +00:00
|
|
|
$store = $this->getRevisionStore( $lb, $blobStore, $cache );
|
2018-01-12 14:40:47 +00:00
|
|
|
|
|
|
|
|
$record = $store->newRevisionFromRow(
|
|
|
|
|
$this->makeRow( $row ),
|
|
|
|
|
0,
|
|
|
|
|
Title::newFromText( __METHOD__ . '-UTPage' )
|
|
|
|
|
);
|
|
|
|
|
|
2018-09-24 21:10:08 +00:00
|
|
|
$this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
|
2018-01-12 14:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-09-20 17:29:04 +00:00
|
|
|
* @covers \MediaWiki\Revision\RevisionStore::newRevisionFromRow
|
2018-01-12 14:40:47 +00:00
|
|
|
*/
|
|
|
|
|
public function testNewRevisionFromRow_legacyEncoding_ignored() {
|
2018-07-04 13:39:24 +00:00
|
|
|
if ( !$this->useTextId() ) {
|
|
|
|
|
$this->markTestSkipped( 'No longer applicable with MCR schema' );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-12 14:40:47 +00:00
|
|
|
$row = [
|
|
|
|
|
'old_flags' => 'utf-8',
|
|
|
|
|
'old_text' => 'Söme Content',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
|
2018-05-02 20:12:12 +00:00
|
|
|
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
2018-01-12 14:40:47 +00:00
|
|
|
|
2018-05-02 20:12:12 +00:00
|
|
|
$blobStore = new SqlBlobStore( $lb, $cache );
|
2018-01-12 14:40:47 +00:00
|
|
|
$blobStore->setLegacyEncoding( 'windows-1252', Language::factory( 'en' ) );
|
|
|
|
|
|
2018-05-02 20:12:12 +00:00
|
|
|
$store = $this->getRevisionStore( $lb, $blobStore, $cache );
|
2018-01-12 14:40:47 +00:00
|
|
|
|
|
|
|
|
$record = $store->newRevisionFromRow(
|
|
|
|
|
$this->makeRow( $row ),
|
|
|
|
|
0,
|
|
|
|
|
Title::newFromText( __METHOD__ . '-UTPage' )
|
|
|
|
|
);
|
2018-09-24 21:10:08 +00:00
|
|
|
$this->assertSame( 'Söme Content', $record->getContent( SlotRecord::MAIN )->serialize() );
|
2018-01-12 14:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function makeRow( array $array ) {
|
|
|
|
|
$row = $array + [
|
|
|
|
|
'rev_id' => 7,
|
|
|
|
|
'rev_page' => 5,
|
|
|
|
|
'rev_timestamp' => '20110101000000',
|
|
|
|
|
'rev_user_text' => 'Tester',
|
|
|
|
|
'rev_user' => 17,
|
|
|
|
|
'rev_minor_edit' => 0,
|
|
|
|
|
'rev_deleted' => 0,
|
|
|
|
|
'rev_len' => 100,
|
|
|
|
|
'rev_parent_id' => 0,
|
|
|
|
|
'rev_sha1' => 'deadbeef',
|
|
|
|
|
'rev_comment_text' => 'Testing',
|
|
|
|
|
'rev_comment_data' => '{}',
|
|
|
|
|
'rev_comment_cid' => 111,
|
|
|
|
|
'page_namespace' => 0,
|
|
|
|
|
'page_title' => 'TEST',
|
|
|
|
|
'page_id' => 5,
|
|
|
|
|
'page_latest' => 7,
|
|
|
|
|
'page_is_redirect' => 0,
|
|
|
|
|
'page_len' => 100,
|
|
|
|
|
'user_name' => 'Tester',
|
2018-07-04 13:39:24 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if ( $this->useTextId() ) {
|
|
|
|
|
$row += [
|
|
|
|
|
'rev_content_format' => CONTENT_FORMAT_TEXT,
|
|
|
|
|
'rev_content_model' => CONTENT_MODEL_TEXT,
|
|
|
|
|
'rev_text_id' => 11,
|
|
|
|
|
'old_id' => 11,
|
2018-01-12 14:40:47 +00:00
|
|
|
'old_text' => 'Hello World',
|
|
|
|
|
'old_flags' => 'utf-8',
|
|
|
|
|
];
|
2018-07-04 13:39:24 +00:00
|
|
|
} else {
|
|
|
|
|
if ( !isset( $row['content'] ) && isset( $array['old_text'] ) ) {
|
|
|
|
|
$row['content'] = [
|
|
|
|
|
'main' => new WikitextContent( $array['old_text'] ),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-12 14:40:47 +00:00
|
|
|
|
|
|
|
|
return (object)$row;
|
|
|
|
|
}
|
2017-12-27 15:46:03 +00:00
|
|
|
|
2018-01-29 15:54:02 +00:00
|
|
|
public function provideMigrationConstruction() {
|
|
|
|
|
return [
|
2018-06-26 17:26:33 +00:00
|
|
|
[ SCHEMA_COMPAT_OLD, false ],
|
|
|
|
|
[ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, false ],
|
|
|
|
|
[ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, false ],
|
|
|
|
|
[ SCHEMA_COMPAT_NEW, false ],
|
|
|
|
|
[ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_BOTH, true ],
|
|
|
|
|
[ SCHEMA_COMPAT_WRITE_OLD | SCHEMA_COMPAT_READ_BOTH, true ],
|
|
|
|
|
[ SCHEMA_COMPAT_WRITE_NEW | SCHEMA_COMPAT_READ_BOTH, true ],
|
2018-01-29 15:54:02 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-09-20 17:29:04 +00:00
|
|
|
* @covers \MediaWiki\Revision\RevisionStore::__construct
|
2018-01-29 15:54:02 +00:00
|
|
|
* @dataProvider provideMigrationConstruction
|
|
|
|
|
*/
|
|
|
|
|
public function testMigrationConstruction( $migration, $expectException ) {
|
|
|
|
|
if ( $expectException ) {
|
|
|
|
|
$this->setExpectedException( InvalidArgumentException::class );
|
|
|
|
|
}
|
|
|
|
|
$loadBalancer = $this->getMockLoadBalancer();
|
|
|
|
|
$blobStore = $this->getMockSqlBlobStore();
|
|
|
|
|
$cache = $this->getHashWANObjectCache();
|
|
|
|
|
$commentStore = $this->getMockCommentStore();
|
2018-09-04 01:59:03 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$nameTables = $services->getNameTableStoreFactory();
|
|
|
|
|
$contentModelStore = $nameTables->getContentModels();
|
|
|
|
|
$slotRoleStore = $nameTables->getSlotRoles();
|
2018-11-19 11:39:56 +00:00
|
|
|
$slotRoleRegistry = $services->getSlotRoleRegistry();
|
2018-01-29 15:54:02 +00:00
|
|
|
$store = new RevisionStore(
|
|
|
|
|
$loadBalancer,
|
|
|
|
|
$blobStore,
|
|
|
|
|
$cache,
|
|
|
|
|
$commentStore,
|
2018-09-04 01:59:03 +00:00
|
|
|
$nameTables->getContentModels(),
|
|
|
|
|
$nameTables->getSlotRoles(),
|
2018-11-19 11:39:56 +00:00
|
|
|
$slotRoleRegistry,
|
2018-01-29 15:54:02 +00:00
|
|
|
$migration,
|
2018-09-04 01:59:03 +00:00
|
|
|
$services->getActorMigration()
|
2018-01-29 15:54:02 +00:00
|
|
|
);
|
|
|
|
|
if ( !$expectException ) {
|
|
|
|
|
$store = TestingAccessWrapper::newFromObject( $store );
|
|
|
|
|
$this->assertSame( $loadBalancer, $store->loadBalancer );
|
|
|
|
|
$this->assertSame( $blobStore, $store->blobStore );
|
|
|
|
|
$this->assertSame( $cache, $store->cache );
|
|
|
|
|
$this->assertSame( $commentStore, $store->commentStore );
|
|
|
|
|
$this->assertSame( $contentModelStore, $store->contentModelStore );
|
|
|
|
|
$this->assertSame( $slotRoleStore, $store->slotRoleStore );
|
|
|
|
|
$this->assertSame( $migration, $store->mcrMigrationStage );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 12:02:40 +00:00
|
|
|
}
|