Merge "SlotRecord:compute sha1 if empty."
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionTest.php
index 5868b8d..d62e4c7 100644 (file)
@@ -281,24 +281,17 @@ class RevisionTest extends MediaWikiTestCase {
         * @covers \MediaWiki\Revision\RevisionStore::newMutableRevisionFromArray
         */
        public function testConstructFromRowWithBadPageId() {
-               $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD );
                $this->overrideMwServices();
                Wikimedia\suppressWarnings();
-               $rev = new Revision( (object)[ 'rev_page' => 77777777 ] );
+               $rev = new Revision( (object)[
+                       'rev_page' => 77777777,
+                       'rev_comment_text' => '',
+                       'rev_comment_data' => null,
+               ] );
                $this->assertSame( 77777777, $rev->getPage() );
                Wikimedia\restoreWarnings();
        }
 
-       public function provideGetRevisionText() {
-               yield 'Generic test' => [
-                       'This is a goat of revision text.',
-                       [
-                               'old_flags' => '',
-                               'old_text' => 'This is a goat of revision text.',
-                       ],
-               ];
-       }
-
        public function provideGetId() {
                yield [
                        [],
@@ -365,6 +358,20 @@ class RevisionTest extends MediaWikiTestCase {
                $this->assertSame( $expected, $rev->getParentId() );
        }
 
+       public function provideGetRevisionText() {
+               yield 'Generic test' => [
+                       'This is a goat of revision text.',
+                       (object)[
+                               'old_flags' => '',
+                               'old_text' => 'This is a goat of revision text.',
+                       ],
+               ];
+               yield 'garbage in, garbage out' => [
+                       false,
+                       false,
+               ];
+       }
+
        /**
         * @covers Revision::getRevisionText
         * @dataProvider provideGetRevisionText
@@ -372,13 +379,13 @@ class RevisionTest extends MediaWikiTestCase {
        public function testGetRevisionText( $expected, $rowData, $prefix = 'old_', $wiki = false ) {
                $this->assertEquals(
                        $expected,
-                       Revision::getRevisionText( (object)$rowData, $prefix, $wiki ) );
+                       Revision::getRevisionText( $rowData, $prefix, $wiki ) );
        }
 
        public function provideGetRevisionTextWithZlibExtension() {
                yield 'Generic gzip test' => [
                        'This is a small goat of revision text.',
-                       [
+                       (object)[
                                'old_flags' => 'gzip',
                                'old_text' => gzdeflate( 'This is a small goat of revision text.' ),
                        ],
@@ -397,7 +404,7 @@ class RevisionTest extends MediaWikiTestCase {
        public function provideGetRevisionTextWithZlibExtension_badData() {
                yield 'Generic gzip test' => [
                        'This is a small goat of revision text.',
-                       [
+                       (object)[
                                'old_flags' => 'gzip',
                                'old_text' => 'DEAD BEEF',
                        ],
@@ -431,10 +438,11 @@ class RevisionTest extends MediaWikiTestCase {
                $lb = $this->getMockBuilder( LoadBalancer::class )
                        ->disableOriginalConstructor()
                        ->getMock();
-
+               $access = MediaWikiServices::getInstance()->getExternalStoreAccess();
                $cache = $this->getWANObjectCache();
 
-               $blobStore = new SqlBlobStore( $lb, $cache );
+               $blobStore = new SqlBlobStore( $lb, $access, $cache );
+
                return $blobStore;
        }
 
@@ -470,6 +478,7 @@ class RevisionTest extends MediaWikiTestCase {
                        MediaWikiServices::getInstance()->getCommentStore(),
                        MediaWikiServices::getInstance()->getContentModelStore(),
                        MediaWikiServices::getInstance()->getSlotRoleStore(),
+                       MediaWikiServices::getInstance()->getSlotRoleRegistry(),
                        MIGRATION_OLD,
                        MediaWikiServices::getInstance()->getActorMigration()
                );
@@ -481,7 +490,7 @@ class RevisionTest extends MediaWikiTestCase {
                        "Wiki est l'\xc3\xa9cole superieur !",
                        'fr',
                        'iso-8859-1',
-                       [
+                       (object)[
                                'old_flags' => 'utf-8',
                                'old_text' => "Wiki est l'\xc3\xa9cole superieur !",
                        ]
@@ -490,7 +499,7 @@ class RevisionTest extends MediaWikiTestCase {
                        "Wiki est l'\xc3\xa9cole superieur !",
                        'fr',
                        'iso-8859-1',
-                       [
+                       (object)[
                                'old_flags' => '',
                                'old_text' => "Wiki est l'\xe9cole superieur !",
                        ]
@@ -519,7 +528,7 @@ class RevisionTest extends MediaWikiTestCase {
                        "Wiki est l'\xc3\xa9cole superieur !",
                        'fr',
                        'iso-8859-1',
-                       [
+                       (object)[
                                'old_flags' => 'gzip,utf-8',
                                'old_text' => gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" ),
                        ]
@@ -528,7 +537,7 @@ class RevisionTest extends MediaWikiTestCase {
                        "Wiki est l'\xc3\xa9cole superieur !",
                        'fr',
                        'iso-8859-1',
-                       [
+                       (object)[
                                'old_flags' => 'gzip',
                                'old_text' => gzdeflate( "Wiki est l'\xe9cole superieur !" ),
                        ]
@@ -556,9 +565,9 @@ class RevisionTest extends MediaWikiTestCase {
                $row = new stdClass;
                $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
                $row->old_flags = Revision::compressRevisionText( $row->old_text );
-               $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
+               $this->assertTrue( strpos( $row->old_flags, 'utf-8' ) !== false,
                        "Flags should contain 'utf-8'" );
-               $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ),
+               $this->assertFalse( strpos( $row->old_flags, 'gzip' ) !== false,
                        "Flags should not contain 'gzip'" );
                $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
                        $row->old_text, "Direct check" );
@@ -579,9 +588,9 @@ class RevisionTest extends MediaWikiTestCase {
                $row = new stdClass;
                $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
                $row->old_flags = Revision::compressRevisionText( $row->old_text );
-               $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
+               $this->assertTrue( strpos( $row->old_flags, 'utf-8' ) !== false,
                        "Flags should contain 'utf-8'" );
-               $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ),
+               $this->assertTrue( strpos( $row->old_flags, 'gzip' ) !== false,
                        "Flags should contain 'gzip'" );
                $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
                        gzinflate( $row->old_text ), "Direct check" );
@@ -593,8 +602,7 @@ class RevisionTest extends MediaWikiTestCase {
         * @covers Revision::loadFromTitle
         */
        public function testLoadFromTitle() {
-               $this->setMwGlobals( 'wgCommentTableSchemaMigrationStage', MIGRATION_OLD );
-               $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_OLD );
+               $this->setMwGlobals( 'wgActorTableSchemaMigrationStage', SCHEMA_COMPAT_NEW );
                $this->overrideMwServices();
                $title = $this->getMockTitle();
 
@@ -630,7 +638,11 @@ class RevisionTest extends MediaWikiTestCase {
                $db->expects( $this->once() )
                        ->method( 'selectRow' )
                        ->with(
-                               $this->equalTo( [ 'revision', 'page', 'user' ] ),
+                               $this->equalTo( [
+                                       'revision', 'page', 'user',
+                                       'temp_rev_comment' => 'revision_comment_temp', 'comment_rev_comment' => 'comment',
+                                       'temp_rev_user' => 'revision_actor_temp', 'actor_rev_user' => 'actor',
+                               ] ),
                                // We don't really care about the fields are they come from the selectField methods
                                $this->isType( 'array' ),
                                $this->equalTo( $conditions ),
@@ -729,13 +741,6 @@ class RevisionTest extends MediaWikiTestCase {
                );
        }
 
-       /**
-        * @covers Revision::getRevisionText
-        */
-       public function testGetRevisionText_returnsFalseWhenNoTextField() {
-               $this->assertFalse( Revision::getRevisionText( new stdClass() ) );
-       }
-
        public function provideTestGetRevisionText_returnsDecompressedTextFieldWhenNotExternal() {
                yield 'Just text' => [
                        (object)[ 'old_text' => 'SomeText' ],
@@ -803,7 +808,7 @@ class RevisionTest extends MediaWikiTestCase {
        public function testGetRevisionText_external_noOldId() {
                $this->setService(
                        'ExternalStoreFactory',
-                       new ExternalStoreFactory( [ 'ForTesting' ] )
+                       new ExternalStoreFactory( [ 'ForTesting' ], [ 'ForTesting://cluster1' ], 'test-id' )
                );
                $this->assertSame(
                        'AAAABBAAA',
@@ -825,14 +830,15 @@ class RevisionTest extends MediaWikiTestCase {
 
                $this->setService(
                        'ExternalStoreFactory',
-                       new ExternalStoreFactory( [ 'ForTesting' ] )
+                       new ExternalStoreFactory( [ 'ForTesting' ], [ 'ForTesting://cluster1' ], 'test-id' )
                );
 
                $lb = $this->getMockBuilder( LoadBalancer::class )
                        ->disableOriginalConstructor()
                        ->getMock();
+               $access = MediaWikiServices::getInstance()->getExternalStoreAccess();
 
-               $blobStore = new SqlBlobStore( $lb, $cache );
+               $blobStore = new SqlBlobStore( $lb, $access, $cache );
                $this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
 
                $this->assertSame(