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