<?php
+use MediaWiki\Storage\BlobStoreFactory;
use MediaWiki\Storage\RevisionStore;
use MediaWiki\Storage\SqlBlobStore;
use Wikimedia\Rdbms\IDatabase;
->method( 'getPrefixedText' )
->will( $this->returnValue( 'RevisionTest' ) );
$mock->expects( $this->any() )
- ->method( 'getDBKey' )
+ ->method( 'getDBkey' )
->will( $this->returnValue( 'RevisionTest' ) );
$mock->expects( $this->any() )
->method( 'getArticleID' )
$this->assertNull( $rev->getContent(), 'no content object should be available' );
}
+ /**
+ * @covers Revision::__construct
+ * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
+ */
+ public function testConstructFromArrayWithBadPageId() {
+ MediaWiki\suppressWarnings();
+ $rev = new Revision( [ 'page' => 77777777 ] );
+ $this->assertSame( 77777777, $rev->getPage() );
+ MediaWiki\restoreWarnings();
+ }
+
public function provideConstructFromArray_userSetAsExpected() {
yield 'no user defaults to wgUser' => [
[
) );
// Note override internal service, so RevisionStore uses it as well.
- $this->setService( '_SqlBlobStore', $blobStore );
+ $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
$row = (object)$arrayData;
$rev = new Revision( $row, 0, $this->getMockTitle() );
$assertions( $this, $rev );
}
+ /**
+ * @covers Revision::__construct
+ * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
+ */
+ public function testConstructFromRowWithBadPageId() {
+ MediaWiki\suppressWarnings();
+ $rev = new Revision( (object)[ 'rev_page' => 77777777 ] );
+ $this->assertSame( 77777777, $rev->getPage() );
+ MediaWiki\restoreWarnings();
+ }
+
public function provideGetRevisionText() {
yield 'Generic test' => [
'This is a goat of revision text.',
return $blobStore;
}
+ private function mockBlobStoreFactory( $blobStore ) {
+ /** @var LoadBalancer $lb */
+ $factory = $this->getMockBuilder( BlobStoreFactory::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $factory->expects( $this->any() )
+ ->method( 'newBlobStore' )
+ ->willReturn( $blobStore );
+ $factory->expects( $this->any() )
+ ->method( 'newSqlBlobStore' )
+ ->willReturn( $blobStore );
+ return $factory;
+ }
+
/**
* @return RevisionStore
*/
public function testGetRevisionWithLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
$blobStore = $this->getBlobStore();
$blobStore->setLegacyEncoding( $encoding, Language::factory( $lang ) );
- $this->setService( 'BlobStore', $blobStore );
+ $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
$this->testGetRevisionText( $expected, $rowData );
}
$blobStore = $this->getBlobStore();
$blobStore->setLegacyEncoding( $encoding, Language::factory( $lang ) );
- $this->setService( 'BlobStore', $blobStore );
+ $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
$this->testGetRevisionText( $expected, $rowData );
}
$blobStore = $this->getBlobStore();
$blobStore->setCompressBlobs( true );
- $this->setService( 'BlobStore', $blobStore );
+ $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
$row = new stdClass;
$row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
$blobStore->setLegacyEncoding( $legacyEncoding, Language::factory( 'en' ) );
}
- $this->setService( 'BlobStore', $blobStore );
+ $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
$this->assertSame(
$expected,
Revision::decompressRevisionText( $text, $flags )
->getMock();
$blobStore = new SqlBlobStore( $lb, $cache );
- $this->setService( 'BlobStore', $blobStore );
+ $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
$this->assertSame(
'AAAABBAAA',