Merge "mw.rcfilters.ui.SaveFiltersPopupButtonWidget: Remove pointless option"
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionTest.php
1 <?php
2
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;
8
9 /**
10 * Test cases in RevisionTest should not interact with the Database.
11 * For test cases that need Database interaction see RevisionDbTestBase.
12 */
13 class RevisionTest extends MediaWikiTestCase {
14
15 public function provideConstructFromArray() {
16 yield 'with text' => [
17 [
18 'text' => 'hello world.',
19 'content_model' => CONTENT_MODEL_JAVASCRIPT
20 ],
21 ];
22 yield 'with content' => [
23 [
24 'content' => new JavaScriptContent( 'hellow world.' )
25 ],
26 ];
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
29 }
30
31 /**
32 * @param string $model
33 * @return Title
34 */
35 public function getMockTitle( $model = CONTENT_MODEL_WIKITEXT ) {
36 $mock = $this->getMockBuilder( Title::class )
37 ->disableOriginalConstructor()
38 ->getMock();
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 ) );
54
55 return $mock;
56 }
57
58 /**
59 * @dataProvider provideConstructFromArray
60 * @covers Revision::__construct
61 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
62 */
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() );
68 }
69
70 /**
71 * @covers Revision::__construct
72 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
73 */
74 public function testConstructFromEmptyArray() {
75 $rev = new Revision( [], 0, $this->getMockTitle() );
76 $this->assertNull( $rev->getContent(), 'no content object should be available' );
77 }
78
79 public function provideConstructFromArray_userSetAsExpected() {
80 yield 'no user defaults to wgUser' => [
81 [
82 'content' => new JavaScriptContent( 'hello world.' ),
83 ],
84 null,
85 null,
86 ];
87 yield 'user text and id' => [
88 [
89 'content' => new JavaScriptContent( 'hello world.' ),
90 'user_text' => 'SomeTextUserName',
91 'user' => 99,
92
93 ],
94 99,
95 'SomeTextUserName',
96 ];
97 yield 'user text only' => [
98 [
99 'content' => new JavaScriptContent( 'hello world.' ),
100 'user_text' => '111.111.111.111',
101 ],
102 0,
103 '111.111.111.111',
104 ];
105 }
106
107 /**
108 * @dataProvider provideConstructFromArray_userSetAsExpected
109 * @covers Revision::__construct
110 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
111 *
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
115 */
116 public function testConstructFromArray_userSetAsExpected(
117 array $rowArray,
118 $expectedUserId,
119 $expectedUserName
120 ) {
121 $testUser = $this->getTestUser()->getUser();
122 $this->setMwGlobals( 'wgUser', $testUser );
123 if ( $expectedUserId === null ) {
124 $expectedUserId = $testUser->getId();
125 }
126 if ( $expectedUserName === null ) {
127 $expectedUserName = $testUser->getName();
128 }
129
130 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
131 $this->assertEquals( $expectedUserId, $rev->getUser() );
132 $this->assertEquals( $expectedUserName, $rev->getUserText() );
133 }
134
135 public function provideConstructFromArrayThrowsExceptions() {
136 yield 'content and text_id both not empty' => [
137 [
138 'content' => new WikitextContent( 'GOAT' ),
139 'text_id' => 'someid',
140 ],
141 new MWException( "Text already stored in external store (id someid), " .
142 "can't serialize content object" )
143 ];
144 yield 'unknown user id and no user name' => [
145 [
146 'content' => new JavaScriptContent( 'hello world.' ),
147 'user' => 9989,
148 ],
149 new MWException( 'user_text not given, and unknown user ID 9989' )
150 ];
151 yield 'with bad content object (class)' => [
152 [ 'content' => new stdClass() ],
153 new MWException( 'content field must contain a Content object.' )
154 ];
155 yield 'with bad content object (string)' => [
156 [ 'content' => 'ImAGoat' ],
157 new MWException( 'content field must contain a Content object.' )
158 ];
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'
163 )
164 ];
165 }
166
167 /**
168 * @dataProvider provideConstructFromArrayThrowsExceptions
169 * @covers Revision::__construct
170 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
171 */
172 public function testConstructFromArrayThrowsExceptions( $rowArray, Exception $expectedException ) {
173 $this->setExpectedException(
174 get_class( $expectedException ),
175 $expectedException->getMessage(),
176 $expectedException->getCode()
177 );
178 new Revision( $rowArray, 0, $this->getMockTitle() );
179 }
180
181 /**
182 * @covers Revision::__construct
183 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
184 */
185 public function testConstructFromNothing() {
186 $this->setExpectedException(
187 InvalidArgumentException::class
188 );
189 new Revision( [] );
190 }
191
192 public function provideConstructFromRow() {
193 yield 'Full construction' => [
194 [
195 'rev_id' => '42',
196 'rev_page' => '23',
197 'rev_text_id' => '2',
198 'rev_timestamp' => '20171017114835',
199 'rev_user_text' => '127.0.0.1',
200 'rev_user' => '0',
201 'rev_minor_edit' => '0',
202 'rev_deleted' => '0',
203 'rev_len' => '46',
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',
211 ],
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() );
227 }
228 ];
229 yield 'default field values' => [
230 [
231 'rev_id' => '42',
232 'rev_page' => '23',
233 'rev_text_id' => '2',
234 'rev_timestamp' => '20171017114835',
235 'rev_user_text' => '127.0.0.1',
236 'rev_user' => '0',
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,
242 ],
243 function ( RevisionTest $testCase, Revision $rev ) {
244 // parent ID may be null
245 $testCase->assertSame( null, $rev->getParentId(), 'revision id' );
246
247 // given fields
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' );
254
255 // computed fields
256 $testCase->assertNotNull( $rev->getSize(), 'size' );
257 $testCase->assertNotNull( $rev->getSha1(), 'hash' );
258
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' );
262 }
263 ];
264 }
265
266 /**
267 * @dataProvider provideConstructFromRow
268 * @covers Revision::__construct
269 * @covers \MediaWiki\Storage\RevisionStore::newMutableRevisionFromArray
270 */
271 public function testConstructFromRow( array $arrayData, $assertions ) {
272 $data = 'Hello goat.'; // needs to match model and format
273
274 $blobStore = $this->getMockBuilder( SqlBlobStore::class )
275 ->disableOriginalConstructor()
276 ->getMock();
277
278 $blobStore->method( 'getBlob' )
279 ->will( $this->returnValue( $data ) );
280
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 );
289 }
290 ) );
291
292 // Note override internal service, so RevisionStore uses it as well.
293 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
294
295 $row = (object)$arrayData;
296 $rev = new Revision( $row, 0, $this->getMockTitle() );
297 $assertions( $this, $rev );
298 }
299
300 public function provideGetRevisionText() {
301 yield 'Generic test' => [
302 'This is a goat of revision text.',
303 [
304 'old_flags' => '',
305 'old_text' => 'This is a goat of revision text.',
306 ],
307 ];
308 }
309
310 public function provideGetId() {
311 yield [
312 [],
313 null
314 ];
315 yield [
316 [ 'id' => 998 ],
317 998
318 ];
319 }
320
321 /**
322 * @dataProvider provideGetId
323 * @covers Revision::getId
324 */
325 public function testGetId( $rowArray, $expectedId ) {
326 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
327 $this->assertEquals( $expectedId, $rev->getId() );
328 }
329
330 public function provideSetId() {
331 yield [ '123', 123 ];
332 yield [ 456, 456 ];
333 }
334
335 /**
336 * @dataProvider provideSetId
337 * @covers Revision::setId
338 */
339 public function testSetId( $input, $expected ) {
340 $rev = new Revision( [], 0, $this->getMockTitle() );
341 $rev->setId( $input );
342 $this->assertSame( $expected, $rev->getId() );
343 }
344
345 public function provideSetUserIdAndName() {
346 yield [ '123', 123, 'GOaT' ];
347 yield [ 456, 456, 'GOaT' ];
348 }
349
350 /**
351 * @dataProvider provideSetUserIdAndName
352 * @covers Revision::setUserIdAndName
353 */
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 ) );
359 }
360
361 public function provideGetTextId() {
362 yield [ [], null ];
363 yield [ [ 'text_id' => '123' ], 123 ];
364 yield [ [ 'text_id' => 456 ], 456 ];
365 }
366
367 /**
368 * @dataProvider provideGetTextId
369 * @covers Revision::getTextId()
370 */
371 public function testGetTextId( $rowArray, $expected ) {
372 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
373 $this->assertSame( $expected, $rev->getTextId() );
374 }
375
376 public function provideGetParentId() {
377 yield [ [], null ];
378 yield [ [ 'parent_id' => '123' ], 123 ];
379 yield [ [ 'parent_id' => 456 ], 456 ];
380 }
381
382 /**
383 * @dataProvider provideGetParentId
384 * @covers Revision::getParentId()
385 */
386 public function testGetParentId( $rowArray, $expected ) {
387 $rev = new Revision( $rowArray, 0, $this->getMockTitle() );
388 $this->assertSame( $expected, $rev->getParentId() );
389 }
390
391 /**
392 * @covers Revision::getRevisionText
393 * @dataProvider provideGetRevisionText
394 */
395 public function testGetRevisionText( $expected, $rowData, $prefix = 'old_', $wiki = false ) {
396 $this->assertEquals(
397 $expected,
398 Revision::getRevisionText( (object)$rowData, $prefix, $wiki ) );
399 }
400
401 public function provideGetRevisionTextWithZlibExtension() {
402 yield 'Generic gzip test' => [
403 'This is a small goat of revision text.',
404 [
405 'old_flags' => 'gzip',
406 'old_text' => gzdeflate( 'This is a small goat of revision text.' ),
407 ],
408 ];
409 }
410
411 /**
412 * @covers Revision::getRevisionText
413 * @dataProvider provideGetRevisionTextWithZlibExtension
414 */
415 public function testGetRevisionWithZlibExtension( $expected, $rowData ) {
416 $this->checkPHPExtension( 'zlib' );
417 $this->testGetRevisionText( $expected, $rowData );
418 }
419
420 private function getWANObjectCache() {
421 return new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
422 }
423
424 /**
425 * @return SqlBlobStore
426 */
427 private function getBlobStore() {
428 /** @var LoadBalancer $lb */
429 $lb = $this->getMockBuilder( LoadBalancer::class )
430 ->disableOriginalConstructor()
431 ->getMock();
432
433 $cache = $this->getWANObjectCache();
434
435 $blobStore = new SqlBlobStore( $lb, $cache );
436 return $blobStore;
437 }
438
439 private function mockBlobStoreFactory( $blobStore ) {
440 /** @var LoadBalancer $lb */
441 $factory = $this->getMockBuilder( BlobStoreFactory::class )
442 ->disableOriginalConstructor()
443 ->getMock();
444 $factory->expects( $this->any() )
445 ->method( 'newBlobStore' )
446 ->willReturn( $blobStore );
447 $factory->expects( $this->any() )
448 ->method( 'newSqlBlobStore' )
449 ->willReturn( $blobStore );
450 return $factory;
451 }
452
453 /**
454 * @return RevisionStore
455 */
456 private function getRevisionStore() {
457 /** @var LoadBalancer $lb */
458 $lb = $this->getMockBuilder( LoadBalancer::class )
459 ->disableOriginalConstructor()
460 ->getMock();
461
462 $cache = $this->getWANObjectCache();
463
464 $blobStore = new RevisionStore( $lb, $this->getBlobStore(), $cache );
465 return $blobStore;
466 }
467
468 public function provideGetRevisionTextWithLegacyEncoding() {
469 yield 'Utf8Native' => [
470 "Wiki est l'\xc3\xa9cole superieur !",
471 'fr',
472 'iso-8859-1',
473 [
474 'old_flags' => 'utf-8',
475 'old_text' => "Wiki est l'\xc3\xa9cole superieur !",
476 ]
477 ];
478 yield 'Utf8Legacy' => [
479 "Wiki est l'\xc3\xa9cole superieur !",
480 'fr',
481 'iso-8859-1',
482 [
483 'old_flags' => '',
484 'old_text' => "Wiki est l'\xe9cole superieur !",
485 ]
486 ];
487 }
488
489 /**
490 * @covers Revision::getRevisionText
491 * @dataProvider provideGetRevisionTextWithLegacyEncoding
492 */
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 ) );
497
498 $this->testGetRevisionText( $expected, $rowData );
499 }
500
501 public function provideGetRevisionTextWithGzipAndLegacyEncoding() {
502 /**
503 * WARNING!
504 * Do not set the external flag!
505 * Otherwise, getRevisionText will hit the live database (if ExternalStore is enabled)!
506 */
507 yield 'Utf8NativeGzip' => [
508 "Wiki est l'\xc3\xa9cole superieur !",
509 'fr',
510 'iso-8859-1',
511 [
512 'old_flags' => 'gzip,utf-8',
513 'old_text' => gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" ),
514 ]
515 ];
516 yield 'Utf8LegacyGzip' => [
517 "Wiki est l'\xc3\xa9cole superieur !",
518 'fr',
519 'iso-8859-1',
520 [
521 'old_flags' => 'gzip',
522 'old_text' => gzdeflate( "Wiki est l'\xe9cole superieur !" ),
523 ]
524 ];
525 }
526
527 /**
528 * @covers Revision::getRevisionText
529 * @dataProvider provideGetRevisionTextWithGzipAndLegacyEncoding
530 */
531 public function testGetRevisionWithGzipAndLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
532 $this->checkPHPExtension( 'zlib' );
533
534 $blobStore = $this->getBlobStore();
535 $blobStore->setLegacyEncoding( $encoding, Language::factory( $lang ) );
536 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
537
538 $this->testGetRevisionText( $expected, $rowData );
539 }
540
541 /**
542 * @covers Revision::compressRevisionText
543 */
544 public function testCompressRevisionTextUtf8() {
545 $row = new stdClass;
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" );
556 }
557
558 /**
559 * @covers Revision::compressRevisionText
560 */
561 public function testCompressRevisionTextUtf8Gzip() {
562 $this->checkPHPExtension( 'zlib' );
563
564 $blobStore = $this->getBlobStore();
565 $blobStore->setCompressBlobs( true );
566 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
567
568 $row = new stdClass;
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" );
579 }
580
581 /**
582 * @covers Revision::loadFromTitle
583 */
584 public function testLoadFromTitle() {
585 $title = $this->getMockTitle();
586
587 $conditions = [
588 'rev_id=page_latest',
589 'page_namespace' => $title->getNamespace(),
590 'page_title' => $title->getDBkey()
591 ];
592
593 $row = (object)[
594 'rev_id' => '42',
595 'rev_page' => $title->getArticleID(),
596 'rev_text_id' => '2',
597 'rev_timestamp' => '20171017114835',
598 'rev_user_text' => '127.0.0.1',
599 'rev_user' => '0',
600 'rev_minor_edit' => '0',
601 'rev_deleted' => '0',
602 'rev_len' => '46',
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',
610 ];
611
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' )
618 ->with(
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 ),
623 // Method name
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' )
629 )
630 ->willReturn( $row );
631
632 $revision = Revision::loadFromTitle( $db, $title );
633
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() );
642 }
643
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',
651 ];
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,
655 ];
656 yield '(no legacy encoding), serialized object in with object flag returns string' => [
657 false,
658 // Using a TitleValue object as it has a getText method (which is needed)
659 serialize( new TitleValue( 0, 'HHJJDDFF' ) ),
660 [ 'object' ],
661 'HHJJDDFF',
662 ];
663 yield '(no legacy encoding), serialized object in with object & gzip flag returns string' => [
664 false,
665 // Using a TitleValue object as it has a getText method (which is needed)
666 gzdeflate( serialize( new TitleValue( 0, '8219JJJ840' ) ) ),
667 [ 'object', 'gzip' ],
668 '8219JJJ840',
669 ];
670 yield '(ISO-8859-1 encoding), string in string out' => [
671 'ISO-8859-1',
672 iconv( 'utf-8', 'ISO-8859-1', "1®Àþ1" ),
673 [],
674 '1®Àþ1',
675 ];
676 yield '(ISO-8859-1 encoding), serialized object in with gzip flags returns string' => [
677 'ISO-8859-1',
678 gzdeflate( iconv( 'utf-8', 'ISO-8859-1', "4®Àþ4" ) ),
679 [ 'gzip' ],
680 '4®Àþ4',
681 ];
682 yield '(ISO-8859-1 encoding), serialized object in with object flags returns string' => [
683 'ISO-8859-1',
684 serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "3®Àþ3" ) ) ),
685 [ 'object' ],
686 '3®Àþ3',
687 ];
688 yield '(ISO-8859-1 encoding), serialized object in with object & gzip flags returns string' => [
689 'ISO-8859-1',
690 gzdeflate( serialize( new TitleValue( 0, iconv( 'utf-8', 'ISO-8859-1', "2®Àþ2" ) ) ) ),
691 [ 'gzip', 'object' ],
692 '2®Àþ2',
693 ];
694 }
695
696 /**
697 * @dataProvider provideDecompressRevisionText
698 * @covers Revision::decompressRevisionText
699 *
700 * @param bool $legacyEncoding
701 * @param mixed $text
702 * @param array $flags
703 * @param mixed $expected
704 */
705 public function testDecompressRevisionText( $legacyEncoding, $text, $flags, $expected ) {
706 $blobStore = $this->getBlobStore();
707 if ( $legacyEncoding ) {
708 $blobStore->setLegacyEncoding( $legacyEncoding, Language::factory( 'en' ) );
709 }
710
711 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
712 $this->assertSame(
713 $expected,
714 Revision::decompressRevisionText( $text, $flags )
715 );
716 }
717
718 /**
719 * @covers Revision::getRevisionText
720 */
721 public function testGetRevisionText_returnsFalseWhenNoTextField() {
722 $this->assertFalse( Revision::getRevisionText( new stdClass() ) );
723 }
724
725 public function provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal() {
726 yield 'Just text' => [
727 (object)[ 'old_text' => 'SomeText' ],
728 'old_',
729 'SomeText'
730 ];
731 // gzip string below generated with gzdeflate( 'AAAABBAAA' )
732 yield 'gzip text' => [
733 (object)[
734 'old_text' => "sttttr\002\022\000",
735 'old_flags' => 'gzip'
736 ],
737 'old_',
738 'AAAABBAAA'
739 ];
740 yield 'gzip text and different prefix' => [
741 (object)[
742 'jojo_text' => "sttttr\002\022\000",
743 'jojo_flags' => 'gzip'
744 ],
745 'jojo_',
746 'AAAABBAAA'
747 ];
748 }
749
750 /**
751 * @dataProvider provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal
752 * @covers Revision::getRevisionText
753 */
754 public function testGetRevisionText_returnsDecompressedTextFieldWhenNotExternal(
755 $row,
756 $prefix,
757 $expected
758 ) {
759 $this->assertSame( $expected, Revision::getRevisionText( $row, $prefix ) );
760 }
761
762 public function provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts() {
763 yield 'Just some text' => [ 'someNonUrlText' ];
764 yield 'No second URL part' => [ 'someProtocol://' ];
765 }
766
767 /**
768 * @dataProvider provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts
769 * @covers Revision::getRevisionText
770 */
771 public function testGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts(
772 $text
773 ) {
774 $this->assertFalse(
775 Revision::getRevisionText(
776 (object)[
777 'old_text' => $text,
778 'old_flags' => 'external',
779 ]
780 )
781 );
782 }
783
784 /**
785 * @covers Revision::getRevisionText
786 */
787 public function testGetRevisionText_external_noOldId() {
788 $this->setService(
789 'ExternalStoreFactory',
790 new ExternalStoreFactory( [ 'ForTesting' ] )
791 );
792 $this->assertSame(
793 'AAAABBAAA',
794 Revision::getRevisionText(
795 (object)[
796 'old_text' => 'ForTesting://cluster1/12345',
797 'old_flags' => 'external,gzip',
798 ]
799 )
800 );
801 }
802
803 /**
804 * @covers Revision::getRevisionText
805 */
806 public function testGetRevisionText_external_oldId() {
807 $cache = $this->getWANObjectCache();
808 $this->setService( 'MainWANObjectCache', $cache );
809
810 $this->setService(
811 'ExternalStoreFactory',
812 new ExternalStoreFactory( [ 'ForTesting' ] )
813 );
814
815 $lb = $this->getMockBuilder( LoadBalancer::class )
816 ->disableOriginalConstructor()
817 ->getMock();
818
819 $blobStore = new SqlBlobStore( $lb, $cache );
820 $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
821
822 $this->assertSame(
823 'AAAABBAAA',
824 Revision::getRevisionText(
825 (object)[
826 'old_text' => 'ForTesting://cluster1/12345',
827 'old_flags' => 'external,gzip',
828 'old_id' => '7777',
829 ]
830 )
831 );
832
833 $cacheKey = $cache->makeKey( 'revisiontext', 'textid', 'tt:7777' );
834 $this->assertSame( 'AAAABBAAA', $cache->get( $cacheKey ) );
835 }
836
837 /**
838 * @covers Revision::userJoinCond
839 */
840 public function testUserJoinCond() {
841 $this->hideDeprecated( 'Revision::userJoinCond' );
842 $this->assertEquals(
843 [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
844 Revision::userJoinCond()
845 );
846 }
847
848 /**
849 * @covers Revision::pageJoinCond
850 */
851 public function testPageJoinCond() {
852 $this->hideDeprecated( 'Revision::pageJoinCond' );
853 $this->assertEquals(
854 [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
855 Revision::pageJoinCond()
856 );
857 }
858
859 public function provideSelectFields() {
860 yield [
861 true,
862 [
863 'rev_id',
864 'rev_page',
865 'rev_text_id',
866 'rev_timestamp',
867 'rev_user_text',
868 'rev_user',
869 'rev_minor_edit',
870 'rev_deleted',
871 'rev_len',
872 'rev_parent_id',
873 'rev_sha1',
874 'rev_comment_text' => 'rev_comment',
875 'rev_comment_data' => 'NULL',
876 'rev_comment_cid' => 'NULL',
877 'rev_content_format',
878 'rev_content_model',
879 ]
880 ];
881 yield [
882 false,
883 [
884 'rev_id',
885 'rev_page',
886 'rev_text_id',
887 'rev_timestamp',
888 'rev_user_text',
889 'rev_user',
890 'rev_minor_edit',
891 'rev_deleted',
892 'rev_len',
893 'rev_parent_id',
894 'rev_sha1',
895 'rev_comment_text' => 'rev_comment',
896 'rev_comment_data' => 'NULL',
897 'rev_comment_cid' => 'NULL',
898 ]
899 ];
900 }
901
902 /**
903 * @dataProvider provideSelectFields
904 * @covers Revision::selectFields
905 * @todo a true unit test would mock CommentStore
906 */
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() );
912 }
913
914 public function provideSelectArchiveFields() {
915 yield [
916 true,
917 [
918 'ar_id',
919 'ar_page_id',
920 'ar_rev_id',
921 'ar_text',
922 'ar_text_id',
923 'ar_timestamp',
924 'ar_user_text',
925 'ar_user',
926 'ar_minor_edit',
927 'ar_deleted',
928 'ar_len',
929 'ar_parent_id',
930 'ar_sha1',
931 'ar_comment_text' => 'ar_comment',
932 'ar_comment_data' => 'NULL',
933 'ar_comment_cid' => 'NULL',
934 'ar_content_format',
935 'ar_content_model',
936 ]
937 ];
938 yield [
939 false,
940 [
941 'ar_id',
942 'ar_page_id',
943 'ar_rev_id',
944 'ar_text',
945 'ar_text_id',
946 'ar_timestamp',
947 'ar_user_text',
948 'ar_user',
949 'ar_minor_edit',
950 'ar_deleted',
951 'ar_len',
952 'ar_parent_id',
953 'ar_sha1',
954 'ar_comment_text' => 'ar_comment',
955 'ar_comment_data' => 'NULL',
956 'ar_comment_cid' => 'NULL',
957 ]
958 ];
959 }
960
961 /**
962 * @dataProvider provideSelectArchiveFields
963 * @covers Revision::selectArchiveFields
964 * @todo a true unit test would mock CommentStore
965 */
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() );
971 }
972
973 /**
974 * @covers Revision::selectTextFields
975 */
976 public function testSelectTextFields() {
977 $this->hideDeprecated( 'Revision::selectTextFields' );
978 $this->assertEquals(
979 [
980 'old_text',
981 'old_flags',
982 ],
983 Revision::selectTextFields()
984 );
985 }
986
987 /**
988 * @covers Revision::selectPageFields
989 */
990 public function testSelectPageFields() {
991 $this->hideDeprecated( 'Revision::selectPageFields' );
992 $this->assertEquals(
993 [
994 'page_namespace',
995 'page_title',
996 'page_id',
997 'page_latest',
998 'page_is_redirect',
999 'page_len',
1000 ],
1001 Revision::selectPageFields()
1002 );
1003 }
1004
1005 /**
1006 * @covers Revision::selectUserFields
1007 */
1008 public function testSelectUserFields() {
1009 $this->hideDeprecated( 'Revision::selectUserFields' );
1010 $this->assertEquals(
1011 [
1012 'user_name',
1013 ],
1014 Revision::selectUserFields()
1015 );
1016 }
1017
1018 public function provideGetArchiveQueryInfo() {
1019 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD' => [
1020 [
1021 'wgContentHandlerUseDB' => false,
1022 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
1023 ],
1024 [
1025 'tables' => [ 'archive' ],
1026 'fields' => [
1027 'ar_id',
1028 'ar_page_id',
1029 'ar_namespace',
1030 'ar_title',
1031 'ar_rev_id',
1032 'ar_text',
1033 'ar_text_id',
1034 'ar_timestamp',
1035 'ar_user_text',
1036 'ar_user',
1037 'ar_minor_edit',
1038 'ar_deleted',
1039 'ar_len',
1040 'ar_parent_id',
1041 'ar_sha1',
1042 'ar_comment_text' => 'ar_comment',
1043 'ar_comment_data' => 'NULL',
1044 'ar_comment_cid' => 'NULL',
1045 ],
1046 'joins' => [],
1047 ]
1048 ];
1049 yield 'wgContentHandlerUseDB true, wgCommentTableSchemaMigrationStage OLD' => [
1050 [
1051 'wgContentHandlerUseDB' => true,
1052 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
1053 ],
1054 [
1055 'tables' => [ 'archive' ],
1056 'fields' => [
1057 'ar_id',
1058 'ar_page_id',
1059 'ar_namespace',
1060 'ar_title',
1061 'ar_rev_id',
1062 'ar_text',
1063 'ar_text_id',
1064 'ar_timestamp',
1065 'ar_user_text',
1066 'ar_user',
1067 'ar_minor_edit',
1068 'ar_deleted',
1069 'ar_len',
1070 'ar_parent_id',
1071 'ar_sha1',
1072 'ar_comment_text' => 'ar_comment',
1073 'ar_comment_data' => 'NULL',
1074 'ar_comment_cid' => 'NULL',
1075 'ar_content_format',
1076 'ar_content_model',
1077 ],
1078 'joins' => [],
1079 ]
1080 ];
1081 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_BOTH' => [
1082 [
1083 'wgContentHandlerUseDB' => false,
1084 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH,
1085 ],
1086 [
1087 'tables' => [
1088 'archive',
1089 'comment_ar_comment' => 'comment',
1090 ],
1091 'fields' => [
1092 'ar_id',
1093 'ar_page_id',
1094 'ar_namespace',
1095 'ar_title',
1096 'ar_rev_id',
1097 'ar_text',
1098 'ar_text_id',
1099 'ar_timestamp',
1100 'ar_user_text',
1101 'ar_user',
1102 'ar_minor_edit',
1103 'ar_deleted',
1104 'ar_len',
1105 'ar_parent_id',
1106 'ar_sha1',
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',
1110 ],
1111 'joins' => [
1112 'comment_ar_comment' => [
1113 'LEFT JOIN',
1114 'comment_ar_comment.comment_id = ar_comment_id',
1115 ],
1116 ],
1117 ]
1118 ];
1119 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_NEW' => [
1120 [
1121 'wgContentHandlerUseDB' => false,
1122 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW,
1123 ],
1124 [
1125 'tables' => [
1126 'archive',
1127 'comment_ar_comment' => 'comment',
1128 ],
1129 'fields' => [
1130 'ar_id',
1131 'ar_page_id',
1132 'ar_namespace',
1133 'ar_title',
1134 'ar_rev_id',
1135 'ar_text',
1136 'ar_text_id',
1137 'ar_timestamp',
1138 'ar_user_text',
1139 'ar_user',
1140 'ar_minor_edit',
1141 'ar_deleted',
1142 'ar_len',
1143 'ar_parent_id',
1144 'ar_sha1',
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',
1148 ],
1149 'joins' => [
1150 'comment_ar_comment' => [
1151 'LEFT JOIN',
1152 'comment_ar_comment.comment_id = ar_comment_id',
1153 ],
1154 ],
1155 ]
1156 ];
1157 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage NEW' => [
1158 [
1159 'wgContentHandlerUseDB' => false,
1160 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW,
1161 ],
1162 [
1163 'tables' => [
1164 'archive',
1165 'comment_ar_comment' => 'comment',
1166 ],
1167 'fields' => [
1168 'ar_id',
1169 'ar_page_id',
1170 'ar_namespace',
1171 'ar_title',
1172 'ar_rev_id',
1173 'ar_text',
1174 'ar_text_id',
1175 'ar_timestamp',
1176 'ar_user_text',
1177 'ar_user',
1178 'ar_minor_edit',
1179 'ar_deleted',
1180 'ar_len',
1181 'ar_parent_id',
1182 'ar_sha1',
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',
1186 ],
1187 'joins' => [
1188 'comment_ar_comment' => [
1189 'JOIN',
1190 'comment_ar_comment.comment_id = ar_comment_id',
1191 ],
1192 ],
1193 ]
1194 ];
1195 }
1196
1197 /**
1198 * @covers Revision::getArchiveQueryInfo
1199 * @dataProvider provideGetArchiveQueryInfo
1200 */
1201 public function testGetArchiveQueryInfo( $globals, $expected ) {
1202 $this->setMwGlobals( $globals );
1203
1204 $revisionStore = $this->getRevisionStore();
1205 $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
1206 $this->setService( 'RevisionStore', $revisionStore );
1207
1208 $this->assertEquals(
1209 $expected,
1210 Revision::getArchiveQueryInfo()
1211 );
1212 }
1213
1214 public function provideGetQueryInfo() {
1215 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts none' => [
1216 [
1217 'wgContentHandlerUseDB' => false,
1218 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
1219 ],
1220 [],
1221 [
1222 'tables' => [ 'revision' ],
1223 'fields' => [
1224 'rev_id',
1225 'rev_page',
1226 'rev_text_id',
1227 'rev_timestamp',
1228 'rev_user_text',
1229 'rev_user',
1230 'rev_minor_edit',
1231 'rev_deleted',
1232 'rev_len',
1233 'rev_parent_id',
1234 'rev_sha1',
1235 'rev_comment_text' => 'rev_comment',
1236 'rev_comment_data' => 'NULL',
1237 'rev_comment_cid' => 'NULL',
1238 ],
1239 'joins' => [],
1240 ],
1241 ];
1242 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts page' => [
1243 [
1244 'wgContentHandlerUseDB' => false,
1245 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
1246 ],
1247 [ 'page' ],
1248 [
1249 'tables' => [ 'revision', 'page' ],
1250 'fields' => [
1251 'rev_id',
1252 'rev_page',
1253 'rev_text_id',
1254 'rev_timestamp',
1255 'rev_user_text',
1256 'rev_user',
1257 'rev_minor_edit',
1258 'rev_deleted',
1259 'rev_len',
1260 'rev_parent_id',
1261 'rev_sha1',
1262 'rev_comment_text' => 'rev_comment',
1263 'rev_comment_data' => 'NULL',
1264 'rev_comment_cid' => 'NULL',
1265 'page_namespace',
1266 'page_title',
1267 'page_id',
1268 'page_latest',
1269 'page_is_redirect',
1270 'page_len',
1271 ],
1272 'joins' => [
1273 'page' => [
1274 'INNER JOIN',
1275 [ 'page_id = rev_page' ],
1276 ],
1277 ],
1278 ],
1279 ];
1280 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts user' => [
1281 [
1282 'wgContentHandlerUseDB' => false,
1283 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
1284 ],
1285 [ 'user' ],
1286 [
1287 'tables' => [ 'revision', 'user' ],
1288 'fields' => [
1289 'rev_id',
1290 'rev_page',
1291 'rev_text_id',
1292 'rev_timestamp',
1293 'rev_user_text',
1294 'rev_user',
1295 'rev_minor_edit',
1296 'rev_deleted',
1297 'rev_len',
1298 'rev_parent_id',
1299 'rev_sha1',
1300 'rev_comment_text' => 'rev_comment',
1301 'rev_comment_data' => 'NULL',
1302 'rev_comment_cid' => 'NULL',
1303 'user_name',
1304 ],
1305 'joins' => [
1306 'user' => [
1307 'LEFT JOIN',
1308 [
1309 'rev_user != 0',
1310 'user_id = rev_user',
1311 ],
1312 ],
1313 ],
1314 ],
1315 ];
1316 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts text' => [
1317 [
1318 'wgContentHandlerUseDB' => false,
1319 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
1320 ],
1321 [ 'text' ],
1322 [
1323 'tables' => [ 'revision', 'text' ],
1324 'fields' => [
1325 'rev_id',
1326 'rev_page',
1327 'rev_text_id',
1328 'rev_timestamp',
1329 'rev_user_text',
1330 'rev_user',
1331 'rev_minor_edit',
1332 'rev_deleted',
1333 'rev_len',
1334 'rev_parent_id',
1335 'rev_sha1',
1336 'rev_comment_text' => 'rev_comment',
1337 'rev_comment_data' => 'NULL',
1338 'rev_comment_cid' => 'NULL',
1339 'old_text',
1340 'old_flags',
1341 ],
1342 'joins' => [
1343 'text' => [
1344 'INNER JOIN',
1345 [ 'rev_text_id=old_id' ],
1346 ],
1347 ],
1348 ],
1349 ];
1350 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD, opts 3' => [
1351 [
1352 'wgContentHandlerUseDB' => false,
1353 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
1354 ],
1355 [ 'text', 'page', 'user' ],
1356 [
1357 'tables' => [ 'revision', 'page', 'user', 'text' ],
1358 'fields' => [
1359 'rev_id',
1360 'rev_page',
1361 'rev_text_id',
1362 'rev_timestamp',
1363 'rev_user_text',
1364 'rev_user',
1365 'rev_minor_edit',
1366 'rev_deleted',
1367 'rev_len',
1368 'rev_parent_id',
1369 'rev_sha1',
1370 'rev_comment_text' => 'rev_comment',
1371 'rev_comment_data' => 'NULL',
1372 'rev_comment_cid' => 'NULL',
1373 'page_namespace',
1374 'page_title',
1375 'page_id',
1376 'page_latest',
1377 'page_is_redirect',
1378 'page_len',
1379 'user_name',
1380 'old_text',
1381 'old_flags',
1382 ],
1383 'joins' => [
1384 'page' => [
1385 'INNER JOIN',
1386 [ 'page_id = rev_page' ],
1387 ],
1388 'user' => [
1389 'LEFT JOIN',
1390 [
1391 'rev_user != 0',
1392 'user_id = rev_user',
1393 ],
1394 ],
1395 'text' => [
1396 'INNER JOIN',
1397 [ 'rev_text_id=old_id' ],
1398 ],
1399 ],
1400 ],
1401 ];
1402 yield 'wgContentHandlerUseDB true, wgCommentTableSchemaMigrationStage OLD, opts none' => [
1403 [
1404 'wgContentHandlerUseDB' => true,
1405 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
1406 ],
1407 [],
1408 [
1409 'tables' => [ 'revision' ],
1410 'fields' => [
1411 'rev_id',
1412 'rev_page',
1413 'rev_text_id',
1414 'rev_timestamp',
1415 'rev_user_text',
1416 'rev_user',
1417 'rev_minor_edit',
1418 'rev_deleted',
1419 'rev_len',
1420 'rev_parent_id',
1421 'rev_sha1',
1422 'rev_comment_text' => 'rev_comment',
1423 'rev_comment_data' => 'NULL',
1424 'rev_comment_cid' => 'NULL',
1425 'rev_content_format',
1426 'rev_content_model',
1427 ],
1428 'joins' => [],
1429 ],
1430 ];
1431 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_BOTH, opts none' => [
1432 [
1433 'wgContentHandlerUseDB' => false,
1434 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH,
1435 ],
1436 [],
1437 [
1438 'tables' => [
1439 'revision',
1440 'temp_rev_comment' => 'revision_comment_temp',
1441 'comment_rev_comment' => 'comment',
1442 ],
1443 'fields' => [
1444 'rev_id',
1445 'rev_page',
1446 'rev_text_id',
1447 'rev_timestamp',
1448 'rev_user_text',
1449 'rev_user',
1450 'rev_minor_edit',
1451 'rev_deleted',
1452 'rev_len',
1453 'rev_parent_id',
1454 'rev_sha1',
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',
1458 ],
1459 'joins' => [
1460 'temp_rev_comment' => [
1461 'LEFT JOIN',
1462 'temp_rev_comment.revcomment_rev = rev_id',
1463 ],
1464 'comment_rev_comment' => [
1465 'LEFT JOIN',
1466 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
1467 ],
1468 ],
1469 ],
1470 ];
1471 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_NEW, opts none' => [
1472 [
1473 'wgContentHandlerUseDB' => false,
1474 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW,
1475 ],
1476 [],
1477 [
1478 'tables' => [
1479 'revision',
1480 'temp_rev_comment' => 'revision_comment_temp',
1481 'comment_rev_comment' => 'comment',
1482 ],
1483 'fields' => [
1484 'rev_id',
1485 'rev_page',
1486 'rev_text_id',
1487 'rev_timestamp',
1488 'rev_user_text',
1489 'rev_user',
1490 'rev_minor_edit',
1491 'rev_deleted',
1492 'rev_len',
1493 'rev_parent_id',
1494 'rev_sha1',
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',
1498 ],
1499 'joins' => [
1500 'temp_rev_comment' => [
1501 'LEFT JOIN',
1502 'temp_rev_comment.revcomment_rev = rev_id',
1503 ],
1504 'comment_rev_comment' => [
1505 'LEFT JOIN',
1506 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
1507 ],
1508 ],
1509 ],
1510 ];
1511 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage NEW, opts none' => [
1512 [
1513 'wgContentHandlerUseDB' => false,
1514 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW,
1515 ],
1516 [],
1517 [
1518 'tables' => [
1519 'revision',
1520 'temp_rev_comment' => 'revision_comment_temp',
1521 'comment_rev_comment' => 'comment',
1522 ],
1523 'fields' => [
1524 'rev_id',
1525 'rev_page',
1526 'rev_text_id',
1527 'rev_timestamp',
1528 'rev_user_text',
1529 'rev_user',
1530 'rev_minor_edit',
1531 'rev_deleted',
1532 'rev_len',
1533 'rev_parent_id',
1534 'rev_sha1',
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',
1538 ],
1539 'joins' => [
1540 'temp_rev_comment' => [
1541 'JOIN',
1542 'temp_rev_comment.revcomment_rev = rev_id',
1543 ],
1544 'comment_rev_comment' => [
1545 'JOIN',
1546 'comment_rev_comment.comment_id = temp_rev_comment.revcomment_comment_id',
1547 ],
1548 ],
1549 ],
1550 ];
1551 }
1552
1553 /**
1554 * @covers Revision::getQueryInfo
1555 * @dataProvider provideGetQueryInfo
1556 */
1557 public function testGetQueryInfo( $globals, $options, $expected ) {
1558 $this->setMwGlobals( $globals );
1559
1560 $revisionStore = $this->getRevisionStore();
1561 $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] );
1562 $this->setService( 'RevisionStore', $revisionStore );
1563
1564 $this->assertEquals(
1565 $expected,
1566 Revision::getQueryInfo( $options )
1567 );
1568 }
1569
1570 }