3 use MediaWiki\Storage\RevisionStore
;
4 use MediaWiki\Storage\SqlBlobStore
;
5 use Wikimedia\Rdbms\IDatabase
;
6 use Wikimedia\Rdbms\LoadBalancer
;
9 * Test cases in RevisionTest should not interact with the Database.
10 * For test cases that need Database interaction see RevisionDbTestBase.
12 class RevisionTest
extends MediaWikiTestCase
{
14 public function provideConstructFromArray() {
15 yield
'with text' => [
17 'text' => 'hello world.',
18 'content_model' => CONTENT_MODEL_JAVASCRIPT
21 yield
'with content' => [
23 'content' => new JavaScriptContent( 'hellow world.' )
26 // FIXME: test with and without user ID, and with a user object.
27 // We can't prepare that here though, since we don't yet have a dummy DB
31 * @param string $model
34 public function getMockTitle( $model = CONTENT_MODEL_WIKITEXT
) {
35 $mock = $this->getMockBuilder( Title
::class )
36 ->disableOriginalConstructor()
38 $mock->expects( $this->any() )
39 ->method( 'getNamespace' )
40 ->will( $this->returnValue( $this->getDefaultWikitextNS() ) );
41 $mock->expects( $this->any() )
42 ->method( 'getPrefixedText' )
43 ->will( $this->returnValue( 'RevisionTest' ) );
44 $mock->expects( $this->any() )
45 ->method( 'getDBKey' )
46 ->will( $this->returnValue( 'RevisionTest' ) );
47 $mock->expects( $this->any() )
48 ->method( 'getArticleID' )
49 ->will( $this->returnValue( 23 ) );
50 $mock->expects( $this->any() )
51 ->method( 'getModel' )
52 ->will( $this->returnValue( $model ) );
58 * @dataProvider provideConstructFromArray
59 * @covers Revision::__construct
60 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
62 public function testConstructFromArray( $rowArray ) {
63 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
64 $this->assertNotNull( $rev->getContent(), 'no content object available' );
65 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $rev->getContent()->getModel() );
66 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT
, $rev->getContentModel() );
70 * @covers Revision::__construct
71 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
73 public function testConstructFromEmptyArray() {
74 $rev = new Revision( [], 0, $this->getMockTitle() );
75 $this->assertNull( $rev->getContent(), 'no content object should be available' );
78 public function provideConstructFromArray_userSetAsExpected() {
79 yield
'no user defaults to wgUser' => [
81 'content' => new JavaScriptContent( 'hello world.' ),
86 yield
'user text and id' => [
88 'content' => new JavaScriptContent( 'hello world.' ),
89 'user_text' => 'SomeTextUserName',
96 yield
'user text only' => [
98 'content' => new JavaScriptContent( 'hello world.' ),
99 'user_text' => '111.111.111.111',
107 * @dataProvider provideConstructFromArray_userSetAsExpected
108 * @covers Revision::__construct
109 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
111 * @param array $rowArray
112 * @param mixed $expectedUserId null to expect the current wgUser ID
113 * @param mixed $expectedUserName null to expect the current wgUser name
115 public function testConstructFromArray_userSetAsExpected(
120 $testUser = $this->getTestUser()->getUser();
121 $this->setMwGlobals( 'wgUser', $testUser );
122 if ( $expectedUserId === null ) {
123 $expectedUserId = $testUser->getId();
125 if ( $expectedUserName === null ) {
126 $expectedUserName = $testUser->getName();
129 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
130 $this->assertEquals( $expectedUserId, $rev->getUser() );
131 $this->assertEquals( $expectedUserName, $rev->getUserText() );
134 public function provideConstructFromArrayThrowsExceptions() {
135 yield
'content and text_id both not empty' => [
137 'content' => new WikitextContent( 'GOAT' ),
138 'text_id' => 'someid',
140 new MWException( "Text already stored in external store (id someid), " .
141 "can't serialize content object" )
143 yield
'unknown user id and no user name' => [
145 'content' => new JavaScriptContent( 'hello world.' ),
148 new MWException( 'user_text not given, and unknown user ID 9989' )
150 yield
'with bad content object (class)' => [
151 [ 'content' => new stdClass() ],
152 new MWException( 'content field must contain a Content object.' )
154 yield
'with bad content object (string)' => [
155 [ 'content' => 'ImAGoat' ],
156 new MWException( 'content field must contain a Content object.' )
158 yield
'bad row format' => [
159 'imastring, not a row',
160 new InvalidArgumentException(
161 '$row must be a row object, an associative array, or a RevisionRecord'
167 * @dataProvider provideConstructFromArrayThrowsExceptions
168 * @covers Revision::__construct
169 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
171 public function testConstructFromArrayThrowsExceptions( $rowArray, Exception
$expectedException ) {
172 $this->setExpectedException(
173 get_class( $expectedException ),
174 $expectedException->getMessage(),
175 $expectedException->getCode()
177 new Revision( $rowArray, 0, $this->getMockTitle() );
181 * @covers Revision::__construct
182 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
184 public function testConstructFromNothing() {
185 $this->setExpectedException(
186 InvalidArgumentException
::class
191 public function provideConstructFromRow() {
192 yield
'Full construction' => [
196 'rev_text_id' => '2',
197 'rev_timestamp' => '20171017114835',
198 'rev_user_text' => '127.0.0.1',
200 'rev_minor_edit' => '0',
201 'rev_deleted' => '0',
203 'rev_parent_id' => '1',
204 'rev_sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
205 'rev_comment_text' => 'Goat Comment!',
206 'rev_comment_data' => null,
207 'rev_comment_cid' => null,
208 'rev_content_format' => 'GOATFORMAT',
209 'rev_content_model' => 'GOATMODEL',
211 function ( RevisionTest
$testCase, Revision
$rev ) {
212 $testCase->assertSame( 42, $rev->getId() );
213 $testCase->assertSame( 23, $rev->getPage() );
214 $testCase->assertSame( 2, $rev->getTextId() );
215 $testCase->assertSame( '20171017114835', $rev->getTimestamp() );
216 $testCase->assertSame( '127.0.0.1', $rev->getUserText() );
217 $testCase->assertSame( 0, $rev->getUser() );
218 $testCase->assertSame( false, $rev->isMinor() );
219 $testCase->assertSame( false, $rev->isDeleted( Revision
::DELETED_TEXT
) );
220 $testCase->assertSame( 46, $rev->getSize() );
221 $testCase->assertSame( 1, $rev->getParentId() );
222 $testCase->assertSame( 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z', $rev->getSha1() );
223 $testCase->assertSame( 'Goat Comment!', $rev->getComment() );
224 $testCase->assertSame( 'GOATFORMAT', $rev->getContentFormat() );
225 $testCase->assertSame( 'GOATMODEL', $rev->getContentModel() );
228 yield
'default field values' => [
232 'rev_text_id' => '2',
233 'rev_timestamp' => '20171017114835',
234 'rev_user_text' => '127.0.0.1',
236 'rev_minor_edit' => '0',
237 'rev_deleted' => '0',
238 'rev_comment_text' => 'Goat Comment!',
239 'rev_comment_data' => null,
240 'rev_comment_cid' => null,
242 function ( RevisionTest
$testCase, Revision
$rev ) {
243 // parent ID may be null
244 $testCase->assertSame( null, $rev->getParentId(), 'revision id' );
247 $testCase->assertSame( $rev->getTimestamp(), '20171017114835', 'timestamp' );
248 $testCase->assertSame( $rev->getUserText(), '127.0.0.1', 'user name' );
249 $testCase->assertSame( $rev->getUser(), 0, 'user id' );
250 $testCase->assertSame( $rev->getComment(), 'Goat Comment!' );
251 $testCase->assertSame( false, $rev->isMinor(), 'minor edit' );
252 $testCase->assertSame( 0, $rev->getVisibility(), 'visibility flags' );
255 $testCase->assertNotNull( $rev->getSize(), 'size' );
256 $testCase->assertNotNull( $rev->getSha1(), 'hash' );
258 // NOTE: model and format will be detected based on the namespace of the (mock) title
259 $testCase->assertSame( 'text/x-wiki', $rev->getContentFormat(), 'format' );
260 $testCase->assertSame( 'wikitext', $rev->getContentModel(), 'model' );
266 * @dataProvider provideConstructFromRow
267 * @covers Revision::__construct
268 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
270 public function testConstructFromRow( array $arrayData, $assertions ) {
271 $data = 'Hello goat.'; // needs to match model and format
273 $blobStore = $this->getMockBuilder( SqlBlobStore
::class )
274 ->disableOriginalConstructor()
277 $blobStore->method( 'getBlob' )
278 ->will( $this->returnValue( $data ) );
280 $blobStore->method( 'getTextIdFromAddress' )
281 ->will( $this->returnCallback(
282 function ( $address ) {
283 // Turn "tt:1234" into 12345.
284 // Note that this must be functional so we can test getTextId().
285 // Ideally, we'd un-mock getTextIdFromAddress and use its actual implementation.
286 $parts = explode( ':', $address );
287 return (int)array_pop( $parts );
291 // Note override internal service, so RevisionStore uses it as well.
292 $this->setService( '_SqlBlobStore', $blobStore );
294 $row = (object)$arrayData;
295 $rev = new Revision( $row, 0, $this->getMockTitle() );
296 $assertions( $this, $rev );
299 public function provideGetRevisionText() {
300 yield
'Generic test' => [
301 'This is a goat of revision text.',
304 'old_text' => 'This is a goat of revision text.',
309 public function provideGetId() {
321 * @dataProvider provideGetId
322 * @covers Revision::getId
324 public function testGetId( $rowArray, $expectedId ) {
325 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
326 $this->assertEquals( $expectedId, $rev->getId() );
329 public function provideSetId() {
330 yield
[ '123', 123 ];
335 * @dataProvider provideSetId
336 * @covers Revision::setId
338 public function testSetId( $input, $expected ) {
339 $rev = new Revision( [], 0, $this->getMockTitle() );
340 $rev->setId( $input );
341 $this->assertSame( $expected, $rev->getId() );
344 public function provideSetUserIdAndName() {
345 yield
[ '123', 123, 'GOaT' ];
346 yield
[ 456, 456, 'GOaT' ];
350 * @dataProvider provideSetUserIdAndName
351 * @covers Revision::setUserIdAndName
353 public function testSetUserIdAndName( $inputId, $expectedId, $name ) {
354 $rev = new Revision( [], 0, $this->getMockTitle() );
355 $rev->setUserIdAndName( $inputId, $name );
356 $this->assertSame( $expectedId, $rev->getUser( Revision
::RAW
) );
357 $this->assertEquals( $name, $rev->getUserText( Revision
::RAW
) );
360 public function provideGetTextId() {
362 yield
[ [ 'text_id' => '123' ], 123 ];
363 yield
[ [ 'text_id' => 456 ], 456 ];
367 * @dataProvider provideGetTextId
368 * @covers Revision::getTextId()
370 public function testGetTextId( $rowArray, $expected ) {
371 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
372 $this->assertSame( $expected, $rev->getTextId() );
375 public function provideGetParentId() {
377 yield
[ [ 'parent_id' => '123' ], 123 ];
378 yield
[ [ 'parent_id' => 456 ], 456 ];
382 * @dataProvider provideGetParentId
383 * @covers Revision::getParentId()
385 public function testGetParentId( $rowArray, $expected ) {
386 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
387 $this->assertSame( $expected, $rev->getParentId() );
391 * @covers Revision::getRevisionText
392 * @dataProvider provideGetRevisionText
394 public function testGetRevisionText( $expected, $rowData, $prefix = 'old_', $wiki = false ) {
397 Revision
::getRevisionText( (object)$rowData, $prefix, $wiki ) );
400 public function provideGetRevisionTextWithZlibExtension() {
401 yield
'Generic gzip test' => [
402 'This is a small goat of revision text.',
404 'old_flags' => 'gzip',
405 'old_text' => gzdeflate( 'This is a small goat of revision text.' ),
411 * @covers Revision::getRevisionText
412 * @dataProvider provideGetRevisionTextWithZlibExtension
414 public function testGetRevisionWithZlibExtension( $expected, $rowData ) {
415 $this->checkPHPExtension( 'zlib' );
416 $this->testGetRevisionText( $expected, $rowData );
419 private function getWANObjectCache() {
420 return new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
424 * @return SqlBlobStore
426 private function getBlobStore() {
427 /** @var LoadBalancer $lb */
428 $lb = $this->getMockBuilder( LoadBalancer
::class )
429 ->disableOriginalConstructor()
432 $cache = $this->getWANObjectCache();
434 $blobStore = new SqlBlobStore( $lb, $cache );
439 * @return RevisionStore
441 private function getRevisionStore() {
442 /** @var LoadBalancer $lb */
443 $lb = $this->getMockBuilder( LoadBalancer
::class )
444 ->disableOriginalConstructor()
447 $cache = $this->getWANObjectCache();
449 $blobStore = new RevisionStore( $lb, $this->getBlobStore(), $cache );
453 public function provideGetRevisionTextWithLegacyEncoding() {
454 yield
'Utf8Native' => [
455 "Wiki est l'\xc3\xa9cole superieur !",
459 'old_flags' => 'utf-8',
460 'old_text' => "Wiki est l'\xc3\xa9cole superieur !",
463 yield
'Utf8Legacy' => [
464 "Wiki est l'\xc3\xa9cole superieur !",
469 'old_text' => "Wiki est l'\xe9cole superieur !",
475 * @covers Revision::getRevisionText
476 * @dataProvider provideGetRevisionTextWithLegacyEncoding
478 public function testGetRevisionWithLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
479 $blobStore = $this->getBlobStore();
480 $blobStore->setLegacyEncoding( $encoding, Language
::factory( $lang ) );
481 $this->setService( 'BlobStore', $blobStore );
483 $this->testGetRevisionText( $expected, $rowData );
486 public function provideGetRevisionTextWithGzipAndLegacyEncoding() {
489 * Do not set the external flag!
490 * Otherwise, getRevisionText will hit the live database (if ExternalStore is enabled)!
492 yield
'Utf8NativeGzip' => [
493 "Wiki est l'\xc3\xa9cole superieur !",
497 'old_flags' => 'gzip,utf-8',
498 'old_text' => gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" ),
501 yield
'Utf8LegacyGzip' => [
502 "Wiki est l'\xc3\xa9cole superieur !",
506 'old_flags' => 'gzip',
507 'old_text' => gzdeflate( "Wiki est l'\xe9cole superieur !" ),
513 * @covers Revision::getRevisionText
514 * @dataProvider provideGetRevisionTextWithGzipAndLegacyEncoding
516 public function testGetRevisionWithGzipAndLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
517 $this->checkPHPExtension( 'zlib' );
519 $blobStore = $this->getBlobStore();
520 $blobStore->setLegacyEncoding( $encoding, Language
::factory( $lang ) );
521 $this->setService( 'BlobStore', $blobStore );
523 $this->testGetRevisionText( $expected, $rowData );
527 * @covers Revision::compressRevisionText
529 public function testCompressRevisionTextUtf8() {
531 $row->old_text
= "Wiki est l'\xc3\xa9cole superieur !";
532 $row->old_flags
= Revision
::compressRevisionText( $row->old_text
);
533 $this->assertTrue( false !== strpos( $row->old_flags
, 'utf-8' ),
534 "Flags should contain 'utf-8'" );
535 $this->assertFalse( false !== strpos( $row->old_flags
, 'gzip' ),
536 "Flags should not contain 'gzip'" );
537 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
538 $row->old_text
, "Direct check" );
539 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
540 Revision
::getRevisionText( $row ), "getRevisionText" );
544 * @covers Revision::compressRevisionText
546 public function testCompressRevisionTextUtf8Gzip() {
547 $this->checkPHPExtension( 'zlib' );
549 $blobStore = $this->getBlobStore();
550 $blobStore->setCompressBlobs( true );
551 $this->setService( 'BlobStore', $blobStore );
554 $row->old_text
= "Wiki est l'\xc3\xa9cole superieur !";
555 $row->old_flags
= Revision
::compressRevisionText( $row->old_text
);
556 $this->assertTrue( false !== strpos( $row->old_flags
, 'utf-8' ),
557 "Flags should contain 'utf-8'" );
558 $this->assertTrue( false !== strpos( $row->old_flags
, 'gzip' ),
559 "Flags should contain 'gzip'" );
560 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
561 gzinflate( $row->old_text
), "Direct check" );
562 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
563 Revision
::getRevisionText( $row ), "getRevisionText" );
567 * @covers Revision::loadFromTitle
569 public function testLoadFromTitle() {
570 $title = $this->getMockTitle();
573 'rev_id=page_latest',
574 'page_namespace' => $title->getNamespace(),
575 'page_title' => $title->getDBkey()
580 'rev_page' => $title->getArticleID(),
581 'rev_text_id' => '2',
582 'rev_timestamp' => '20171017114835',
583 'rev_user_text' => '127.0.0.1',
585 'rev_minor_edit' => '0',
586 'rev_deleted' => '0',
588 'rev_parent_id' => '1',
589 'rev_sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
590 'rev_comment_text' => 'Goat Comment!',
591 'rev_comment_data' => null,
592 'rev_comment_cid' => null,
593 'rev_content_format' => 'GOATFORMAT',
594 'rev_content_model' => 'GOATMODEL',
597 $db = $this->getMock( IDatabase
::class );
598 $db->expects( $this->any() )
599 ->method( 'getDomainId' )
600 ->will( $this->returnValue( wfWikiID() ) );
601 $db->expects( $this->once() )
602 ->method( 'selectRow' )
604 $this->equalTo( [ 'revision', 'page', 'user' ] ),
605 // We don't really care about the fields are they come from the selectField methods
606 $this->isType( 'array' ),
607 $this->equalTo( $conditions ),
609 $this->stringContains( 'fetchRevisionRowFromConds' ),
610 // We don't really care about the options here
611 $this->isType( 'array' ),
612 // We don't really care about the join conds are they come from the joinCond methods
613 $this->isType( 'array' )
615 ->willReturn( $row );
617 $revision = Revision
::loadFromTitle( $db, $title );
619 $this->assertEquals( $title->getArticleID(), $revision->getTitle()->getArticleID() );
620 $this->assertEquals( $row->rev_id
, $revision->getId() );
621 $this->assertEquals( $row->rev_len
, $revision->getSize() );
622 $this->assertEquals( $row->rev_sha1
, $revision->getSha1() );
623 $this->assertEquals( $row->rev_parent_id
, $revision->getParentId() );
624 $this->assertEquals( $row->rev_timestamp
, $revision->getTimestamp() );
625 $this->assertEquals( $row->rev_comment_text
, $revision->getComment() );
626 $this->assertEquals( $row->rev_user_text
, $revision->getUserText() );
629 public function provideDecompressRevisionText() {
630 yield
'(no legacy encoding), false in false out' => [ false, false, [], false ];
631 yield
'(no legacy encoding), empty in empty out' => [ false, '', [], '' ];
632 yield
'(no legacy encoding), empty in empty out' => [ false, 'A', [], 'A' ];
633 yield
'(no legacy encoding), string in with gzip flag returns string' => [
634 // gzip string below generated with gzdeflate( 'AAAABBAAA' )
635 false, "sttttr\002\022\000", [ 'gzip' ], 'AAAABBAAA',
637 yield
'(no legacy encoding), string in with object flag returns false' => [
638 // gzip string below generated with serialize( 'JOJO' )
639 false, "s:4:\"JOJO\";", [ 'object' ], false,
641 yield
'(no legacy encoding), serialized object in with object flag returns string' => [
643 // Using a TitleValue object as it has a getText method (which is needed)
644 serialize( new TitleValue( 0, 'HHJJDDFF' ) ),
648 yield
'(no legacy encoding), serialized object in with object & gzip flag returns string' => [
650 // Using a TitleValue object as it has a getText method (which is needed)
651 gzdeflate( serialize( new TitleValue( 0, '8219JJJ840' ) ) ),
652 [ 'object', 'gzip' ],
655 yield
'(ISO-8859-1 encoding), string in string out' => [
657 iconv( 'utf-8', 'ISO-8859-1', "1®Àþ1" ),
661 yield
'(ISO-8859-1 encoding), serialized object in with gzip flags returns string' => [
663 gzdeflate( iconv( 'utf-8', 'ISO-8859-1', "4®Àþ4" ) ),
667 yield
'(ISO-8859-1 encoding), serialized object in with object flags returns string' => [
669 serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "3®Àþ3" ) ) ),
673 yield
'(ISO-8859-1 encoding), serialized object in with object & gzip flags returns string' => [
675 gzdeflate( serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "2®Àþ2" ) ) ) ),
676 [ 'gzip', 'object' ],
682 * @dataProvider provideDecompressRevisionText
683 * @covers Revision::decompressRevisionText
685 * @param bool $legacyEncoding
687 * @param array $flags
688 * @param mixed $expected
690 public function testDecompressRevisionText( $legacyEncoding, $text, $flags, $expected ) {
691 $blobStore = $this->getBlobStore();
692 if ( $legacyEncoding ) {
693 $blobStore->setLegacyEncoding( $legacyEncoding, Language
::factory( 'en' ) );
696 $this->setService( 'BlobStore', $blobStore );
699 Revision
::decompressRevisionText( $text, $flags )
704 * @covers Revision::getRevisionText
706 public function testGetRevisionText_returnsFalseWhenNoTextField() {
707 $this->assertFalse( Revision
::getRevisionText( new stdClass() ) );
710 public function provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal() {
711 yield
'Just text' => [
712 (object)[ 'old_text' => 'SomeText' ],
716 // gzip string below generated with gzdeflate( 'AAAABBAAA' )
717 yield
'gzip text' => [
719 'old_text' => "sttttr\002\022\000",
720 'old_flags' => 'gzip'
725 yield
'gzip text and different prefix' => [
727 'jojo_text' => "sttttr\002\022\000",
728 'jojo_flags' => 'gzip'
736 * @dataProvider provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal
737 * @covers Revision::getRevisionText
739 public function testGetRevisionText_returnsDecompressedTextFieldWhenNotExternal(
744 $this->assertSame( $expected, Revision
::getRevisionText( $row, $prefix ) );
747 public function provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts() {
748 yield
'Just some text' => [ 'someNonUrlText' ];
749 yield
'No second URL part' => [ 'someProtocol://' ];
753 * @dataProvider provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts
754 * @covers Revision::getRevisionText
756 public function testGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts(
760 Revision
::getRevisionText(
763 'old_flags' => 'external',
770 * @covers Revision::getRevisionText
772 public function testGetRevisionText_external_noOldId() {
774 'ExternalStoreFactory',
775 new ExternalStoreFactory( [ 'ForTesting' ] )
779 Revision
::getRevisionText(
781 'old_text' => 'ForTesting://cluster1/12345',
782 'old_flags' => 'external,gzip',
789 * @covers Revision::getRevisionText
791 public function testGetRevisionText_external_oldId() {
792 $cache = $this->getWANObjectCache();
793 $this->setService( 'MainWANObjectCache', $cache );
796 'ExternalStoreFactory',
797 new ExternalStoreFactory( [ 'ForTesting' ] )
800 $lb = $this->getMockBuilder( LoadBalancer
::class )
801 ->disableOriginalConstructor()
804 $blobStore = new SqlBlobStore( $lb, $cache );
805 $this->setService( 'BlobStore', $blobStore );
809 Revision
::getRevisionText(
811 'old_text' => 'ForTesting://cluster1/12345',
812 'old_flags' => 'external,gzip',
818 $cacheKey = $cache->makeKey( 'revisiontext', 'textid', 'tt:7777' );
819 $this->assertSame( 'AAAABBAAA', $cache->get( $cacheKey ) );
823 * @covers Revision::userJoinCond
825 public function testUserJoinCond() {
826 $this->hideDeprecated( 'Revision::userJoinCond' );
828 [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
829 Revision
::userJoinCond()
834 * @covers Revision::pageJoinCond
836 public function testPageJoinCond() {
837 $this->hideDeprecated( 'Revision::pageJoinCond' );
839 [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
840 Revision
::pageJoinCond()
844 public function provideSelectFields() {
859 'rev_comment_text' => 'rev_comment',
860 'rev_comment_data' => 'NULL',
861 'rev_comment_cid' => 'NULL',
862 'rev_content_format',
880 'rev_comment_text' => 'rev_comment',
881 'rev_comment_data' => 'NULL',
882 'rev_comment_cid' => 'NULL',
888 * @dataProvider provideSelectFields
889 * @covers Revision::selectFields
890 * @todo a true unit test would mock CommentStore
892 public function testSelectFields( $contentHandlerUseDB, $expected ) {
893 $this->hideDeprecated( 'Revision::selectFields' );
894 $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
895 $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD
);
896 $this->assertEquals( $expected, Revision
::selectFields() );
899 public function provideSelectArchiveFields() {
916 'ar_comment_text' => 'ar_comment',
917 'ar_comment_data' => 'NULL',
918 'ar_comment_cid' => 'NULL',
939 'ar_comment_text' => 'ar_comment',
940 'ar_comment_data' => 'NULL',
941 'ar_comment_cid' => 'NULL',
947 * @dataProvider provideSelectArchiveFields
948 * @covers Revision::selectArchiveFields
949 * @todo a true unit test would mock CommentStore
951 public function testSelectArchiveFields( $contentHandlerUseDB, $expected ) {
952 $this->hideDeprecated( 'Revision::selectArchiveFields' );
953 $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
954 $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD
);
955 $this->assertEquals( $expected, Revision
::selectArchiveFields() );
959 * @covers Revision::selectTextFields
961 public function testSelectTextFields() {
962 $this->hideDeprecated( 'Revision::selectTextFields' );
968 Revision
::selectTextFields()
973 * @covers Revision::selectPageFields
975 public function testSelectPageFields() {
976 $this->hideDeprecated( 'Revision::selectPageFields' );
986 Revision
::selectPageFields()
991 * @covers Revision::selectUserFields
993 public function testSelectUserFields() {
994 $this->hideDeprecated( 'Revision::selectUserFields' );
999 Revision
::selectUserFields()
1003 public function provideGetArchiveQueryInfo() {
1004 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD' => [
1006 'wgContentHandlerUseDB' => false,
1007 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1010 'tables' => [ 'archive' ],
1027 'ar_comment_text' => 'ar_comment',
1028 'ar_comment_data' => 'NULL',
1029 'ar_comment_cid' => 'NULL',
1034 yield
'wgContentHandlerUseDB true, wgCommentTableSchemaMigrationStage OLD' => [
1036 'wgContentHandlerUseDB' => true,
1037 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1040 'tables' => [ 'archive' ],
1057 'ar_comment_text' => 'ar_comment',
1058 'ar_comment_data' => 'NULL',
1059 'ar_comment_cid' => 'NULL',
1060 'ar_content_format',
1066 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_BOTH' => [
1068 'wgContentHandlerUseDB' => false,
1069 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
1074 'comment_ar_comment' => 'comment',
1092 'ar_comment_text' => 'COALESCE( comment_ar_comment.comment_text, ar_comment )',
1093 'ar_comment_data' => 'comment_ar_comment.comment_data',
1094 'ar_comment_cid' => 'comment_ar_comment.comment_id',
1097 'comment_ar_comment' => [
1099 'comment_ar_comment.comment_id = ar_comment_id',
1104 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_NEW' => [
1106 'wgContentHandlerUseDB' => false,
1107 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
1112 'comment_ar_comment' => 'comment',
1130 'ar_comment_text' => 'COALESCE( comment_ar_comment.comment_text, ar_comment )',
1131 'ar_comment_data' => 'comment_ar_comment.comment_data',
1132 'ar_comment_cid' => 'comment_ar_comment.comment_id',
1135 'comment_ar_comment' => [
1137 'comment_ar_comment.comment_id = ar_comment_id',
1142 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage NEW' => [
1144 'wgContentHandlerUseDB' => false,
1145 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW
,
1150 'comment_ar_comment' => 'comment',
1168 'ar_comment_text' => 'comment_ar_comment.comment_text',
1169 'ar_comment_data' => 'comment_ar_comment.comment_data',
1170 'ar_comment_cid' => 'comment_ar_comment.comment_id',
1173 'comment_ar_comment' => [
1175 'comment_ar_comment.comment_id = ar_comment_id',
1183 * @covers Revision::getArchiveQueryInfo
1184 * @dataProvider provideGetArchiveQueryInfo
1186 public function testGetArchiveQueryInfo( $globals, $expected ) {
1187 $this->setMwGlobals( $globals );
1189 $revisionStore = $this->getRevisionStore();
1190 $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
1191 $this->setService( 'RevisionStore', $revisionStore );
1193 $this->assertEquals(
1195 Revision
::getArchiveQueryInfo()
1199 public function provideGetQueryInfo() {
1200 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts none' => [
1202 'wgContentHandlerUseDB' => false,
1203 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1207 'tables' => [ 'revision' ],
1220 'rev_comment_text' => 'rev_comment',
1221 'rev_comment_data' => 'NULL',
1222 'rev_comment_cid' => 'NULL',
1227 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts page' => [
1229 'wgContentHandlerUseDB' => false,
1230 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1234 'tables' => [ 'revision', 'page' ],
1247 'rev_comment_text' => 'rev_comment',
1248 'rev_comment_data' => 'NULL',
1249 'rev_comment_cid' => 'NULL',
1260 [ 'page_id = rev_page' ],
1265 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts user' => [
1267 'wgContentHandlerUseDB' => false,
1268 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1272 'tables' => [ 'revision', 'user' ],
1285 'rev_comment_text' => 'rev_comment',
1286 'rev_comment_data' => 'NULL',
1287 'rev_comment_cid' => 'NULL',
1295 'user_id = rev_user',
1301 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts text' => [
1303 'wgContentHandlerUseDB' => false,
1304 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1308 'tables' => [ 'revision', 'text' ],
1321 'rev_comment_text' => 'rev_comment',
1322 'rev_comment_data' => 'NULL',
1323 'rev_comment_cid' => 'NULL',
1330 [ 'rev_text_id=old_id' ],
1335 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts 3' => [
1337 'wgContentHandlerUseDB' => false,
1338 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1340 [ 'text', 'page', 'user' ],
1342 'tables' => [ 'revision', 'page', 'user', 'text' ],
1355 'rev_comment_text' => 'rev_comment',
1356 'rev_comment_data' => 'NULL',
1357 'rev_comment_cid' => 'NULL',
1371 [ 'page_id = rev_page' ],
1377 'user_id = rev_user',
1382 [ 'rev_text_id=old_id' ],
1387 yield
'wgContentHandlerUseDB true, wgCommentTableSchemaMigrationStage OLD, opts none' => [
1389 'wgContentHandlerUseDB' => true,
1390 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD
,
1394 'tables' => [ 'revision' ],
1407 'rev_comment_text' => 'rev_comment',
1408 'rev_comment_data' => 'NULL',
1409 'rev_comment_cid' => 'NULL',
1410 'rev_content_format',
1411 'rev_content_model',
1416 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_BOTH, opts none' => [
1418 'wgContentHandlerUseDB' => false,
1419 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH
,
1425 'temp_rev_comment' => 'revision_comment_temp',
1426 'comment_rev_comment' => 'comment',
1440 'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
1441 'rev_comment_data' => 'comment_rev_comment.comment_data',
1442 'rev_comment_cid' => 'comment_rev_comment.comment_id',
1445 'temp_rev_comment' => [
1447 'temp_rev_comment.revcomment_rev = rev_id',
1449 'comment_rev_comment' => [
1451 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
1456 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_NEW, opts none' => [
1458 'wgContentHandlerUseDB' => false,
1459 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW
,
1465 'temp_rev_comment' => 'revision_comment_temp',
1466 'comment_rev_comment' => 'comment',
1480 'rev_comment_text' => 'COALESCE( comment_rev_comment.comment_text, rev_comment )',
1481 'rev_comment_data' => 'comment_rev_comment.comment_data',
1482 'rev_comment_cid' => 'comment_rev_comment.comment_id',
1485 'temp_rev_comment' => [
1487 'temp_rev_comment.revcomment_rev = rev_id',
1489 'comment_rev_comment' => [
1491 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
1496 yield
'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage NEW, opts none' => [
1498 'wgContentHandlerUseDB' => false,
1499 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW
,
1505 'temp_rev_comment' => 'revision_comment_temp',
1506 'comment_rev_comment' => 'comment',
1520 'rev_comment_text' => 'comment_rev_comment.comment_text',
1521 'rev_comment_data' => 'comment_rev_comment.comment_data',
1522 'rev_comment_cid' => 'comment_rev_comment.comment_id',
1525 'temp_rev_comment' => [
1527 'temp_rev_comment.revcomment_rev = rev_id',
1529 'comment_rev_comment' => [
1531 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
1539 * @covers Revision::getQueryInfo
1540 * @dataProvider provideGetQueryInfo
1542 public function testGetQueryInfo( $globals, $options, $expected ) {
1543 $this->setMwGlobals( $globals );
1545 $revisionStore = $this->getRevisionStore();
1546 $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
1547 $this->setService( 'RevisionStore', $revisionStore );
1549 $this->assertEquals(
1551 Revision
::getQueryInfo( $options )