[MCR] tests for Revision::getArchiveQueryInfo
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionTest.php
1 <?php
2
3 use Wikimedia\TestingAccessWrapper;
4
5 /**
6 * Test cases in RevisionTest should not interact with the Database.
7 * For test cases that need Database interaction see RevisionDbTestBase.
8 */
9 class RevisionTest extends MediaWikiTestCase {
10
11 public function provideConstructFromArray() {
12 yield 'with text' => [
13 [
14 'text' => 'hello world.',
15 'content_model' => CONTENT_MODEL_JAVASCRIPT
16 ],
17 ];
18 yield 'with content' => [
19 [
20 'content' => new JavaScriptContent( 'hellow world.' )
21 ],
22 ];
23 }
24
25 /**
26 * @dataProvider provideConstructFromArray
27 * @covers Revision::__construct
28 * @covers Revision::constructFromRowArray
29 */
30 public function testConstructFromArray( array $rowArray ) {
31 $rev = new Revision( $rowArray );
32 $this->assertNotNull( $rev->getContent(), 'no content object available' );
33 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContent()->getModel() );
34 $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
35 }
36
37 public function provideConstructFromArrayThrowsExceptions() {
38 yield 'content and text_id both not empty' => [
39 [
40 'content' => new WikitextContent( 'GOAT' ),
41 'text_id' => 'someid',
42 ],
43 new MWException( "Text already stored in external store (id someid), " .
44 "can't serialize content object" )
45 ];
46 yield 'with bad content object (class)' => [
47 [ 'content' => new stdClass() ],
48 new MWException( '`content` field must contain a Content object.' )
49 ];
50 yield 'with bad content object (string)' => [
51 [ 'content' => 'ImAGoat' ],
52 new MWException( '`content` field must contain a Content object.' )
53 ];
54 yield 'bad row format' => [
55 'imastring, not a row',
56 new MWException( 'Revision constructor passed invalid row format.' )
57 ];
58 }
59
60 /**
61 * @dataProvider provideConstructFromArrayThrowsExceptions
62 * @covers Revision::__construct
63 * @covers Revision::constructFromRowArray
64 */
65 public function testConstructFromArrayThrowsExceptions( $rowArray, Exception $expectedException ) {
66 $this->setExpectedException(
67 get_class( $expectedException ),
68 $expectedException->getMessage(),
69 $expectedException->getCode()
70 );
71 new Revision( $rowArray );
72 }
73
74 public function provideConstructFromRow() {
75 yield 'Full construction' => [
76 [
77 'rev_id' => '2',
78 'rev_page' => '1',
79 'rev_text_id' => '2',
80 'rev_timestamp' => '20171017114835',
81 'rev_user_text' => '127.0.0.1',
82 'rev_user' => '0',
83 'rev_minor_edit' => '0',
84 'rev_deleted' => '0',
85 'rev_len' => '46',
86 'rev_parent_id' => '1',
87 'rev_sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
88 'rev_comment_text' => 'Goat Comment!',
89 'rev_comment_data' => null,
90 'rev_comment_cid' => null,
91 'rev_content_format' => 'GOATFORMAT',
92 'rev_content_model' => 'GOATMODEL',
93 ],
94 function ( RevisionTest $testCase, Revision $rev ) {
95 $testCase->assertSame( 2, $rev->getId() );
96 $testCase->assertSame( 1, $rev->getPage() );
97 $testCase->assertSame( 2, $rev->getTextId() );
98 $testCase->assertSame( '20171017114835', $rev->getTimestamp() );
99 $testCase->assertSame( '127.0.0.1', $rev->getUserText() );
100 $testCase->assertSame( 0, $rev->getUser() );
101 $testCase->assertSame( false, $rev->isMinor() );
102 $testCase->assertSame( false, $rev->isDeleted( Revision::DELETED_TEXT ) );
103 $testCase->assertSame( 46, $rev->getSize() );
104 $testCase->assertSame( 1, $rev->getParentId() );
105 $testCase->assertSame( 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z', $rev->getSha1() );
106 $testCase->assertSame( 'Goat Comment!', $rev->getComment() );
107 $testCase->assertSame( 'GOATFORMAT', $rev->getContentFormat() );
108 $testCase->assertSame( 'GOATMODEL', $rev->getContentModel() );
109 }
110 ];
111 yield 'null fields' => [
112 [
113 'rev_id' => '2',
114 'rev_page' => '1',
115 'rev_text_id' => '2',
116 'rev_timestamp' => '20171017114835',
117 'rev_user_text' => '127.0.0.1',
118 'rev_user' => '0',
119 'rev_minor_edit' => '0',
120 'rev_deleted' => '0',
121 'rev_comment_text' => 'Goat Comment!',
122 'rev_comment_data' => null,
123 'rev_comment_cid' => null,
124 ],
125 function ( RevisionTest $testCase, Revision $rev ) {
126 $testCase->assertNull( $rev->getSize() );
127 $testCase->assertNull( $rev->getParentId() );
128 $testCase->assertNull( $rev->getSha1() );
129 $testCase->assertSame( 'text/x-wiki', $rev->getContentFormat() );
130 $testCase->assertSame( 'wikitext', $rev->getContentModel() );
131 }
132 ];
133 }
134
135 /**
136 * @dataProvider provideConstructFromRow
137 * @covers Revision::__construct
138 * @covers Revision::constructFromDbRowObject
139 */
140 public function testConstructFromRow( array $arrayData, $assertions ) {
141 $row = (object)$arrayData;
142 $rev = new Revision( $row );
143 $assertions( $this, $rev );
144 }
145
146 public function provideGetRevisionText() {
147 yield 'Generic test' => [
148 'This is a goat of revision text.',
149 [
150 'old_flags' => '',
151 'old_text' => 'This is a goat of revision text.',
152 ],
153 ];
154 }
155
156 public function provideGetId() {
157 yield [
158 [],
159 null
160 ];
161 yield [
162 [ 'id' => 998 ],
163 998
164 ];
165 }
166
167 /**
168 * @dataProvider provideGetId
169 * @covers Revision::getId
170 */
171 public function testGetId( $rowArray, $expectedId ) {
172 $rev = new Revision( $rowArray );
173 $this->assertEquals( $expectedId, $rev->getId() );
174 }
175
176 public function provideSetId() {
177 yield [ '123', 123 ];
178 yield [ 456, 456 ];
179 }
180
181 /**
182 * @dataProvider provideSetId
183 * @covers Revision::setId
184 */
185 public function testSetId( $input, $expected ) {
186 $rev = new Revision( [] );
187 $rev->setId( $input );
188 $this->assertSame( $expected, $rev->getId() );
189 }
190
191 public function provideSetUserIdAndName() {
192 yield [ '123', 123, 'GOaT' ];
193 yield [ 456, 456, 'GOaT' ];
194 }
195
196 /**
197 * @dataProvider provideSetUserIdAndName
198 * @covers Revision::setUserIdAndName
199 */
200 public function testSetUserIdAndName( $inputId, $expectedId, $name ) {
201 $rev = new Revision( [] );
202 $rev->setUserIdAndName( $inputId, $name );
203 $this->assertSame( $expectedId, $rev->getUser( Revision::RAW ) );
204 $this->assertEquals( $name, $rev->getUserText( Revision::RAW ) );
205 }
206
207 public function provideGetTextId() {
208 yield [ [], null ];
209 yield [ [ 'text_id' => '123' ], 123 ];
210 yield [ [ 'text_id' => 456 ], 456 ];
211 }
212
213 /**
214 * @dataProvider provideGetTextId
215 * @covers Revision::getTextId()
216 */
217 public function testGetTextId( $rowArray, $expected ) {
218 $rev = new Revision( $rowArray );
219 $this->assertSame( $expected, $rev->getTextId() );
220 }
221
222 public function provideGetParentId() {
223 yield [ [], null ];
224 yield [ [ 'parent_id' => '123' ], 123 ];
225 yield [ [ 'parent_id' => 456 ], 456 ];
226 }
227
228 /**
229 * @dataProvider provideGetParentId
230 * @covers Revision::getParentId()
231 */
232 public function testGetParentId( $rowArray, $expected ) {
233 $rev = new Revision( $rowArray );
234 $this->assertSame( $expected, $rev->getParentId() );
235 }
236
237 /**
238 * @covers Revision::getRevisionText
239 * @dataProvider provideGetRevisionText
240 */
241 public function testGetRevisionText( $expected, $rowData, $prefix = 'old_', $wiki = false ) {
242 $this->assertEquals(
243 $expected,
244 Revision::getRevisionText( (object)$rowData, $prefix, $wiki ) );
245 }
246
247 public function provideGetRevisionTextWithZlibExtension() {
248 yield 'Generic gzip test' => [
249 'This is a small goat of revision text.',
250 [
251 'old_flags' => 'gzip',
252 'old_text' => gzdeflate( 'This is a small goat of revision text.' ),
253 ],
254 ];
255 }
256
257 /**
258 * @covers Revision::getRevisionText
259 * @dataProvider provideGetRevisionTextWithZlibExtension
260 */
261 public function testGetRevisionWithZlibExtension( $expected, $rowData ) {
262 $this->checkPHPExtension( 'zlib' );
263 $this->testGetRevisionText( $expected, $rowData );
264 }
265
266 public function provideGetRevisionTextWithLegacyEncoding() {
267 yield 'Utf8Native' => [
268 "Wiki est l'\xc3\xa9cole superieur !",
269 'iso-8859-1',
270 [
271 'old_flags' => 'utf-8',
272 'old_text' => "Wiki est l'\xc3\xa9cole superieur !",
273 ]
274 ];
275 yield 'Utf8Legacy' => [
276 "Wiki est l'\xc3\xa9cole superieur !",
277 'iso-8859-1',
278 [
279 'old_flags' => '',
280 'old_text' => "Wiki est l'\xe9cole superieur !",
281 ]
282 ];
283 }
284
285 /**
286 * @covers Revision::getRevisionText
287 * @dataProvider provideGetRevisionTextWithLegacyEncoding
288 */
289 public function testGetRevisionWithLegacyEncoding( $expected, $encoding, $rowData ) {
290 $this->setMwGlobals( 'wgLegacyEncoding', $encoding );
291 $this->testGetRevisionText( $expected, $rowData );
292 }
293
294 public function provideGetRevisionTextWithGzipAndLegacyEncoding() {
295 /**
296 * WARNING!
297 * Do not set the external flag!
298 * Otherwise, getRevisionText will hit the live database (if ExternalStore is enabled)!
299 */
300 yield 'Utf8NativeGzip' => [
301 "Wiki est l'\xc3\xa9cole superieur !",
302 'iso-8859-1',
303 [
304 'old_flags' => 'gzip,utf-8',
305 'old_text' => gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" ),
306 ]
307 ];
308 yield 'Utf8LegacyGzip' => [
309 "Wiki est l'\xc3\xa9cole superieur !",
310 'iso-8859-1',
311 [
312 'old_flags' => 'gzip',
313 'old_text' => gzdeflate( "Wiki est l'\xe9cole superieur !" ),
314 ]
315 ];
316 }
317
318 /**
319 * @covers Revision::getRevisionText
320 * @dataProvider provideGetRevisionTextWithGzipAndLegacyEncoding
321 */
322 public function testGetRevisionWithGzipAndLegacyEncoding( $expected, $encoding, $rowData ) {
323 $this->checkPHPExtension( 'zlib' );
324 $this->setMwGlobals( 'wgLegacyEncoding', $encoding );
325 $this->testGetRevisionText( $expected, $rowData );
326 }
327
328 /**
329 * @covers Revision::compressRevisionText
330 */
331 public function testCompressRevisionTextUtf8() {
332 $row = new stdClass;
333 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
334 $row->old_flags = Revision::compressRevisionText( $row->old_text );
335 $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
336 "Flags should contain 'utf-8'" );
337 $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ),
338 "Flags should not contain 'gzip'" );
339 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
340 $row->old_text, "Direct check" );
341 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
342 Revision::getRevisionText( $row ), "getRevisionText" );
343 }
344
345 /**
346 * @covers Revision::compressRevisionText
347 */
348 public function testCompressRevisionTextUtf8Gzip() {
349 $this->checkPHPExtension( 'zlib' );
350 $this->setMwGlobals( 'wgCompressRevisions', true );
351
352 $row = new stdClass;
353 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
354 $row->old_flags = Revision::compressRevisionText( $row->old_text );
355 $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
356 "Flags should contain 'utf-8'" );
357 $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ),
358 "Flags should contain 'gzip'" );
359 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
360 gzinflate( $row->old_text ), "Direct check" );
361 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
362 Revision::getRevisionText( $row ), "getRevisionText" );
363 }
364
365 public function provideFetchFromConds() {
366 yield [ 0, [] ];
367 yield [ Revision::READ_LOCKING, [ 'FOR UPDATE' ] ];
368 }
369
370 /**
371 * @dataProvider provideFetchFromConds
372 * @covers Revision::fetchFromConds
373 */
374 public function testFetchFromConds( $flags, array $options ) {
375 $conditions = [ 'conditionsArray' ];
376
377 $db = $this->getMock( IDatabase::class );
378 $db->expects( $this->once() )
379 ->method( 'selectRow' )
380 ->with(
381 $this->equalTo( [ 'revision', 'page', 'user' ] ),
382 // We don't really care about the fields are they come from the selectField methods
383 $this->isType( 'array' ),
384 $this->equalTo( $conditions ),
385 // Method name
386 $this->equalTo( 'Revision::fetchFromConds' ),
387 $this->equalTo( $options ),
388 // We don't really care about the join conds are they come from the joinCond methods
389 $this->isType( 'array' )
390 )
391 ->willReturn( 'RETURNVALUE' );
392
393 $wrapper = TestingAccessWrapper::newFromClass( Revision::class );
394 $result = $wrapper->fetchFromConds( $db, $conditions, $flags );
395
396 $this->assertEquals( 'RETURNVALUE', $result );
397 }
398
399 public function provideDecompressRevisionText() {
400 yield '(no legacy encoding), false in false out' => [ false, false, [], false ];
401 yield '(no legacy encoding), empty in empty out' => [ false, '', [], '' ];
402 yield '(no legacy encoding), empty in empty out' => [ false, 'A', [], 'A' ];
403 yield '(no legacy encoding), string in with gzip flag returns string' => [
404 // gzip string below generated with gzdeflate( 'AAAABBAAA' )
405 false, "sttttr\002\022\000", [ 'gzip' ], 'AAAABBAAA',
406 ];
407 yield '(no legacy encoding), string in with object flag returns false' => [
408 // gzip string below generated with serialize( 'JOJO' )
409 false, "s:4:\"JOJO\";", [ 'object' ], false,
410 ];
411 yield '(no legacy encoding), serialized object in with object flag returns string' => [
412 false,
413 // Using a TitleValue object as it has a getText method (which is needed)
414 serialize( new TitleValue( 0, 'HHJJDDFF' ) ),
415 [ 'object' ],
416 'HHJJDDFF',
417 ];
418 yield '(no legacy encoding), serialized object in with object & gzip flag returns string' => [
419 false,
420 // Using a TitleValue object as it has a getText method (which is needed)
421 gzdeflate( serialize( new TitleValue( 0, '8219JJJ840' ) ) ),
422 [ 'object', 'gzip' ],
423 '8219JJJ840',
424 ];
425 yield '(ISO-8859-1 encoding), string in string out' => [
426 'ISO-8859-1',
427 iconv( 'utf8', 'ISO-8859-1', "1®Àþ1" ),
428 [],
429 '1®Àþ1',
430 ];
431 yield '(ISO-8859-1 encoding), serialized object in with gzip flags returns string' => [
432 'ISO-8859-1',
433 gzdeflate( iconv( 'utf8', 'ISO-8859-1', "4®Àþ4" ) ),
434 [ 'gzip' ],
435 '4®Àþ4',
436 ];
437 yield '(ISO-8859-1 encoding), serialized object in with object flags returns string' => [
438 'ISO-8859-1',
439 serialize( new TitleValue( 0, iconv( 'utf8', 'ISO-8859-1', "3®Àþ3" ) ) ),
440 [ 'object' ],
441 '3®Àþ3',
442 ];
443 yield '(ISO-8859-1 encoding), serialized object in with object & gzip flags returns string' => [
444 'ISO-8859-1',
445 gzdeflate( serialize( new TitleValue( 0, iconv( 'utf8', 'ISO-8859-1', "2®Àþ2" ) ) ) ),
446 [ 'gzip', 'object' ],
447 '2®Àþ2',
448 ];
449 }
450
451 /**
452 * @dataProvider provideDecompressRevisionText
453 * @covers Revision::decompressRevisionText
454 *
455 * @param bool $legacyEncoding
456 * @param mixed $text
457 * @param array $flags
458 * @param mixed $expected
459 */
460 public function testDecompressRevisionText( $legacyEncoding, $text, $flags, $expected ) {
461 $this->setMwGlobals( 'wgLegacyEncoding', $legacyEncoding );
462 $this->setMwGlobals( 'wgLanguageCode', 'en' );
463 $this->assertSame(
464 $expected,
465 Revision::decompressRevisionText( $text, $flags )
466 );
467 }
468
469 /**
470 * @covers Revision::getRevisionText
471 */
472 public function testGetRevisionText_returnsFalseWhenNoTextField() {
473 $this->assertFalse( Revision::getRevisionText( new stdClass() ) );
474 }
475
476 public function provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal() {
477 yield 'Just text' => [
478 (object)[ 'old_text' => 'SomeText' ],
479 'old_',
480 'SomeText'
481 ];
482 // gzip string below generated with gzdeflate( 'AAAABBAAA' )
483 yield 'gzip text' => [
484 (object)[
485 'old_text' => "sttttr\002\022\000",
486 'old_flags' => 'gzip'
487 ],
488 'old_',
489 'AAAABBAAA'
490 ];
491 yield 'gzip text and different prefix' => [
492 (object)[
493 'jojo_text' => "sttttr\002\022\000",
494 'jojo_flags' => 'gzip'
495 ],
496 'jojo_',
497 'AAAABBAAA'
498 ];
499 }
500
501 /**
502 * @dataProvider provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal
503 * @covers Revision::getRevisionText
504 */
505 public function testGetRevisionText_returnsDecompressedTextFieldWhenNotExternal(
506 $row,
507 $prefix,
508 $expected
509 ) {
510 $this->assertSame( $expected, Revision::getRevisionText( $row, $prefix ) );
511 }
512
513 public function provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts() {
514 yield 'Just some text' => [ 'someNonUrlText' ];
515 yield 'No second URL part' => [ 'someProtocol://' ];
516 }
517
518 /**
519 * @dataProvider provideTestGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts
520 * @covers Revision::getRevisionText
521 */
522 public function testGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts(
523 $text
524 ) {
525 $this->assertFalse(
526 Revision::getRevisionText(
527 (object)[
528 'old_text' => $text,
529 'old_flags' => 'external',
530 ]
531 )
532 );
533 }
534
535 /**
536 * @covers Revision::getRevisionText
537 */
538 public function testGetRevisionText_external_noOldId() {
539 $this->setService(
540 'ExternalStoreFactory',
541 new ExternalStoreFactory( [ 'ForTesting' ] )
542 );
543 $this->assertSame(
544 'AAAABBAAA',
545 Revision::getRevisionText(
546 (object)[
547 'old_text' => 'ForTesting://cluster1/12345',
548 'old_flags' => 'external,gzip',
549 ]
550 )
551 );
552 }
553
554 /**
555 * @covers Revision::getRevisionText
556 */
557 public function testGetRevisionText_external_oldId() {
558 $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
559 $this->setService( 'MainWANObjectCache', $cache );
560 $this->setService(
561 'ExternalStoreFactory',
562 new ExternalStoreFactory( [ 'ForTesting' ] )
563 );
564
565 $cacheKey = $cache->makeKey( 'revisiontext', 'textid', '7777' );
566
567 $this->assertSame(
568 'AAAABBAAA',
569 Revision::getRevisionText(
570 (object)[
571 'old_text' => 'ForTesting://cluster1/12345',
572 'old_flags' => 'external,gzip',
573 'old_id' => '7777',
574 ]
575 )
576 );
577 $this->assertSame( 'AAAABBAAA', $cache->get( $cacheKey ) );
578 }
579
580 /**
581 * @covers Revision::userJoinCond
582 */
583 public function testUserJoinCond() {
584 $this->hideDeprecated( 'Revision::userJoinCond' );
585 $this->assertEquals(
586 [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ],
587 Revision::userJoinCond()
588 );
589 }
590
591 /**
592 * @covers Revision::pageJoinCond
593 */
594 public function testPageJoinCond() {
595 $this->hideDeprecated( 'Revision::pageJoinCond' );
596 $this->assertEquals(
597 [ 'INNER JOIN', [ 'page_id = rev_page' ] ],
598 Revision::pageJoinCond()
599 );
600 }
601
602 public function provideSelectFields() {
603 yield [
604 true,
605 [
606 'rev_id',
607 'rev_page',
608 'rev_text_id',
609 'rev_timestamp',
610 'rev_user_text',
611 'rev_user',
612 'rev_minor_edit',
613 'rev_deleted',
614 'rev_len',
615 'rev_parent_id',
616 'rev_sha1',
617 'rev_comment_text' => 'rev_comment',
618 'rev_comment_data' => 'NULL',
619 'rev_comment_cid' => 'NULL',
620 'rev_content_format',
621 'rev_content_model',
622 ]
623 ];
624 yield [
625 false,
626 [
627 'rev_id',
628 'rev_page',
629 'rev_text_id',
630 'rev_timestamp',
631 'rev_user_text',
632 'rev_user',
633 'rev_minor_edit',
634 'rev_deleted',
635 'rev_len',
636 'rev_parent_id',
637 'rev_sha1',
638 'rev_comment_text' => 'rev_comment',
639 'rev_comment_data' => 'NULL',
640 'rev_comment_cid' => 'NULL',
641 ]
642 ];
643 }
644
645 /**
646 * @dataProvider provideSelectFields
647 * @covers Revision::selectFields
648 * @todo a true unit test would mock CommentStore
649 */
650 public function testSelectFields( $contentHandlerUseDB, $expected ) {
651 $this->hideDeprecated( 'Revision::selectFields' );
652 $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
653 $this->assertEquals( $expected, Revision::selectFields() );
654 }
655
656 public function provideSelectArchiveFields() {
657 yield [
658 true,
659 [
660 'ar_id',
661 'ar_page_id',
662 'ar_rev_id',
663 'ar_text',
664 'ar_text_id',
665 'ar_timestamp',
666 'ar_user_text',
667 'ar_user',
668 'ar_minor_edit',
669 'ar_deleted',
670 'ar_len',
671 'ar_parent_id',
672 'ar_sha1',
673 'ar_comment_text' => 'ar_comment',
674 'ar_comment_data' => 'NULL',
675 'ar_comment_cid' => 'NULL',
676 'ar_content_format',
677 'ar_content_model',
678 ]
679 ];
680 yield [
681 false,
682 [
683 'ar_id',
684 'ar_page_id',
685 'ar_rev_id',
686 'ar_text',
687 'ar_text_id',
688 'ar_timestamp',
689 'ar_user_text',
690 'ar_user',
691 'ar_minor_edit',
692 'ar_deleted',
693 'ar_len',
694 'ar_parent_id',
695 'ar_sha1',
696 'ar_comment_text' => 'ar_comment',
697 'ar_comment_data' => 'NULL',
698 'ar_comment_cid' => 'NULL',
699 ]
700 ];
701 }
702
703 /**
704 * @dataProvider provideSelectArchiveFields
705 * @covers Revision::selectArchiveFields
706 * @todo a true unit test would mock CommentStore
707 */
708 public function testSelectArchiveFields( $contentHandlerUseDB, $expected ) {
709 $this->hideDeprecated( 'Revision::selectArchiveFields' );
710 $this->setMwGlobals( 'wgContentHandlerUseDB', $contentHandlerUseDB );
711 $this->assertEquals( $expected, Revision::selectArchiveFields() );
712 }
713
714 /**
715 * @covers Revision::selectTextFields
716 */
717 public function testSelectTextFields() {
718 $this->hideDeprecated( 'Revision::selectTextFields' );
719 $this->assertEquals(
720 [
721 'old_text',
722 'old_flags',
723 ],
724 Revision::selectTextFields()
725 );
726 }
727
728 /**
729 * @covers Revision::selectPageFields
730 */
731 public function testSelectPageFields() {
732 $this->hideDeprecated( 'Revision::selectPageFields' );
733 $this->assertEquals(
734 [
735 'page_namespace',
736 'page_title',
737 'page_id',
738 'page_latest',
739 'page_is_redirect',
740 'page_len',
741 ],
742 Revision::selectPageFields()
743 );
744 }
745
746 /**
747 * @covers Revision::selectUserFields
748 */
749 public function testSelectUserFields() {
750 $this->hideDeprecated( 'Revision::selectUserFields' );
751 $this->assertEquals(
752 [
753 'user_name',
754 ],
755 Revision::selectUserFields()
756 );
757 }
758
759 public function provideGetArchiveQueryInfo() {
760 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage OLD' => [
761 [
762 'wgContentHandlerUseDB' => false,
763 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
764 ],
765 [
766 'tables' => [ 'archive' ],
767 'fields' => [
768 'ar_id',
769 'ar_page_id',
770 'ar_rev_id',
771 'ar_text',
772 'ar_text_id',
773 'ar_timestamp',
774 'ar_user_text',
775 'ar_user',
776 'ar_minor_edit',
777 'ar_deleted',
778 'ar_len',
779 'ar_parent_id',
780 'ar_sha1',
781 'ar_comment_text' => 'ar_comment',
782 'ar_comment_data' => 'NULL',
783 'ar_comment_cid' => 'NULL',
784 ],
785 'joins' => [],
786 ]
787 ];
788 yield 'wgContentHandlerUseDB true, wgCommentTableSchemaMigrationStage OLD' => [
789 [
790 'wgContentHandlerUseDB' => true,
791 'wgCommentTableSchemaMigrationStage' => MIGRATION_OLD,
792 ],
793 [
794 'tables' => [ 'archive' ],
795 'fields' => [
796 'ar_id',
797 'ar_page_id',
798 'ar_rev_id',
799 'ar_text',
800 'ar_text_id',
801 'ar_timestamp',
802 'ar_user_text',
803 'ar_user',
804 'ar_minor_edit',
805 'ar_deleted',
806 'ar_len',
807 'ar_parent_id',
808 'ar_sha1',
809 'ar_comment_text' => 'ar_comment',
810 'ar_comment_data' => 'NULL',
811 'ar_comment_cid' => 'NULL',
812 'ar_content_format',
813 'ar_content_model',
814 ],
815 'joins' => [],
816 ]
817 ];
818 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_BOTH' => [
819 [
820 'wgContentHandlerUseDB' => false,
821 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_BOTH,
822 ],
823 [
824 'tables' => [
825 'archive',
826 'comment_ar_comment' => 'comment',
827 ],
828 'fields' => [
829 'ar_id',
830 'ar_page_id',
831 'ar_rev_id',
832 'ar_text',
833 'ar_text_id',
834 'ar_timestamp',
835 'ar_user_text',
836 'ar_user',
837 'ar_minor_edit',
838 'ar_deleted',
839 'ar_len',
840 'ar_parent_id',
841 'ar_sha1',
842 'ar_comment_text' => 'COALESCE( comment_ar_comment.comment_text, ar_comment )',
843 'ar_comment_data' => 'comment_ar_comment.comment_data',
844 'ar_comment_cid' => 'comment_ar_comment.comment_id',
845 ],
846 'joins' => [
847 'comment_ar_comment' => [
848 'LEFT JOIN',
849 'comment_ar_comment.comment_id = ar_comment_id',
850 ],
851 ],
852 ]
853 ];
854 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage WRITE_NEW' => [
855 [
856 'wgContentHandlerUseDB' => false,
857 'wgCommentTableSchemaMigrationStage' => MIGRATION_WRITE_NEW,
858 ],
859 [
860 'tables' => [
861 'archive',
862 'comment_ar_comment' => 'comment',
863 ],
864 'fields' => [
865 'ar_id',
866 'ar_page_id',
867 'ar_rev_id',
868 'ar_text',
869 'ar_text_id',
870 'ar_timestamp',
871 'ar_user_text',
872 'ar_user',
873 'ar_minor_edit',
874 'ar_deleted',
875 'ar_len',
876 'ar_parent_id',
877 'ar_sha1',
878 'ar_comment_text' => 'COALESCE( comment_ar_comment.comment_text, ar_comment )',
879 'ar_comment_data' => 'comment_ar_comment.comment_data',
880 'ar_comment_cid' => 'comment_ar_comment.comment_id',
881 ],
882 'joins' => [
883 'comment_ar_comment' => [
884 'LEFT JOIN',
885 'comment_ar_comment.comment_id = ar_comment_id',
886 ],
887 ],
888 ]
889 ];
890 yield 'wgContentHandlerUseDB false, wgCommentTableSchemaMigrationStage NEW' => [
891 [
892 'wgContentHandlerUseDB' => false,
893 'wgCommentTableSchemaMigrationStage' => MIGRATION_NEW,
894 ],
895 [
896 'tables' => [
897 'archive',
898 'comment_ar_comment' => 'comment',
899 ],
900 'fields' => [
901 'ar_id',
902 'ar_page_id',
903 'ar_rev_id',
904 'ar_text',
905 'ar_text_id',
906 'ar_timestamp',
907 'ar_user_text',
908 'ar_user',
909 'ar_minor_edit',
910 'ar_deleted',
911 'ar_len',
912 'ar_parent_id',
913 'ar_sha1',
914 'ar_comment_text' => 'comment_ar_comment.comment_text',
915 'ar_comment_data' => 'comment_ar_comment.comment_data',
916 'ar_comment_cid' => 'comment_ar_comment.comment_id',
917 ],
918 'joins' => [
919 'comment_ar_comment' => [
920 'JOIN',
921 'comment_ar_comment.comment_id = ar_comment_id',
922 ],
923 ],
924 ]
925 ];
926 }
927
928 /**
929 * @covers Revision::getArchiveQueryInfo
930 * @dataProvider provideGetArchiveQueryInfo
931 */
932 public function testGetArchiveQueryInfo( $globals, $expected ) {
933 $this->setMwGlobals( $globals );
934 $this->assertEquals(
935 $expected,
936 Revision::getArchiveQueryInfo()
937 );
938 }
939
940 }