Debian Codegraph @

tests/phpunit/unit/includes/Revision/RevisionStoreRecordTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Unit\Revision;
4
5 use DummyContentForTesting;
6 use MediaWiki\CommentStore\CommentStoreComment;
7 use MediaWiki\Page\PageIdentityValue;
8 use MediaWiki\Revision\RevisionRecord;
9 use MediaWiki\Revision\RevisionSlots;
10 use MediaWiki\Revision\RevisionStoreRecord;
11 use MediaWiki\Revision\SlotRecord;
12 use MediaWiki\User\UserIdentityValue;
13 use MediaWikiUnitTestCase;
14
15 /**
16 * @covers \MediaWiki\Revision\RevisionStoreRecord
17 * @covers \MediaWiki\Revision\RevisionRecord
18 */
19 class RevisionStoreRecordTest extends MediaWikiUnitTestCase {
20 use RevisionRecordTests;
21
22 protected function expectedDefaultFieldVisibility( $field ): bool {
23 return true;
24 }
25
26 /**
27 * @param array $rowOverrides
28 *
29 * @return RevisionStoreRecord
30 */
31 protected function newRevision( array $rowOverrides = [] ) {
32 $wikiId = $rowOverrides['wikiId'] ?? RevisionRecord::LOCAL;
33
34 $title = new PageIdentityValue( 17, NS_MAIN, 'Dummy', $wikiId );
35
36 $user = new UserIdentityValue( 11, 'Tester' );
37 $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
38
39 $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new DummyContentForTesting( 'Lorem Ipsum' ) );
40 $aux = SlotRecord::newUnsaved( 'aux', new DummyContentForTesting( 'Frumious Bandersnatch' ) );
41 $slots = new RevisionSlots( [ $main, $aux ] );
42
43 $row = [
44 'rev_id' => '7',
45 'rev_page' => '17',
46 'rev_timestamp' => '20200101000000',
47 'rev_deleted' => 0,
48 'rev_minor_edit' => 0,
49 'rev_parent_id' => '5',
50 'rev_len' => $slots->computeSize(),
51 'rev_sha1' => $slots->computeSha1(),
52 'page_latest' => '18',
53 ];
54
55 $row = array_merge( $row, $rowOverrides );
56
57 return new RevisionStoreRecord( $title, $user, $comment, (object)$row, $slots, $wikiId );
58 }
59
60 public static function provideIsCurrent() {
61 yield [
62 [
63 'rev_id' => 11,
64 'page_latest' => 11,
65 ],
66 true,
67 ];
68 yield [
69 [
70 'rev_id' => 11,
71 'page_latest' => 10,
72 ],
73 false,
74 ];
75 }
76
77 /**
78 * @dataProvider provideIsCurrent
79 */
80 public function testIsCurrent( $row, $current ) {
81 $rev = $this->newRevision( $row );
82
83 $this->assertSame( $current, $rev->isCurrent(), 'isCurrent()' );
84 }
85
86 public function provideGetSlot_audience_latest() {
87 return $this->provideAudienceCheckData( RevisionRecord::DELETED_TEXT );
88 }
89
90 /**
91 * @dataProvider provideGetSlot_audience_latest
92 */
93 public function testGetSlot_audience_latest( $visibility, $permissions, $userCan, $publicCan ) {
94 $performer = $this->mockRegisteredAuthorityWithPermissions( $permissions );
95 $rev = $this->newRevision(
96 [
97 'rev_deleted' => $visibility,
98 'rev_id' => 11,
99 'page_latest' => 11, // revision is current
100 ]
101 );
102
103 // NOTE: slot meta-data is never suppressed, just the content is!
104 $this->assertNotNull( $rev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW ), 'raw can' );
105 $this->assertNotNull( $rev->getSlot( SlotRecord::MAIN, RevisionRecord::FOR_PUBLIC ),
106 'public can' );
107
108 $this->assertNotNull(
109 $rev->getSlot( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $performer ),
110 'user can'
111 );
112
113 $rev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getContent();
114 // NOTE: the content of the current revision is never suppressed!
115 // Check that getContent() doesn't throw SuppressedDataException
116 $rev->getSlot( SlotRecord::MAIN, RevisionRecord::FOR_PUBLIC )->getContent();
117 $rev->getSlot( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $performer )->getContent();
118 }
119
120 }