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->mPageId = intval( $row->rev_page );
$this->mComment = $comment; $this->mComment = $comment;
$timestamp = MWTimestamp::convert( TS_MW, $row->rev_timestamp ); // Don't use MWTimestamp::convert, instead let any detailed exception from MWTimestamp
Assert::parameter( // bubble up (T254210)
is_string( $timestamp ), $timestamp = ( new MWTimestamp( $row->rev_timestamp ) )->getTimestamp( TS_MW );
'$row->rev_timestamp',
"must be a valid timestamp (rev_id={$this->mId}, rev_timestamp={$row->rev_timestamp})"
);
$this->mUser = $user; $this->mUser = $user;
$this->mMinorEdit = boolval( $row->rev_minor_edit ); $this->mMinorEdit = boolval( $row->rev_minor_edit );

View file

@ -18,6 +18,7 @@ use TextContent;
use Title; use Title;
use TitleValue; use TitleValue;
use Wikimedia\Assert\PreconditionException; use Wikimedia\Assert\PreconditionException;
use Wikimedia\Timestamp\TimestampException;
/** /**
* @covers \MediaWiki\Revision\RevisionStoreRecord * @covers \MediaWiki\Revision\RevisionStoreRecord
@ -244,17 +245,6 @@ class RevisionStoreRecordTest extends MediaWikiIntegrationTestCase {
'acmewiki' 'acmewiki'
]; ];
$row = $protoRow;
$row['rev_timestamp'] = 'kittens';
yield 'bad timestamp' => [
$title,
$user,
$comment,
(object)$row,
$slots
];
$row = $protoRow; $row = $protoRow;
$row['rev_page'] = 99; $row['rev_page'] = 99;
@ -299,4 +289,21 @@ class RevisionStoreRecordTest extends MediaWikiIntegrationTestCase {
$this->expectException( InvalidArgumentException::class ); $this->expectException( InvalidArgumentException::class );
new RevisionStoreRecord( $page, $user, $comment, $row, $slots, $wikiId ); 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
);
}
} }