X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FStorage%2FRevisionRecordTests.php;h=20270d001e324780955e80b7cab2ab1a18e725a1;hb=74d04edec385aa86ee01943b9a27475d79f74e78;hp=30dacdb7ac28b18275b681eb000148a797a02b2b;hpb=e66bef06b293868f7a61a6c3b3e20067bf938471;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/Storage/RevisionRecordTests.php b/tests/phpunit/includes/Storage/RevisionRecordTests.php index 30dacdb7ac..20270d001e 100644 --- a/tests/phpunit/includes/Storage/RevisionRecordTests.php +++ b/tests/phpunit/includes/Storage/RevisionRecordTests.php @@ -1,5 +1,7 @@ forceStandardPermissions(); $user = $this->getTestUser( $userGroups )->getUser(); @@ -371,72 +378,75 @@ trait RevisionRecordTests { } public function provideHasSameContent() { - /** - * @param SlotRecord[] $slots - * @param int $revId - * @return RevisionStoreRecord - */ - $recordCreator = function ( array $slots, $revId ) { - $title = Title::newFromText( 'provideHasSameContent' ); - $title->resetArticleID( 19 ); - $slots = new RevisionSlots( $slots ); - - return new RevisionStoreRecord( - $title, - new UserIdentityValue( 11, __METHOD__, 0 ), - CommentStoreComment::newUnsavedComment( __METHOD__ ), - (object)[ - 'rev_id' => strval( $revId ), - 'rev_page' => strval( $title->getArticleID() ), - 'rev_timestamp' => '20200101000000', - 'rev_deleted' => 0, - 'rev_minor_edit' => 0, - 'rev_parent_id' => '5', - 'rev_len' => $slots->computeSize(), - 'rev_sha1' => $slots->computeSha1(), - 'page_latest' => '18', - ], - $slots - ); - }; - // Create some slots with content $mainA = SlotRecord::newUnsaved( 'main', new TextContent( 'A' ) ); $mainB = SlotRecord::newUnsaved( 'main', new TextContent( 'B' ) ); $auxA = SlotRecord::newUnsaved( 'aux', new TextContent( 'A' ) ); $auxB = SlotRecord::newUnsaved( 'aux', new TextContent( 'A' ) ); - $initialRecord = $recordCreator( [ $mainA ], 12 ); + $initialRecordSpec = [ [ $mainA ], 12 ]; return [ 'same record object' => [ true, - $initialRecord, - $initialRecord, + $initialRecordSpec, + $initialRecordSpec, ], 'same record content, different object' => [ true, - $recordCreator( [ $mainA ], 12 ), - $recordCreator( [ $mainA ], 13 ), + [ [ $mainA ], 12 ], + [ [ $mainA ], 13 ], ], 'same record content, aux slot, different object' => [ true, - $recordCreator( [ $auxA ], 12 ), - $recordCreator( [ $auxB ], 13 ), + [ [ $auxA ], 12 ], + [ [ $auxB ], 13 ], ], 'different content' => [ false, - $recordCreator( [ $mainA ], 12 ), - $recordCreator( [ $mainB ], 13 ), + [ [ $mainA ], 12 ], + [ [ $mainB ], 13 ], ], 'different content and number of slots' => [ false, - $recordCreator( [ $mainA ], 12 ), - $recordCreator( [ $mainA, $mainB ], 13 ), + [ [ $mainA ], 12 ], + [ [ $mainA, $mainB ], 13 ], ], ]; } + /** + * @note Do not call directly from a data provider! Data providers cannot instantiate + * Title objects! See T202641. + * + * @param SlotRecord[] $slots + * @param int $revId + * @return RevisionStoreRecord + */ + private function makeHasSameContentTestRecord( array $slots, $revId ) { + $title = Title::newFromText( 'provideHasSameContent' ); + $title->resetArticleID( 19 ); + $slots = new RevisionSlots( $slots ); + + return new RevisionStoreRecord( + $title, + new UserIdentityValue( 11, __METHOD__, 0 ), + CommentStoreComment::newUnsavedComment( __METHOD__ ), + (object)[ + 'rev_id' => strval( $revId ), + 'rev_page' => strval( $title->getArticleID() ), + 'rev_timestamp' => '20200101000000', + 'rev_deleted' => 0, + 'rev_minor_edit' => 0, + 'rev_parent_id' => '5', + 'rev_len' => $slots->computeSize(), + 'rev_sha1' => $slots->computeSha1(), + 'page_latest' => '18', + ], + $slots + ); + } + /** * @dataProvider provideHasSameContent * @covers \MediaWiki\Storage\RevisionRecord::hasSameContent @@ -444,9 +454,12 @@ trait RevisionRecordTests { */ public function testHasSameContent( $expected, - RevisionRecord $record1, - RevisionRecord $record2 + $recordSpec1, + $recordSpec2 ) { + $record1 = $this->makeHasSameContentTestRecord( ...$recordSpec1 ); + $record2 = $this->makeHasSameContentTestRecord( ...$recordSpec2 ); + $this->assertSame( $expected, $record1->hasSameContent( $record2 ) @@ -506,4 +519,9 @@ trait RevisionRecordTests { } } + public function testIsReadyForInsertion() { + $rev = $this->newRevision(); + $this->assertTrue( $rev->isReadyForInsertion() ); + } + }