Debian Codegraph @

tests/phpunit/unit/includes/Revision/RevisionArchiveRecordTest.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\RevisionArchiveRecord;
9 use MediaWiki\Revision\RevisionRecord;
10 use MediaWiki\Revision\RevisionSlots;
11 use MediaWiki\Revision\SlotRecord;
12 use MediaWiki\User\UserIdentityValue;
13 use MediaWikiUnitTestCase;
14
15 /**
16 * @covers \MediaWiki\Revision\RevisionArchiveRecord
17 * @covers \MediaWiki\Revision\RevisionRecord
18 */
19 class RevisionArchiveRecordTest extends MediaWikiUnitTestCase {
20 use RevisionRecordTests;
21
22 protected function expectedDefaultFieldVisibility( $field ): bool {
23 return [
24 RevisionRecord::DELETED_TEXT => false,
25 RevisionRecord::DELETED_COMMENT => false,
26 RevisionRecord::DELETED_USER => true,
27 ][ $field ];
28 }
29
30 /**
31 * @param array $rowOverrides
32 * @return RevisionArchiveRecord
33 */
34 protected function newRevision( array $rowOverrides = [] ) {
35 $wikiId = $rowOverrides['wikiId'] ?? RevisionRecord::LOCAL;
36
37 $title = new PageIdentityValue( 17, NS_MAIN, 'Dummy', $wikiId );
38
39 $user = new UserIdentityValue( 11, 'Tester' );
40 $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
41
42 $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new DummyContentForTesting( 'Lorem Ipsum' ) );
43 $aux = SlotRecord::newUnsaved( 'aux', new DummyContentForTesting( 'Frumious Bandersnatch' ) );
44 $slots = new RevisionSlots( [ $main, $aux ] );
45
46 $row = [
47 'ar_id' => '5',
48 'ar_rev_id' => '7',
49 'ar_page_id' => '17',
50 'ar_timestamp' => '20200101000000',
51 'ar_deleted' => 0,
52 'ar_minor_edit' => 0,
53 'ar_parent_id' => '5',
54 'ar_len' => $slots->computeSize(),
55 'ar_sha1' => $slots->computeSha1(),
56 ];
57
58 foreach ( $rowOverrides as $field => $value ) {
59 if ( $field === 'rev_id' ) {
60 $field = 'ar_rev_id';
61 } else {
62 $field = preg_replace( '/^rev_/', 'ar_', $field );
63 }
64 $row[$field] = $value;
65 }
66
67 return new RevisionArchiveRecord( $title, $user, $comment, (object)$row, $slots, $wikiId );
68 }
69
70 public function testIsCurrent() {
71 $rev = $this->newRevision();
72 $this->assertFalse( $rev->isCurrent(),
73 RevisionArchiveRecord::class . ' cannot be stored current revision' );
74 }
75 }