Merge "mw.rcfilters.ui.SaveFiltersPopupButtonWidget: Remove pointless option"
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / RevisionStoreRecordTest.php
1 <?php
2
3 namespace MediaWiki\Tests\Storage;
4
5 use CommentStoreComment;
6 use InvalidArgumentException;
7 use LogicException;
8 use MediaWiki\Storage\RevisionRecord;
9 use MediaWiki\Storage\RevisionSlots;
10 use MediaWiki\Storage\RevisionStoreRecord;
11 use MediaWiki\Storage\SlotRecord;
12 use MediaWiki\Storage\SuppressedDataException;
13 use MediaWiki\User\UserIdentity;
14 use MediaWiki\User\UserIdentityValue;
15 use MediaWikiTestCase;
16 use TextContent;
17 use Title;
18
19 /**
20 * @covers \MediaWiki\Storage\RevisionStoreRecord
21 */
22 class RevisionStoreRecordTest extends MediaWikiTestCase {
23
24 /**
25 * @param array $rowOverrides
26 *
27 * @return RevisionStoreRecord
28 */
29 public function newRevision( array $rowOverrides = [] ) {
30 $title = Title::newFromText( 'Dummy' );
31 $title->resetArticleID( 17 );
32
33 $user = new UserIdentityValue( 11, 'Tester' );
34 $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
35
36 $main = SlotRecord::newUnsaved( 'main', new TextContent( 'Lorem Ipsum' ) );
37 $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
38 $slots = new RevisionSlots( [ $main, $aux ] );
39
40 $row = [
41 'rev_id' => '7',
42 'rev_page' => strval( $title->getArticleID() ),
43 'rev_timestamp' => '20200101000000',
44 'rev_deleted' => 0,
45 'rev_minor_edit' => 0,
46 'rev_parent_id' => '5',
47 'rev_len' => $slots->computeSize(),
48 'rev_sha1' => $slots->computeSha1(),
49 'page_latest' => '18',
50 ];
51
52 $row = array_merge( $row, $rowOverrides );
53
54 return new RevisionStoreRecord( $title, $user, $comment, (object)$row, $slots );
55 }
56
57 public function provideConstructor() {
58 $title = Title::newFromText( 'Dummy' );
59 $title->resetArticleID( 17 );
60
61 $user = new UserIdentityValue( 11, 'Tester' );
62 $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
63
64 $main = SlotRecord::newUnsaved( 'main', new TextContent( 'Lorem Ipsum' ) );
65 $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
66 $slots = new RevisionSlots( [ $main, $aux ] );
67
68 $protoRow = [
69 'rev_id' => '7',
70 'rev_page' => strval( $title->getArticleID() ),
71 'rev_timestamp' => '20200101000000',
72 'rev_deleted' => 0,
73 'rev_minor_edit' => 0,
74 'rev_parent_id' => '5',
75 'rev_len' => $slots->computeSize(),
76 'rev_sha1' => $slots->computeSha1(),
77 'page_latest' => '18',
78 ];
79
80 $row = $protoRow;
81 yield 'all info' => [
82 $title,
83 $user,
84 $comment,
85 (object)$row,
86 $slots,
87 'acmewiki'
88 ];
89
90 $row = $protoRow;
91 $row['rev_minor_edit'] = '1';
92 $row['rev_deleted'] = strval( RevisionRecord::DELETED_USER );
93
94 yield 'minor deleted' => [
95 $title,
96 $user,
97 $comment,
98 (object)$row,
99 $slots
100 ];
101
102 $row = $protoRow;
103 $row['page_latest'] = $row['rev_id'];
104
105 yield 'latest' => [
106 $title,
107 $user,
108 $comment,
109 (object)$row,
110 $slots
111 ];
112
113 $row = $protoRow;
114 unset( $row['rev_parent'] );
115
116 yield 'no parent' => [
117 $title,
118 $user,
119 $comment,
120 (object)$row,
121 $slots
122 ];
123
124 $row = $protoRow;
125 unset( $row['rev_len'] );
126 unset( $row['rev_sha1'] );
127
128 yield 'no length, no hash' => [
129 $title,
130 $user,
131 $comment,
132 (object)$row,
133 $slots
134 ];
135
136 $row = $protoRow;
137 yield 'no length, no hash' => [
138 Title::newFromText( 'DummyDoesNotExist' ),
139 $user,
140 $comment,
141 (object)$row,
142 $slots
143 ];
144 }
145
146 /**
147 * @dataProvider provideConstructor
148 *
149 * @param Title $title
150 * @param UserIdentity $user
151 * @param CommentStoreComment $comment
152 * @param object $row
153 * @param RevisionSlots $slots
154 * @param bool $wikiId
155 */
156 public function testConstructorAndGetters(
157 Title $title,
158 UserIdentity $user,
159 CommentStoreComment $comment,
160 $row,
161 RevisionSlots $slots,
162 $wikiId = false
163 ) {
164 $rec = new RevisionStoreRecord( $title, $user, $comment, $row, $slots, $wikiId );
165
166 $this->assertSame( $title, $rec->getPageAsLinkTarget(), 'getPageAsLinkTarget' );
167 $this->assertSame( $user, $rec->getUser( RevisionRecord::RAW ), 'getUser' );
168 $this->assertSame( $comment, $rec->getComment(), 'getComment' );
169
170 $this->assertSame( $slots->getSlotRoles(), $rec->getSlotRoles(), 'getSlotRoles' );
171 $this->assertSame( $wikiId, $rec->getWikiId(), 'getWikiId' );
172
173 $this->assertSame( (int)$row->rev_id, $rec->getId(), 'getId' );
174 $this->assertSame( (int)$row->rev_page, $rec->getPageId(), 'getId' );
175 $this->assertSame( $row->rev_timestamp, $rec->getTimestamp(), 'getTimestamp' );
176 $this->assertSame( (int)$row->rev_deleted, $rec->getVisibility(), 'getVisibility' );
177 $this->assertSame( (bool)$row->rev_minor_edit, $rec->isMinor(), 'getIsMinor' );
178
179 if ( isset( $row->rev_parent_id ) ) {
180 $this->assertSame( (int)$row->rev_parent_id, $rec->getParentId(), 'getParentId' );
181 } else {
182 $this->assertSame( 0, $rec->getParentId(), 'getParentId' );
183 }
184
185 if ( isset( $row->rev_len ) ) {
186 $this->assertSame( (int)$row->rev_len, $rec->getSize(), 'getSize' );
187 } else {
188 $this->assertSame( $slots->computeSize(), $rec->getSize(), 'getSize' );
189 }
190
191 if ( isset( $row->rev_sha1 ) ) {
192 $this->assertSame( $row->rev_sha1, $rec->getSha1(), 'getSha1' );
193 } else {
194 $this->assertSame( $slots->computeSha1(), $rec->getSha1(), 'getSha1' );
195 }
196
197 if ( isset( $row->page_latest ) ) {
198 $this->assertSame(
199 (int)$row->rev_id === (int)$row->page_latest,
200 $rec->isCurrent(),
201 'isCurrent'
202 );
203 } else {
204 $this->assertSame(
205 false,
206 $rec->isCurrent(),
207 'isCurrent'
208 );
209 }
210 }
211
212 public function provideConstructorFailure() {
213 $title = Title::newFromText( 'Dummy' );
214 $title->resetArticleID( 17 );
215
216 $user = new UserIdentityValue( 11, 'Tester' );
217
218 $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
219
220 $main = SlotRecord::newUnsaved( 'main', new TextContent( 'Lorem Ipsum' ) );
221 $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
222 $slots = new RevisionSlots( [ $main, $aux ] );
223
224 $protoRow = [
225 'rev_id' => '7',
226 'rev_page' => strval( $title->getArticleID() ),
227 'rev_timestamp' => '20200101000000',
228 'rev_deleted' => 0,
229 'rev_minor_edit' => 0,
230 'rev_parent_id' => '5',
231 'rev_len' => $slots->computeSize(),
232 'rev_sha1' => $slots->computeSha1(),
233 'page_latest' => '18',
234 ];
235
236 yield 'not a row' => [
237 $title,
238 $user,
239 $comment,
240 'not a row',
241 $slots,
242 'acmewiki'
243 ];
244
245 $row = $protoRow;
246 $row['rev_timestamp'] = 'kittens';
247
248 yield 'bad timestamp' => [
249 $title,
250 $user,
251 $comment,
252 (object)$row,
253 $slots
254 ];
255
256 $row = $protoRow;
257 $row['rev_page'] = 99;
258
259 yield 'page ID mismatch' => [
260 $title,
261 $user,
262 $comment,
263 (object)$row,
264 $slots
265 ];
266
267 $row = $protoRow;
268
269 yield 'bad wiki' => [
270 $title,
271 $user,
272 $comment,
273 (object)$row,
274 $slots,
275 12345
276 ];
277 }
278
279 /**
280 * @dataProvider provideConstructorFailure
281 *
282 * @param Title $title
283 * @param UserIdentity $user
284 * @param CommentStoreComment $comment
285 * @param object $row
286 * @param RevisionSlots $slots
287 * @param bool $wikiId
288 */
289 public function testConstructorFailure(
290 Title $title,
291 UserIdentity $user,
292 CommentStoreComment $comment,
293 $row,
294 RevisionSlots $slots,
295 $wikiId = false
296 ) {
297 $this->setExpectedException( InvalidArgumentException::class );
298 new RevisionStoreRecord( $title, $user, $comment, $row, $slots, $wikiId );
299 }
300
301 private function provideAudienceCheckData( $field ) {
302 yield 'field accessible for oversighter (ALL)' => [
303 RevisionRecord::SUPPRESSED_ALL,
304 [ 'oversight' ],
305 true,
306 false
307 ];
308
309 yield 'field accessible for oversighter' => [
310 RevisionRecord::DELETED_RESTRICTED | $field,
311 [ 'oversight' ],
312 true,
313 false
314 ];
315
316 yield 'field not accessible for sysops (ALL)' => [
317 RevisionRecord::SUPPRESSED_ALL,
318 [ 'sysop' ],
319 false,
320 false
321 ];
322
323 yield 'field not accessible for sysops' => [
324 RevisionRecord::DELETED_RESTRICTED | $field,
325 [ 'sysop' ],
326 false,
327 false
328 ];
329
330 yield 'field accessible for sysops' => [
331 $field,
332 [ 'sysop' ],
333 true,
334 false
335 ];
336
337 yield 'field suppressed for logged in users' => [
338 $field,
339 [ 'user' ],
340 false,
341 false
342 ];
343
344 yield 'unrelated field suppressed' => [
345 $field === RevisionRecord::DELETED_COMMENT
346 ? RevisionRecord::DELETED_USER
347 : RevisionRecord::DELETED_COMMENT,
348 [ 'user' ],
349 true,
350 true
351 ];
352
353 yield 'nothing suppressed' => [
354 0,
355 [ 'user' ],
356 true,
357 true
358 ];
359 }
360
361 public function testSerialization_fails() {
362 $this->setExpectedException( LogicException::class );
363 $rev = $this->newRevision();
364 serialize( $rev );
365 }
366
367 public function provideGetComment_audience() {
368 return $this->provideAudienceCheckData( RevisionRecord::DELETED_COMMENT );
369 }
370
371 private function forceStandardPermissions() {
372 $this->setMwGlobals(
373 'wgGroupPermissions',
374 [
375 'user' => [
376 'viewsuppressed' => false,
377 'suppressrevision' => false,
378 'deletedtext' => false,
379 'deletedhistory' => false,
380 ],
381 'sysop' => [
382 'viewsuppressed' => false,
383 'suppressrevision' => false,
384 'deletedtext' => true,
385 'deletedhistory' => true,
386 ],
387 'oversight' => [
388 'deletedtext' => true,
389 'deletedhistory' => true,
390 'viewsuppressed' => true,
391 'suppressrevision' => true,
392 ],
393 ]
394 );
395 }
396
397 /**
398 * @dataProvider provideGetComment_audience
399 */
400 public function testGetComment_audience( $visibility, $groups, $userCan, $publicCan ) {
401 $this->forceStandardPermissions();
402
403 $user = $this->getTestUser( $groups )->getUser();
404 $rev = $this->newRevision( [ 'rev_deleted' => $visibility ] );
405
406 $this->assertNotNull( $rev->getComment( RevisionRecord::RAW ), 'raw can' );
407
408 $this->assertSame(
409 $publicCan,
410 $rev->getComment( RevisionRecord::FOR_PUBLIC ) !== null,
411 'public can'
412 );
413 $this->assertSame(
414 $userCan,
415 $rev->getComment( RevisionRecord::FOR_THIS_USER, $user ) !== null,
416 'user can'
417 );
418 }
419
420 public function provideGetUser_audience() {
421 return $this->provideAudienceCheckData( RevisionRecord::DELETED_USER );
422 }
423
424 /**
425 * @dataProvider provideGetUser_audience
426 */
427 public function testGetUser_audience( $visibility, $groups, $userCan, $publicCan ) {
428 $this->forceStandardPermissions();
429
430 $user = $this->getTestUser( $groups )->getUser();
431 $rev = $this->newRevision( [ 'rev_deleted' => $visibility ] );
432
433 $this->assertNotNull( $rev->getUser( RevisionRecord::RAW ), 'raw can' );
434
435 $this->assertSame(
436 $publicCan,
437 $rev->getUser( RevisionRecord::FOR_PUBLIC ) !== null,
438 'public can'
439 );
440 $this->assertSame(
441 $userCan,
442 $rev->getUser( RevisionRecord::FOR_THIS_USER, $user ) !== null,
443 'user can'
444 );
445 }
446
447 public function provideGetSlot_audience() {
448 return $this->provideAudienceCheckData( RevisionRecord::DELETED_TEXT );
449 }
450
451 /**
452 * @dataProvider provideGetSlot_audience
453 */
454 public function testGetSlot_audience( $visibility, $groups, $userCan, $publicCan ) {
455 $this->forceStandardPermissions();
456
457 $user = $this->getTestUser( $groups )->getUser();
458 $rev = $this->newRevision( [ 'rev_deleted' => $visibility ] );
459
460 // NOTE: slot meta-data is never suppressed, just the content is!
461 $this->assertNotNull( $rev->getSlot( 'main', RevisionRecord::RAW ), 'raw can' );
462 $this->assertNotNull( $rev->getSlot( 'main', RevisionRecord::FOR_PUBLIC ), 'public can' );
463
464 $this->assertNotNull(
465 $rev->getSlot( 'main', RevisionRecord::FOR_THIS_USER, $user ),
466 'user can'
467 );
468
469 try {
470 $rev->getSlot( 'main', RevisionRecord::FOR_PUBLIC )->getContent();
471 $exception = null;
472 } catch ( SuppressedDataException $ex ) {
473 $exception = $ex;
474 }
475
476 $this->assertSame(
477 $publicCan,
478 $exception === null,
479 'public can'
480 );
481
482 try {
483 $rev->getSlot( 'main', RevisionRecord::FOR_THIS_USER, $user )->getContent();
484 $exception = null;
485 } catch ( SuppressedDataException $ex ) {
486 $exception = $ex;
487 }
488
489 $this->assertSame(
490 $userCan,
491 $exception === null,
492 'user can'
493 );
494 }
495
496 public function provideGetSlot_audience_latest() {
497 return $this->provideAudienceCheckData( RevisionRecord::DELETED_TEXT );
498 }
499
500 /**
501 * @dataProvider provideGetSlot_audience_latest
502 */
503 public function testGetSlot_audience_latest( $visibility, $groups, $userCan, $publicCan ) {
504 $this->forceStandardPermissions();
505
506 $user = $this->getTestUser( $groups )->getUser();
507 $rev = $this->newRevision(
508 [
509 'rev_deleted' => $visibility,
510 'rev_id' => 11,
511 'page_latest' => 11, // revision is current
512 ]
513 );
514
515 // sanity check
516 $this->assertTrue( $rev->isCurrent(), 'isCurrent()' );
517
518 // NOTE: slot meta-data is never suppressed, just the content is!
519 $this->assertNotNull( $rev->getSlot( 'main', RevisionRecord::RAW ), 'raw can' );
520 $this->assertNotNull( $rev->getSlot( 'main', RevisionRecord::FOR_PUBLIC ), 'public can' );
521
522 $this->assertNotNull(
523 $rev->getSlot( 'main', RevisionRecord::FOR_THIS_USER, $user ),
524 'user can'
525 );
526
527 // NOTE: the content of the current revision is never suppressed!
528 // Check that getContent() doesn't throw SuppressedDataException
529 $rev->getSlot( 'main', RevisionRecord::RAW )->getContent();
530 $rev->getSlot( 'main', RevisionRecord::FOR_PUBLIC )->getContent();
531 $rev->getSlot( 'main', RevisionRecord::FOR_THIS_USER, $user )->getContent();
532 }
533
534 /**
535 * @dataProvider provideGetSlot_audience
536 */
537 public function testGetContent_audience( $visibility, $groups, $userCan, $publicCan ) {
538 $this->forceStandardPermissions();
539
540 $user = $this->getTestUser( $groups )->getUser();
541 $rev = $this->newRevision( [ 'rev_deleted' => $visibility ] );
542
543 $this->assertNotNull( $rev->getContent( 'main', RevisionRecord::RAW ), 'raw can' );
544
545 $this->assertSame(
546 $publicCan,
547 $rev->getContent( 'main', RevisionRecord::FOR_PUBLIC ) !== null,
548 'public can'
549 );
550 $this->assertSame(
551 $userCan,
552 $rev->getContent( 'main', RevisionRecord::FOR_THIS_USER, $user ) !== null,
553 'user can'
554 );
555 }
556
557 public function testGetSlot() {
558 $rev = $this->newRevision();
559
560 $slot = $rev->getSlot( 'main' );
561 $this->assertNotNull( $slot, 'getSlot()' );
562 $this->assertSame( 'main', $slot->getRole(), 'getRole()' );
563 }
564
565 public function testGetContent() {
566 $rev = $this->newRevision();
567
568 $content = $rev->getSlot( 'main' );
569 $this->assertNotNull( $content, 'getContent()' );
570 $this->assertSame( CONTENT_MODEL_TEXT, $content->getModel(), 'getModel()' );
571 }
572
573 public function provideUserCanBitfield() {
574 yield [ 0, 0, [], null, true ];
575 // Bitfields match, user has no permissions
576 yield [
577 RevisionRecord::DELETED_TEXT,
578 RevisionRecord::DELETED_TEXT,
579 [],
580 null,
581 false
582 ];
583 yield [
584 RevisionRecord::DELETED_COMMENT,
585 RevisionRecord::DELETED_COMMENT,
586 [],
587 null,
588 false,
589 ];
590 yield [
591 RevisionRecord::DELETED_USER,
592 RevisionRecord::DELETED_USER,
593 [],
594 null,
595 false
596 ];
597 yield [
598 RevisionRecord::DELETED_RESTRICTED,
599 RevisionRecord::DELETED_RESTRICTED,
600 [],
601 null,
602 false,
603 ];
604 // Bitfields match, user (admin) does have permissions
605 yield [
606 RevisionRecord::DELETED_TEXT,
607 RevisionRecord::DELETED_TEXT,
608 [ 'sysop' ],
609 null,
610 true,
611 ];
612 yield [
613 RevisionRecord::DELETED_COMMENT,
614 RevisionRecord::DELETED_COMMENT,
615 [ 'sysop' ],
616 null,
617 true,
618 ];
619 yield [
620 RevisionRecord::DELETED_USER,
621 RevisionRecord::DELETED_USER,
622 [ 'sysop' ],
623 null,
624 true,
625 ];
626 // Bitfields match, user (admin) does not have permissions
627 yield [
628 RevisionRecord::DELETED_RESTRICTED,
629 RevisionRecord::DELETED_RESTRICTED,
630 [ 'sysop' ],
631 null,
632 false,
633 ];
634 // Bitfields match, user (oversight) does have permissions
635 yield [
636 RevisionRecord::DELETED_RESTRICTED,
637 RevisionRecord::DELETED_RESTRICTED,
638 [ 'oversight' ],
639 null,
640 true,
641 ];
642 // Check permissions using the title
643 yield [
644 RevisionRecord::DELETED_TEXT,
645 RevisionRecord::DELETED_TEXT,
646 [ 'sysop' ],
647 Title::newFromText( __METHOD__ ),
648 true,
649 ];
650 yield [
651 RevisionRecord::DELETED_TEXT,
652 RevisionRecord::DELETED_TEXT,
653 [],
654 Title::newFromText( __METHOD__ ),
655 false,
656 ];
657 }
658
659 /**
660 * @dataProvider provideUserCanBitfield
661 * @covers \MediaWiki\Storage\RevisionRecord::userCanBitfield
662 */
663 public function testUserCanBitfield( $bitField, $field, $userGroups, $title, $expected ) {
664 $this->forceStandardPermissions();
665
666 $user = $this->getTestUser( $userGroups )->getUser();
667
668 $this->assertSame(
669 $expected,
670 RevisionRecord::userCanBitfield( $bitField, $field, $user, $title )
671 );
672 }
673
674 private function getSlotRecord( $role, $contentString ) {
675 return SlotRecord::newUnsaved( $role, new TextContent( $contentString ) );
676 }
677
678 public function provideHasSameContent() {
679 /**
680 * @param SlotRecord[] $slots
681 * @param int $revId
682 * @return RevisionStoreRecord
683 */
684 $recordCreator = function ( array $slots, $revId ) {
685 $title = Title::newFromText( 'provideHasSameContent' );
686 $title->resetArticleID( 19 );
687 $slots = new RevisionSlots( $slots );
688
689 return new RevisionStoreRecord(
690 $title,
691 new UserIdentityValue( 11, __METHOD__ ),
692 CommentStoreComment::newUnsavedComment( __METHOD__ ),
693 (object)[
694 'rev_id' => strval( $revId ),
695 'rev_page' => strval( $title->getArticleID() ),
696 'rev_timestamp' => '20200101000000',
697 'rev_deleted' => 0,
698 'rev_minor_edit' => 0,
699 'rev_parent_id' => '5',
700 'rev_len' => $slots->computeSize(),
701 'rev_sha1' => $slots->computeSha1(),
702 'page_latest' => '18',
703 ],
704 $slots
705 );
706 };
707
708 // Create some slots with content
709 $mainA = SlotRecord::newUnsaved( 'main', new TextContent( 'A' ) );
710 $mainB = SlotRecord::newUnsaved( 'main', new TextContent( 'B' ) );
711 $auxA = SlotRecord::newUnsaved( 'aux', new TextContent( 'A' ) );
712 $auxB = SlotRecord::newUnsaved( 'aux', new TextContent( 'A' ) );
713
714 $initialRecord = $recordCreator( [ $mainA ], 12 );
715
716 return [
717 'same record object' => [
718 true,
719 $initialRecord,
720 $initialRecord,
721 ],
722 'same record content, different object' => [
723 true,
724 $recordCreator( [ $mainA ], 12 ),
725 $recordCreator( [ $mainA ], 13 ),
726 ],
727 'same record content, aux slot, different object' => [
728 true,
729 $recordCreator( [ $auxA ], 12 ),
730 $recordCreator( [ $auxB ], 13 ),
731 ],
732 'different content' => [
733 false,
734 $recordCreator( [ $mainA ], 12 ),
735 $recordCreator( [ $mainB ], 13 ),
736 ],
737 'different content and number of slots' => [
738 false,
739 $recordCreator( [ $mainA ], 12 ),
740 $recordCreator( [ $mainA, $mainB ], 13 ),
741 ],
742 ];
743 }
744
745 /**
746 * @dataProvider provideHasSameContent
747 * @covers \MediaWiki\Storage\RevisionRecord::hasSameContent
748 * @group Database
749 */
750 public function testHasSameContent(
751 $expected,
752 RevisionRecord $record1,
753 RevisionRecord $record2
754 ) {
755 $this->assertSame(
756 $expected,
757 $record1->hasSameContent( $record2 )
758 );
759 }
760
761 public function provideIsDeleted() {
762 yield 'no deletion' => [
763 0,
764 [
765 RevisionRecord::DELETED_TEXT => false,
766 RevisionRecord::DELETED_COMMENT => false,
767 RevisionRecord::DELETED_USER => false,
768 RevisionRecord::DELETED_RESTRICTED => false,
769 ]
770 ];
771 yield 'text deleted' => [
772 RevisionRecord::DELETED_TEXT,
773 [
774 RevisionRecord::DELETED_TEXT => true,
775 RevisionRecord::DELETED_COMMENT => false,
776 RevisionRecord::DELETED_USER => false,
777 RevisionRecord::DELETED_RESTRICTED => false,
778 ]
779 ];
780 yield 'text and comment deleted' => [
781 RevisionRecord::DELETED_TEXT + RevisionRecord::DELETED_COMMENT,
782 [
783 RevisionRecord::DELETED_TEXT => true,
784 RevisionRecord::DELETED_COMMENT => true,
785 RevisionRecord::DELETED_USER => false,
786 RevisionRecord::DELETED_RESTRICTED => false,
787 ]
788 ];
789 yield 'all 4 deleted' => [
790 RevisionRecord::DELETED_TEXT +
791 RevisionRecord::DELETED_COMMENT +
792 RevisionRecord::DELETED_RESTRICTED +
793 RevisionRecord::DELETED_USER,
794 [
795 RevisionRecord::DELETED_TEXT => true,
796 RevisionRecord::DELETED_COMMENT => true,
797 RevisionRecord::DELETED_USER => true,
798 RevisionRecord::DELETED_RESTRICTED => true,
799 ]
800 ];
801 }
802
803 /**
804 * @dataProvider provideIsDeleted
805 * @covers \MediaWiki\Storage\RevisionRecord::isDeleted
806 */
807 public function testIsDeleted( $revDeleted, $assertionMap ) {
808 $rev = $this->newRevision( [ 'rev_deleted' => $revDeleted ] );
809 foreach ( $assertionMap as $deletionLevel => $expected ) {
810 $this->assertSame( $expected, $rev->isDeleted( $deletionLevel ) );
811 }
812 }
813
814 }