Merge "RevisionStoreRecord: Use MWTimestamp::getTimestamp for detailed errors"

This commit is contained in:
jenkins-bot 2021-04-01 02:06:38 +00:00 committed by Gerrit Code Review
commit 22570181d4
2 changed files with 21 additions and 17 deletions

View file

@ -68,12 +68,9 @@ class RevisionStoreRecord extends RevisionRecord {
$this->mPageId = intval( $row->rev_page );
$this->mComment = $comment;
$timestamp = MWTimestamp::convert( TS_MW, $row->rev_timestamp );
Assert::parameter(
is_string( $timestamp ),
'$row->rev_timestamp',
"must be a valid timestamp (rev_id={$this->mId}, rev_timestamp={$row->rev_timestamp})"
);
// Don't use MWTimestamp::convert, instead let any detailed exception from MWTimestamp
// bubble up (T254210)
$timestamp = ( new MWTimestamp( $row->rev_timestamp ) )->getTimestamp( TS_MW );
$this->mUser = $user;
$this->mMinorEdit = boolval( $row->rev_minor_edit );

View file

@ -18,6 +18,7 @@ use TextContent;
use Title;
use TitleValue;
use Wikimedia\Assert\PreconditionException;
use Wikimedia\Timestamp\TimestampException;
/**
* @covers \MediaWiki\Revision\RevisionStoreRecord
@ -244,17 +245,6 @@ class RevisionStoreRecordTest extends MediaWikiIntegrationTestCase {
'acmewiki'
];
$row = $protoRow;
$row['rev_timestamp'] = 'kittens';
yield 'bad timestamp' => [
$title,
$user,
$comment,
(object)$row,
$slots
];
$row = $protoRow;
$row['rev_page'] = 99;
@ -299,4 +289,21 @@ class RevisionStoreRecordTest extends MediaWikiIntegrationTestCase {
$this->expectException( InvalidArgumentException::class );
new RevisionStoreRecord( $page, $user, $comment, $row, $slots, $wikiId );
}
public function testConstructorBadTimestamp() {
$row = (object)[
'rev_id' => 42,
'rev_page' => 'Foobar',
'rev_timestamp' => 'kittens',
];
$this->expectException( TimestampException::class );
new RevisionStoreRecord(
$this->createMock( PageIdentity::class ),
new UserIdentityValue( 11, 'Tester', 0 ),
$this->createMock( CommentStoreComment::class ),
$row,
$this->createMock( RevisionSlots::class ),
false
);
}
}