> Given all called same-class methods are de-facto and liberally claimed, > and that we keep the coverage limited to the subject class, it maintains > the spirit and intent by listing the class as a whole instead. > > PHPUnit offers a more precise tool when you need it (i.e. when testing > legacy monster/god classes), but for well-written code, the > class-wide tag is exactly what you want. > > We lose useful coverage and waste valuable time on keeping tags > accurate through refactors, especially private functions (or worse, > forget to update it). > Tracking tiny per-method details wastes time in realizing (and > fixing) when people inevitably don't keep them in sync, and time > lost in finding uncovered code to write tests to realize it was > already covered but "not yet claimed". Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen Change-Id: If90fc5285a067ec8f706d87b2ba1ae85020e2ba0
75 lines
2.2 KiB
PHP
75 lines
2.2 KiB
PHP
<?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' );
|
|
}
|
|
}
|