X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FRevisionTest.php;h=7ef11829064618c3482f80b5226c53dd71d037ca;hb=56d45558b102349f3480a46819669407aa3be2d6;hp=ab067a4746b5a072660ae35635db90f6a94226f4;hpb=20670b2ef91c3afbfacdd0a881648a27be0d282d;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/RevisionTest.php b/tests/phpunit/includes/RevisionTest.php index ab067a4746..7ef1182906 100644 --- a/tests/phpunit/includes/RevisionTest.php +++ b/tests/phpunit/includes/RevisionTest.php @@ -17,6 +17,11 @@ use Wikimedia\Rdbms\LoadBalancer; */ class RevisionTest extends MediaWikiTestCase { + public function setUp() { + parent::setUp(); + $this->setMwGlobals( 'wgMultiContentRevisionSchemaMigrationStage', MIGRATION_OLD ); + } + public function provideConstructFromArray() { yield 'with text' => [ [ @@ -154,16 +159,15 @@ class RevisionTest extends MediaWikiTestCase { 'content' => new WikitextContent( 'GOAT' ), 'text_id' => 'someid', ], - new MWException( "Text already stored in external store (id someid), " . - "can't serialize content object" ) + new MWException( 'Text already stored in external store (id someid),' ) ]; yield 'with bad content object (class)' => [ [ 'content' => new stdClass() ], - new MWException( 'content field must contain a Content object.' ) + new MWException( 'content field must contain a Content object' ) ]; yield 'with bad content object (string)' => [ [ 'content' => 'ImAGoat' ], - new MWException( 'content field must contain a Content object.' ) + new MWException( 'content field must contain a Content object' ) ]; yield 'bad row format' => [ 'imastring, not a row', @@ -439,6 +443,31 @@ class RevisionTest extends MediaWikiTestCase { $this->testGetRevisionText( $expected, $rowData ); } + public function provideGetRevisionTextWithZlibExtension_badData() { + yield 'Generic gzip test' => [ + 'This is a small goat of revision text.', + [ + 'old_flags' => 'gzip', + 'old_text' => 'DEAD BEEF', + ], + ]; + } + + /** + * @covers Revision::getRevisionText + * @dataProvider provideGetRevisionTextWithZlibExtension_badData + */ + public function testGetRevisionWithZlibExtension_badData( $expected, $rowData ) { + $this->checkPHPExtension( 'zlib' ); + Wikimedia\suppressWarnings(); + $this->assertFalse( + Revision::getRevisionText( + (object)$rowData + ) + ); + Wikimedia\suppressWarnings( true ); + } + private function getWANObjectCache() { return new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ); } @@ -488,6 +517,9 @@ class RevisionTest extends MediaWikiTestCase { $this->getBlobStore(), $cache, MediaWikiServices::getInstance()->getCommentStore(), + MediaWikiServices::getInstance()->getContentModelStore(), + MediaWikiServices::getInstance()->getSlotRoleStore(), + MIGRATION_OLD, MediaWikiServices::getInstance()->getActorMigration() ); return $blobStore; @@ -802,6 +834,7 @@ class RevisionTest extends MediaWikiTestCase { public function testGetRevisionText_external_returnsFalseWhenNotEnoughUrlParts( $text ) { + Wikimedia\suppressWarnings(); $this->assertFalse( Revision::getRevisionText( (object)[ @@ -810,6 +843,7 @@ class RevisionTest extends MediaWikiTestCase { ] ) ); + Wikimedia\suppressWarnings( true ); } /** @@ -861,7 +895,12 @@ class RevisionTest extends MediaWikiTestCase { ) ); - $cacheKey = $cache->makeKey( 'revisiontext', 'textid', 'tt:7777' ); + $cacheKey = $cache->makeGlobalKey( + 'BlobStore', + 'address', + $lb->getLocalDomainID(), + 'tt:7777' + ); $this->assertSame( 'AAAABBAAA', $cache->get( $cacheKey ) ); } @@ -1156,12 +1195,62 @@ class RevisionTest extends MediaWikiTestCase { $revisionStore = $this->getRevisionStore(); $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] ); $this->setService( 'RevisionStore', $revisionStore ); - $this->assertEquals( - $expected, - Revision::getArchiveQueryInfo() + + $queryInfo = Revision::getArchiveQueryInfo(); + + $this->assertArrayEqualsIgnoringIntKeyOrder( + $expected['tables'], + $queryInfo['tables'] + ); + $this->assertArrayEqualsIgnoringIntKeyOrder( + $expected['fields'], + $queryInfo['fields'] + ); + $this->assertArrayEqualsIgnoringIntKeyOrder( + $expected['joins'], + $queryInfo['joins'] ); } + /** + * Assert that the two arrays passed are equal, ignoring the order of the values that integer + * keys. + * + * Note: Failures of this assertion can be slightly confusing as the arrays are actually + * split into a string key array and an int key array before assertions occur. + * + * @param array $expected + * @param array $actual + */ + private function assertArrayEqualsIgnoringIntKeyOrder( array $expected, array $actual ) { + $this->objectAssociativeSort( $expected ); + $this->objectAssociativeSort( $actual ); + + // Separate the int key values from the string key values so that assertion failures are + // easier to understand. + $expectedIntKeyValues = []; + $actualIntKeyValues = []; + + // Remove all int keys and re add them at the end after sorting by value + // This will result in all int keys being in the same order with same ints at the end of + // the array + foreach ( $expected as $key => $value ) { + if ( is_int( $key ) ) { + unset( $expected[$key] ); + $expectedIntKeyValues[] = $value; + } + } + foreach ( $actual as $key => $value ) { + if ( is_int( $key ) ) { + unset( $actual[$key] ); + $actualIntKeyValues[] = $value; + } + } + + $this->assertArrayEquals( $expected, $actual, false, true ); + $this->assertArrayEquals( $expectedIntKeyValues, $actualIntKeyValues, false, true ); + } + public function provideGetQueryInfo() { yield 'wgContentHandlerUseDB false, opts none' => [ [ @@ -1391,9 +1480,19 @@ class RevisionTest extends MediaWikiTestCase { $revisionStore->setContentHandlerUseDB( $globals['wgContentHandlerUseDB'] ); $this->setService( 'RevisionStore', $revisionStore ); - $this->assertEquals( - $expected, - Revision::getQueryInfo( $options ) + $queryInfo = Revision::getQueryInfo( $options ); + + $this->assertArrayEqualsIgnoringIntKeyOrder( + $expected['tables'], + $queryInfo['tables'] + ); + $this->assertArrayEqualsIgnoringIntKeyOrder( + $expected['fields'], + $queryInfo['fields'] + ); + $this->assertArrayEqualsIgnoringIntKeyOrder( + $expected['joins'], + $queryInfo['joins'] ); }