3 use MediaWiki\Storage\BlobStoreFactory
;
4 use MediaWiki\Storage\RevisionStore
;
5 use MediaWiki\Storage\SqlBlobStore
;
6 use Wikimedia\Rdbms\IDatabase
;
7 use Wikimedia\Rdbms\LoadBalancer
;
10 * Test cases in RevisionTest should not interact with the Database.
11 * For test cases that need Database interaction see RevisionDbTestBase.
13 class RevisionTest
extends MediaWikiTestCase
{
15 public function provideConstructFromArray() {
16 yield
'with text' => [
18 'text' => 'hello world.',
19 'content_model' => CONTENT_MODEL_JAVASCRIPT
22 yield
'with content' => [
24 'content' => new JavaScriptContent( 'hellow world.' )
27 // FIXME: test with and without user ID, and with a user object.
28 // We can't prepare that here though, since we don't yet have a dummy DB
32 * @param string $model
35 public function getMockTitle( $model = CONTENT_MODEL_WIKITEXT
) {
36 $mock = $this->getMockBuilder( Title
::class )
37 ->disableOriginalConstructor()
39 $mock->expects( $this->any() )
40 ->method( 'getNamespace' )
41 ->will( $this->returnValue( $this->getDefaultWikitextNS() ) );
42 $mock->expects( $this->any() )
43 ->method( 'getPrefixedText' )
44 ->will( $this->returnValue( 'RevisionTest' ) );
45 $mock->expects( $this->any() )
46 ->method( 'getDBKey' )
47 ->will( $this->returnValue( 'RevisionTest' ) );
48 $mock->expects( $this->any() )
49 ->method( 'getArticleID' )
50 ->will( $this->returnValue( 23 ) );
51 $mock->expects( $this->any() )
52 ->method( 'getModel' )
53 ->will( $this->returnValue( $model ) );
59 * @dataProvider provideConstructFromArray
60 * @covers Revision::__construct
61 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
63 public function testConstructFromArray( $rowArray ) {
64 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
65 $this->assertNotNull( $rev->getContent(), 'no content object available' );
66 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $rev->getContent()->getModel() );
67 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $rev->getContentModel() );
71 * @covers Revision::__construct
72 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
74 public function testConstructFromEmptyArray() {
75 $rev = new Revision( [], 0, $this->getMockTitle() );
76 $this->assertNull( $rev->getContent(), 'no content object should be available' );
79 public function provideConstructFromArray_userSetAsExpected() {
80 yield
'no user defaults to wgUser' => [
82 'content' => new JavaScriptContent( 'hello world.' ),
87 yield
'user text and id' => [
89 'content' => new JavaScriptContent( 'hello world.' ),
90 'user_text' => 'SomeTextUserName',
97 yield
'user text only' => [
99 'content' => new JavaScriptContent( 'hello world.' ),
100 'user_text' => '111.111.111.111',
108 * @dataProvider provideConstructFromArray_userSetAsExpected
109 * @covers Revision::__construct
110 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
112 * @param array $rowArray
113 * @param mixed $expectedUserId null to expect the current wgUser ID
114 * @param mixed $expectedUserName null to expect the current wgUser name
116 public function testConstructFromArray_userSetAsExpected(
121 $testUser = $this->getTestUser()->getUser();
122 $this->setMwGlobals( 'wgUser', $testUser );
123 if ( $expectedUserId === null ) {
124 $expectedUserId = $testUser->getId();
126 if ( $expectedUserName === null ) {
127 $expectedUserName = $testUser->getName();
130 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
131 $this->assertEquals( $expectedUserId, $rev->getUser() );
132 $this->assertEquals( $expectedUserName, $rev->getUserText() );
135 public function provideConstructFromArrayThrowsExceptions() {
136 yield
'content and text_id both not empty' => [
138 'content' => new WikitextContent( 'GOAT' ),
139 'text_id' => 'someid',
141 new MWException( "Text already stored in external store (id someid), " .
142 "can't serialize content object" )
144 yield
'unknown user id and no user name' => [
146 'content' => new JavaScriptContent( 'hello world.' ),
149 new MWException( 'user_text not given, and unknown user ID 9989' )
151 yield
'with bad content object (class)' => [
152 [ 'content' => new stdClass() ],
153 new MWException( 'content field must contain a Content object.' )
155 yield
'with bad content object (string)' => [
156 [ 'content' => 'ImAGoat' ],
157 new MWException( 'content field must contain a Content object.' )
159 yield
'bad row format' => [
160 'imastring, not a row',
161 new InvalidArgumentException(
162 '$row must be a row object, an associative array, or a RevisionRecord'
168 * @dataProvider provideConstructFromArrayThrowsExceptions
169 * @covers Revision::__construct
170 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
172 public function testConstructFromArrayThrowsExceptions( $rowArray, Exception
$expectedException ) {
173 $this->setExpectedException(
174 get_class( $expectedException ),
175 $expectedException->getMessage(),
176 $expectedException->getCode()
178 new Revision( $rowArray, 0, $this->getMockTitle() );
182 * @covers Revision::__construct
183 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
185 public function testConstructFromNothing() {
186 $this->setExpectedException(
187 InvalidArgumentException
::class
192 public function provideConstructFromRow() {
193 yield
'Full construction' => [
197 'rev_text_id' => '2',
198 'rev_timestamp' => '20171017114835',
199 'rev_user_text' => '127.0.0.1',
201 'rev_minor_edit' => '0',
202 'rev_deleted' => '0',
204 'rev_parent_id' => '1',
205 'rev_sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
206 'rev_comment_text' => 'Goat Comment!',
207 'rev_comment_data' => null,
208 'rev_comment_cid' => null,
209 'rev_content_format' => 'GOATFORMAT',
210 'rev_content_model' => 'GOATMODEL',
212 function ( RevisionTest
$testCase, Revision
$rev ) {
213 $testCase->assertSame( 42, $rev->getId() );
214 $testCase->assertSame( 23, $rev->getPage() );
215 $testCase->assertSame( 2, $rev->getTextId() );
216 $testCase->assertSame( '20171017114835', $rev->getTimestamp() );
217 $testCase->assertSame( '127.0.0.1', $rev->getUserText() );
218 $testCase->assertSame( 0, $rev->getUser() );
219 $testCase->assertSame( false, $rev->isMinor() );
220 $testCase->assertSame( false, $rev->isDeleted( Revision
::DELETED_TEXT
) );
221 $testCase->assertSame( 46, $rev->getSize() );
222 $testCase->assertSame( 1, $rev->getParentId() );
223 $testCase->assertSame( 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z', $rev->getSha1() );
224 $testCase->assertSame( 'Goat Comment!', $rev->getComment() );
225 $testCase->assertSame( 'GOATFORMAT', $rev->getContentFormat() );
226 $testCase->assertSame( 'GOATMODEL', $rev->getContentModel() );
229 yield
'default field values' => [
233 'rev_text_id' => '2',
234 'rev_timestamp' => '20171017114835',
235 'rev_user_text' => '127.0.0.1',
237 'rev_minor_edit' => '0',
238 'rev_deleted' => '0',
239 'rev_comment_text' => 'Goat Comment!',
240 'rev_comment_data' => null,
241 'rev_comment_cid' => null,
243 function ( RevisionTest
$testCase, Revision
$rev ) {
244 // parent ID may be null
245 $testCase->assertSame( null, $rev->getParentId(), 'revision id' );
248 $testCase->assertSame( $rev->getTimestamp(), '20171017114835', 'timestamp' );
249 $testCase->assertSame( $rev->getUserText(), '127.0.0.1', 'user name' );
250 $testCase->assertSame( $rev->getUser(), 0, 'user id' );
251 $testCase->assertSame( $rev->getComment(), 'Goat Comment!' );
252 $testCase->assertSame( false, $rev->isMinor(), 'minor edit' );
253 $testCase->assertSame( 0, $rev->getVisibility(), 'visibility flags' );
256 $testCase->assertNotNull( $rev->getSize(), 'size' );
257 $testCase->assertNotNull( $rev->getSha1(), 'hash' );
259 // NOTE: model and format will be detected based on the namespace of the (mock) title
260 $testCase->assertSame( 'text/x-wiki', $rev->getContentFormat(), 'format' );
261 $testCase->assertSame( 'wikitext', $rev->getContentModel(), 'model' );
267 * @dataProvider provideConstructFromRow
268 * @covers Revision::__construct
269 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
271 public function testConstructFromRow( array $arrayData, $assertions ) {
272 $data = 'Hello goat.'; // needs to match model and format
274 $blobStore = $this->getMockBuilder( SqlBlobStore
::class )
275 ->disableOriginalConstructor()
278 $blobStore->method( 'getBlob' )
279 ->will( $this->returnValue( $data ) );
281 $blobStore->method( 'getTextIdFromAddress' )
282 ->will( $this->returnCallback(
283 function ( $address ) {
284 // Turn "tt:1234" into 12345.
285 // Note that this must be functional so we can test getTextId().
286 // Ideally, we'd un-mock getTextIdFromAddress and use its actual implementation.
287 $parts = explode( ':', $address );
288 return (int)array_pop( $parts );
292 // Note override internal service, so RevisionStore uses it as well.
293 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
295 $row = (object)$arrayData;
296 $rev = new Revision( $row, 0, $this->getMockTitle() );
297 $assertions( $this, $rev );
300 public function provideGetRevisionText() {
301 yield
'Generic test' => [
302 'This is a goat of revision text.',
305 'old_text' => 'This is a goat of revision text.',
310 public function provideGetId() {
322 * @dataProvider provideGetId
323 * @covers Revision::getId
325 public function testGetId( $rowArray, $expectedId ) {
326 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
327 $this->assertEquals( $expectedId, $rev->getId() );
330 public function provideSetId() {
331 yield
[ '123', 123 ];
336 * @dataProvider provideSetId
337 * @covers Revision::setId
339 public function testSetId( $input, $expected ) {
340 $rev = new Revision( [], 0, $this->getMockTitle() );
341 $rev->setId( $input );
342 $this->assertSame( $expected, $rev->getId() );
345 public function provideSetUserIdAndName() {
346 yield
[ '123', 123, 'GOaT' ];
347 yield
[ 456, 456, 'GOaT' ];
351 * @dataProvider provideSetUserIdAndName
352 * @covers Revision::setUserIdAndName
354 public function testSetUserIdAndName( $inputId, $expectedId, $name ) {
355 $rev = new Revision( [], 0, $this->getMockTitle() );
356 $rev->setUserIdAndName( $inputId, $name );
357 $this->assertSame( $expectedId, $rev->getUser( Revision
::RAW
) );
358 $this->assertEquals( $name, $rev->getUserText( Revision
::RAW
) );
361 public function provideGetTextId() {
363 yield
[ [ 'text_id' => '123' ], 123 ];
364 yield
[ [ 'text_id' => 456 ], 456 ];
368 * @dataProvider provideGetTextId
369 * @covers Revision::getTextId()
371 public function testGetTextId( $rowArray, $expected ) {
372 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
373 $this->assertSame( $expected, $rev->getTextId() );
376 public function provideGetParentId() {
378 yield
[ [ 'parent_id' => '123' ], 123 ];
379 yield
[ [ 'parent_id' => 456 ], 456 ];
383 * @dataProvider provideGetParentId
384 * @covers Revision::getParentId()
386 public function testGetParentId( $rowArray, $expected ) {
387 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
388 $this->assertSame( $expected, $rev->getParentId() );
392 * @covers Revision::getRevisionText
393 * @dataProvider provideGetRevisionText
395 public function testGetRevisionText( $expected, $rowData, $prefix = 'old_', $wiki = false ) {
398 Revision
::getRevisionText( (object)$rowData, $prefix, $wiki ) );
401 public function provideGetRevisionTextWithZlibExtension() {
402 yield
'Generic gzip test' => [
403 'This is a small goat of revision text.',
405 'old_flags' => 'gzip',
406 'old_text' => gzdeflate( 'This is a small goat of revision text.' ),
412 * @covers Revision::getRevisionText
413 * @dataProvider provideGetRevisionTextWithZlibExtension
415 public function testGetRevisionWithZlibExtension( $expected, $rowData ) {
416 $this->checkPHPExtension( 'zlib' );
417 $this->testGetRevisionText( $expected, $rowData );
420 private function getWANObjectCache() {
421 return new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
425 * @return SqlBlobStore
427 private function getBlobStore() {
428 /** @var LoadBalancer $lb */
429 $lb = $this->getMockBuilder( LoadBalancer
::class )
430 ->disableOriginalConstructor()
433 $cache = $this->getWANObjectCache();
435 $blobStore = new SqlBlobStore( $lb, $cache );
439 private function mockBlobStoreFactory( $blobStore ) {
440 /** @var LoadBalancer $lb */
441 $factory = $this->getMockBuilder( BlobStoreFactory
::class )
442 ->disableOriginalConstructor()
444 $factory->expects( $this->any() )
445 ->method( 'newBlobStore' )
446 ->willReturn( $blobStore );
447 $factory->expects( $this->any() )
448 ->method( 'newSqlBlobStore' )
449 ->willReturn( $blobStore );
454 * @return RevisionStore
456 private function getRevisionStore() {
457 /** @var LoadBalancer $lb */
458 $lb = $this->getMockBuilder( LoadBalancer
::class )
459 ->disableOriginalConstructor()
462 $cache = $this->getWANObjectCache();
464 $blobStore = new RevisionStore( $lb, $this->getBlobStore(), $cache );
468 public function provideGetRevisionTextWithLegacyEncoding() {
469 yield
'Utf8Native' => [
470 "Wiki est l'\xc3\xa9cole superieur !",
474 'old_flags' => 'utf-8',
475 'old_text' => "Wiki est l'\xc3\xa9cole superieur !",
478 yield
'Utf8Legacy' => [
479 "Wiki est l'\xc3\xa9cole superieur !",
484 'old_text' => "Wiki est l'\xe9cole superieur !",
490 * @covers Revision::getRevisionText
491 * @dataProvider provideGetRevisionTextWithLegacyEncoding
493 public function testGetRevisionWithLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
494 $blobStore = $this->getBlobStore();
495 $blobStore->setLegacyEncoding( $encoding, Language
::factory( $lang ) );
496 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
498 $this->testGetRevisionText( $expected, $rowData );
501 public function provideGetRevisionTextWithGzipAndLegacyEncoding() {
504 * Do not set the external flag!
505 * Otherwise, getRevisionText will hit the live database (if ExternalStore is enabled)!
507 yield
'Utf8NativeGzip' => [
508 "Wiki est l'\xc3\xa9cole superieur !",
512 'old_flags' => 'gzip,utf-8',
513 'old_text' => gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" ),
516 yield
'Utf8LegacyGzip' => [
517 "Wiki est l'\xc3\xa9cole superieur !",
521 'old_flags' => 'gzip',
522 'old_text' => gzdeflate( "Wiki est l'\xe9cole superieur !" ),
528 * @covers Revision::getRevisionText
529 * @dataProvider provideGetRevisionTextWithGzipAndLegacyEncoding
531 public function testGetRevisionWithGzipAndLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
532 $this->checkPHPExtension( 'zlib' );
534 $blobStore = $this->getBlobStore();
535 $blobStore->setLegacyEncoding( $encoding, Language
::factory( $lang ) );
536 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
538 $this->testGetRevisionText( $expected, $rowData );
542 * @covers Revision::compressRevisionText
544 public function testCompressRevisionTextUtf8() {
546 $row->old_text
= "Wiki est l'\xc3\xa9cole superieur !";
547 $row->old_flags
= Revision
::compressRevisionText( $row->old_text
);
548 $this->assertTrue( false !== strpos( $row->old_flags
, 'utf-8' ),
549 "Flags should contain 'utf-8'" );
550 $this->assertFalse( false !== strpos( $row->old_flags
, 'gzip' ),
551 "Flags should not contain 'gzip'" );
552 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
553 $row->old_text
, "Direct check" );
554 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
555 Revision
::getRevisionText( $row ), "getRevisionText" );
559 * @covers Revision::compressRevisionText
561 public function testCompressRevisionTextUtf8Gzip() {
562 $this->checkPHPExtension( 'zlib' );
564 $blobStore = $this->getBlobStore();
565 $blobStore->setCompressBlobs( true );
566 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
569 $row->old_text
= "Wiki est l'\xc3\xa9cole superieur !";
570 $row->old_flags
= Revision
::compressRevisionText( $row->old_text
);
571 $this->assertTrue( false !== strpos( $row->old_flags
, 'utf-8' ),
572 "Flags should contain 'utf-8'" );
573 $this->assertTrue( false !== strpos( $row->old_flags
, 'gzip' ),
574 "Flags should contain 'gzip'" );
575 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
576 gzinflate( $row->old_text
), "Direct check" );
577 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
578 Revision
::getRevisionText( $row ), "getRevisionText" );
582 * @covers Revision::loadFromTitle
584 public function testLoadFromTitle() {
585 $title = $this->getMockTitle();
588 'rev_id=page_latest',
589 'page_namespace' => $title->getNamespace(),
590 'page_title' => $title->getDBkey()
595 'rev_page' => $title->getArticleID(),
596 'rev_text_id' => '2',
597 'rev_timestamp' => '20171017114835',
598 'rev_user_text' => '127.0.0.1',
600 'rev_minor_edit' => '0',
601 'rev_deleted' => '0',
603 'rev_parent_id' => '1',
604 'rev_sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
605 'rev_comment_text' => 'Goat Comment!',
606 'rev_comment_data' => null,
607 'rev_comment_cid' => null,
608 'rev_content_format' => 'GOATFORMAT',
609 'rev_content_model' => 'GOATMODEL',
612 $db = $this->getMock( IDatabase
::class );
613 $db->expects( $this->any() )
614 ->method( 'getDomainId' )
615 ->will( $this->returnValue( wfWikiID() ) );
616 $db->expects( $this->once() )
617 ->method( 'selectRow' )
619 $this->equalTo( [ 'revision', 'page', 'user' ] ),
620 // We don't really care about the fields are they come from the selectField methods
621 $this->isType( 'array' ),
622 $this->equalTo( $conditions ),
624 $this->stringContains( 'fetchRevisionRowFromConds' ),
625 // We don't really care about the options here
626 $this->isType( 'array' ),
627 // We don't really care about the join conds are they come from the joinCond methods
628 $this->isType( 'array' )
630 ->willReturn( $row );
632 $revision = Revision
::loadFromTitle( $db, $title );
634 $this->assertEquals( $title->getArticleID(), $revision->getTitle()->getArticleID() );
635 $this->assertEquals( $row->rev_id
, $revision->getId() );
636 $this->assertEquals( $row->rev_len
, $revision->getSize() );
637 $this->assertEquals( $row->rev_sha1
, $revision->getSha1() );
638 $this->assertEquals( $row->rev_parent_id
, $revision->getParentId() );
639 $this->assertEquals( $row->rev_timestamp
, $revision->getTimestamp() );
640 $this->assertEquals( $row->rev_comment_text
, $revision->getComment() );
641 $this->assertEquals( $row->rev_user_text
, $revision->getUserText() );
644 public function provideDecompressRevisionText() {
645 yield
'(no legacy encoding), false in false out' => [ false, false, [], false ];
646 yield
'(no legacy encoding), empty in empty out' => [ false, '', [], '' ];
647 yield
'(no legacy encoding), empty in empty out' => [ false, 'A', [], 'A' ];
648 yield
'(no legacy encoding), string in with gzip flag returns string' => [
649 // gzip string below generated with gzdeflate( 'AAAABBAAA' )
650 false, "sttttr\002\022\000", [ 'gzip' ], 'AAAABBAAA',
652 yield
'(no legacy encoding), string in with object flag returns false' => [
653 // gzip string below generated with serialize( 'JOJO' )
654 false, "s:4:\"JOJO\";", [ 'object' ], false,
656 yield
'(no legacy encoding), serialized object in with object flag returns string' => [
658 // Using a TitleValue object as it has a getText method (which is needed)
659 serialize( new TitleValue( 0, 'HHJJDDFF' ) ),
663 yield
'(no legacy encoding), serialized object in with object & gzip flag returns string' => [
665 // Using a TitleValue object as it has a getText method (which is needed)
666 gzdeflate( serialize( new TitleValue( 0, '8219JJJ840' ) ) ),
667 [ 'object', 'gzip' ],
670 yield
'(ISO-8859-1 encoding), string in string out' => [
672 iconv( 'utf-8', 'ISO-8859-1', "1®Àþ1" ),
676 yield
'(ISO-8859-1 encoding), serialized object in with gzip flags returns string' => [
678 gzdeflate( iconv( 'utf-8', 'ISO-8859-1', "4®Àþ4" ) ),
682 yield
'(ISO-8859-1 encoding), serialized object in with object flags returns string' => [
684 serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "3®Àþ3" ) ) ),
688 yield
'(ISO-8859-1 encoding), serialized object in with object & gzip flags returns string' => [
690 gzdeflate( serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "2®Àþ2" ) ) ) ),
691 [ 'gzip', 'object' ],
697 * @dataProvider provideDecompressRevisionText
698 * @covers Revision::decompressRevisionText
700 * @param bool $legacyEncoding
702 * @param array $flags
703 * @param mixed $expected
705 public function testDecompressRevisionText( $legacyEncoding, $text, $flags, $expected ) {
706 $blobStore = $this->getBlobStore();
707 if ( $legacyEncoding ) {
708 $blobStore->setLegacyEncoding( $legacyEncoding, Language
::factory( 'en' ) );
711 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
714 Revision
::decompressRevisionText( $text, $flags )
719 * @covers Revision::getRevisionText
721 public function testGetRevisionText_returnsFalseWhenNoTextField() {
722 $this->assertFalse( Revision
::getRevisionText( new stdClass() ) );
725 public function provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal() {
726 yield
'Just text' => [
727 (object)[ 'old_text' => 'SomeText' ],
731 // gzip string below generated with gzdeflate( 'AAAABBAAA' )
732 yield
'gzip text' => [
734 'old_text' => "sttttr\002\022\000",
735 'old_flags' => 'gzip'
740 yield
'gzip text and different prefix' => [
742 'jojo_text' => "sttttr\002\022\000",
743 'jojo_flags' => 'gzip'
751 * @dataProvider provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal
752 * @covers Revision::getRevisionText
754 public function testGetRevisionText_returnsDecompressedTextFieldWhenNotExternal(
759 $this->assertSame( $expected, Revision
::getRevisionText( $row, $prefix ) );
762 public function provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts() {
763 yield
'Just some text' => [ 'someNonUrlText' ];
764 yield
'No second URL part' => [ 'someProtocol://' ];
768 * @dataProvider provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts
769 * @covers Revision::getRevisionText
771 public function testGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts(
775 Revision
::getRevisionText(
778 'old_flags' => 'external',
785 * @covers Revision::getRevisionText
787 public function testGetRevisionText_external_noOldId() {
789 'ExternalStoreFactory',
790 new ExternalStoreFactory( [ 'ForTesting' ] )
794 Revision
::getRevisionText(
796 'old_text' => 'ForTesting://cluster1/12345',
797 'old_flags' => 'external,gzip',
804 * @covers Revision::getRevisionText
806 public function testGetRevisionText_external_oldId() {
807 $cache = $this->getWANObjectCache();
808 $this->setService( 'MainWANObjectCache', $cache );
811 'ExternalStoreFactory',
812 new ExternalStoreFactory( [ 'ForTesting' ] )
815 $lb = $this->getMockBuilder( LoadBalancer
::class )
816 ->disableOriginalConstructor()
819 $blobStore = new SqlBlobStore( $lb, $cache );
820 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
824 Revision
::getRevisionText(
826 'old_text' => 'ForTesting://cluster1/12345',
827 'old_flags' => 'external,gzip',
833 $cacheKey = $cache->makeKey( 'revisiontext', 'textid', 'tt:7777' );
834 $this->assertSame( 'AAAABBAAA', $cache->get( $cacheKey ) );
838 * @covers Revision::userJoinCond
840 public function testUserJoinCond() {
841 $this->hideDeprecated( 'Revision::userJoinCond' );
843 [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
844 Revision
::userJoinCond()
849 * @covers Revision::pageJoinCond
851 public function testPageJoinCond() {
852 $this->hideDeprecated( 'Revision::pageJoinCond' );
854 [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
855 Revision
::pageJoinCond()
859 public function provideSelectFields() {
874 'rev_comment_text' => 'rev_comment',
875 'rev_comment_data' => 'NULL',
876 'rev_comment_cid' => 'NULL',
877 'rev_content_format',
895 'rev_comment_text' => 'rev_comment',
896 'rev_comment_data' => 'NULL',
897 'rev_comment_cid' => 'NULL',
903 * @dataProvider provideSelectFields
904 * @covers Revision::selectFields
905 * @todo a true unit test would mock CommentStore
907 public function testSelectFields( $contentHandlerUseDB, $expected ) {
908 $this->hideDeprecated( 'Revision::selectFields' );
909 $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
910 $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD
);
911 $this->assertEquals( $expected, Revision
::selectFields() );
914 public function provideSelectArchiveFields() {
931 'ar_comment_text' => 'ar_comment',
932 'ar_comment_data' => 'NULL',
933 'ar_comment_cid' => 'NULL',
954 'ar_comment_text' => 'ar_comment',
955 'ar_comment_data' => 'NULL',
956 'ar_comment_cid' => 'NULL',
962 * @dataProvider provideSelectArchiveFields
963 * @covers Revision::selectArchiveFields
964 * @todo a true unit test would mock CommentStore
966 public function testSelectArchiveFields( $contentHandlerUseDB, $expected ) {
967 $this->hideDeprecated( 'Revision::selectArchiveFields' );
968 $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
969 $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD
);
970 $this->assertEquals( $expected, Revision
::selectArchiveFields() );
974 * @covers Revision::selectTextFields
976 public function testSelectTextFields() {
977 $this->hideDeprecated( 'Revision::selectTextFields' );
983 Revision
::selectTextFields()
988 * @covers Revision::selectPageFields
990 public function testSelectPageFields() {
991 $this->hideDeprecated( 'Revision::selectPageFields' );
1001 Revision
::selectPageFields()
1006 * @covers Revision::selectUserFields
1008 public function testSelectUserFields() {
1009 $this->hideDeprecated( 'Revision::selectUserFields' );
1010 $this->assertEquals(
1014 Revision
::selectUserFields()
1018 public function provideGetArchiveQueryInfo() {
1019 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD' => [
1021 'wgContentHandlerUseDB' => false,
1022 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1025 'tables' => [ 'archive' ],
1042 'ar_comment_text' => 'ar_comment',
1043 'ar_comment_data' => 'NULL',
1044 'ar_comment_cid' => 'NULL',
1049 yield
'wgContentHandlerUseDB true, wgCommentTableSchemaMigrationStage OLD' => [
1051 'wgContentHandlerUseDB' => true,
1052 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1055 'tables' => [ 'archive' ],
1072 'ar_comment_text' => 'ar_comment',
1073 'ar_comment_data' => 'NULL',
1074 'ar_comment_cid' => 'NULL',
1075 'ar_content_format',
1081 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_BOTH' => [
1083 'wgContentHandlerUseDB' => false,
1084 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
1089 'comment_ar_comment' => 'comment',
1107 'ar_comment_text' => 'COALESCE( comment_ar_comment.comment_text, ar_comment )',
1108 'ar_comment_data' => 'comment_ar_comment.comment_data',
1109 'ar_comment_cid' => 'comment_ar_comment.comment_id',
1112 'comment_ar_comment' => [
1114 'comment_ar_comment.comment_id = ar_comment_id',
1119 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_NEW' => [
1121 'wgContentHandlerUseDB' => false,
1122 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
1127 'comment_ar_comment' => 'comment',
1145 'ar_comment_text' => 'COALESCE( comment_ar_comment.comment_text, ar_comment )',
1146 'ar_comment_data' => 'comment_ar_comment.comment_data',
1147 'ar_comment_cid' => 'comment_ar_comment.comment_id',
1150 'comment_ar_comment' => [
1152 'comment_ar_comment.comment_id = ar_comment_id',
1157 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage NEW' => [
1159 'wgContentHandlerUseDB' => false,
1160 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW
,
1165 'comment_ar_comment' => 'comment',
1183 'ar_comment_text' => 'comment_ar_comment.comment_text',
1184 'ar_comment_data' => 'comment_ar_comment.comment_data',
1185 'ar_comment_cid' => 'comment_ar_comment.comment_id',
1188 'comment_ar_comment' => [
1190 'comment_ar_comment.comment_id = ar_comment_id',
1198 * @covers Revision::getArchiveQueryInfo
1199 * @dataProvider provideGetArchiveQueryInfo
1201 public function testGetArchiveQueryInfo( $globals, $expected ) {
1202 $this->setMwGlobals( $globals );
1204 $revisionStore = $this->getRevisionStore();
1205 $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
1206 $this->setService( 'RevisionStore', $revisionStore );
1208 $this->assertEquals(
1210 Revision
::getArchiveQueryInfo()
1214 public function provideGetQueryInfo() {
1215 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts none' => [
1217 'wgContentHandlerUseDB' => false,
1218 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1222 'tables' => [ 'revision' ],
1235 'rev_comment_text' => 'rev_comment',
1236 'rev_comment_data' => 'NULL',
1237 'rev_comment_cid' => 'NULL',
1242 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts page' => [
1244 'wgContentHandlerUseDB' => false,
1245 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1249 'tables' => [ 'revision', 'page' ],
1262 'rev_comment_text' => 'rev_comment',
1263 'rev_comment_data' => 'NULL',
1264 'rev_comment_cid' => 'NULL',
1275 [ 'page_id = rev_page' ],
1280 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts user' => [
1282 'wgContentHandlerUseDB' => false,
1283 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1287 'tables' => [ 'revision', 'user' ],
1300 'rev_comment_text' => 'rev_comment',
1301 'rev_comment_data' => 'NULL',
1302 'rev_comment_cid' => 'NULL',
1310 'user_id = rev_user',
1316 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts text' => [
1318 'wgContentHandlerUseDB' => false,
1319 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1323 'tables' => [ 'revision', 'text' ],
1336 'rev_comment_text' => 'rev_comment',
1337 'rev_comment_data' => 'NULL',
1338 'rev_comment_cid' => 'NULL',
1345 [ 'rev_text_id=old_id' ],
1350 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts 3' => [
1352 'wgContentHandlerUseDB' => false,
1353 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1355 [ 'text', 'page', 'user' ],
1357 'tables' => [ 'revision', 'page', 'user', 'text' ],
1370 'rev_comment_text' => 'rev_comment',
1371 'rev_comment_data' => 'NULL',
1372 'rev_comment_cid' => 'NULL',
1386 [ 'page_id = rev_page' ],
1392 'user_id = rev_user',
1397 [ 'rev_text_id=old_id' ],
1402 yield
'wgContentHandlerUseDB true, wgCommentTableSchemaMigrationStage OLD, opts none' => [
1404 'wgContentHandlerUseDB' => true,
1405 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1409 'tables' => [ 'revision' ],
1422 'rev_comment_text' => 'rev_comment',
1423 'rev_comment_data' => 'NULL',
1424 'rev_comment_cid' => 'NULL',
1425 'rev_content_format',
1426 'rev_content_model',
1431 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_BOTH, opts none' => [
1433 'wgContentHandlerUseDB' => false,
1434 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
1440 'temp_rev_comment' => 'revision_comment_temp',
1441 'comment_rev_comment' => 'comment',
1455 'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
1456 'rev_comment_data' => 'comment_rev_comment.comment_data',
1457 'rev_comment_cid' => 'comment_rev_comment.comment_id',
1460 'temp_rev_comment' => [
1462 'temp_rev_comment.revcomment_rev = rev_id',
1464 'comment_rev_comment' => [
1466 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
1471 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_NEW, opts none' => [
1473 'wgContentHandlerUseDB' => false,
1474 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
1480 'temp_rev_comment' => 'revision_comment_temp',
1481 'comment_rev_comment' => 'comment',
1495 'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
1496 'rev_comment_data' => 'comment_rev_comment.comment_data',
1497 'rev_comment_cid' => 'comment_rev_comment.comment_id',
1500 'temp_rev_comment' => [
1502 'temp_rev_comment.revcomment_rev = rev_id',
1504 'comment_rev_comment' => [
1506 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
1511 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage NEW, opts none' => [
1513 'wgContentHandlerUseDB' => false,
1514 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW
,
1520 'temp_rev_comment' => 'revision_comment_temp',
1521 'comment_rev_comment' => 'comment',
1535 'rev_comment_text' => 'comment_rev_comment.comment_text',
1536 'rev_comment_data' => 'comment_rev_comment.comment_data',
1537 'rev_comment_cid' => 'comment_rev_comment.comment_id',
1540 'temp_rev_comment' => [
1542 'temp_rev_comment.revcomment_rev = rev_id',
1544 'comment_rev_comment' => [
1546 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
1554 * @covers Revision::getQueryInfo
1555 * @dataProvider provideGetQueryInfo
1557 public function testGetQueryInfo( $globals, $options, $expected ) {
1558 $this->setMwGlobals( $globals );
1560 $revisionStore = $this->getRevisionStore();
1561 $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
1562 $this->setService( 'RevisionStore', $revisionStore );
1564 $this->assertEquals(
1566 Revision
::getQueryInfo( $options )