Merge "Hide TOC with CSS instead of JavaScript"
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionTest.php
index d928fb4..7ef1182 100644 (file)
@@ -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 ) );
        }
 
@@ -985,7 +1024,6 @@ class RevisionTest extends MediaWikiTestCase {
                                'ar_id',
                                'ar_page_id',
                                'ar_rev_id',
-                               'ar_text',
                                'ar_text_id',
                                'ar_timestamp',
                                'ar_user_text',
@@ -1007,7 +1045,6 @@ class RevisionTest extends MediaWikiTestCase {
                                'ar_id',
                                'ar_page_id',
                                'ar_rev_id',
-                               'ar_text',
                                'ar_text_id',
                                'ar_timestamp',
                                'ar_user_text',
@@ -1097,7 +1134,6 @@ class RevisionTest extends MediaWikiTestCase {
                                        'ar_namespace',
                                        'ar_title',
                                        'ar_rev_id',
-                                       'ar_text',
                                        'ar_text_id',
                                        'ar_timestamp',
                                        'ar_minor_edit',
@@ -1129,7 +1165,6 @@ class RevisionTest extends MediaWikiTestCase {
                                        'ar_namespace',
                                        'ar_title',
                                        'ar_rev_id',
-                                       'ar_text',
                                        'ar_text_id',
                                        'ar_timestamp',
                                        'ar_minor_edit',
@@ -1160,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' => [
                        [
@@ -1395,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']
                );
        }