config: Add new ConfigRepository
[lhc/web/wiklou.git] / tests / phpunit / includes / RevisionDbTestBase.php
index 61f1802..73050e0 100644 (file)
@@ -43,9 +43,25 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                );
        }
 
+       protected function addCoreDBData() {
+               // Blank out. This would fail with a modified schema, and we don't need it.
+       }
+
+       /**
+        * @return int
+        */
+       abstract protected function getMcrMigrationStage();
+
+       /**
+        * @return string[]
+        */
+       abstract protected function getMcrTablesToReset();
+
        protected function setUp() {
                global $wgContLang;
 
+               $this->tablesUsed += $this->getMcrTablesToReset();
+
                parent::setUp();
 
                $this->mergeMwGlobalArrayValue(
@@ -72,11 +88,17 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                );
 
                $this->setMwGlobals( 'wgContentHandlerUseDB', $this->getContentHandlerUseDB() );
+               $this->setMwGlobals(
+                       'wgMultiContentRevisionSchemaMigrationStage',
+                       $this->getMcrMigrationStage()
+               );
 
                MWNamespace::clearCaches();
                // Reset namespace cache
                $wgContLang->resetNamespaces();
 
+               $this->overrideMwServices();
+
                if ( !$this->testPage ) {
                        /**
                         * We have to create a new page for each subclass as the page creation may result
@@ -244,7 +266,6 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                        [
                                'rev_id',
                                'rev_page',
-                               'rev_text_id',
                                'rev_minor_edit',
                                'rev_deleted',
                                'rev_len',
@@ -255,7 +276,6 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                        [ [
                                strval( $rev->getId() ),
                                strval( $this->testPage->getId() ),
-                               strval( $textId ),
                                '0',
                                '0',
                                '13',
@@ -265,19 +285,52 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                );
        }
 
+       public function provideInsertOn_exceptionOnIncomplete() {
+               $content = new TextContent( '' );
+               $user = User::newFromName( 'Foo' );
+
+               yield 'no parent' => [
+                       [
+                               'content' => $content,
+                               'comment' => 'test',
+                               'user' => $user,
+                       ],
+                       IncompleteRevisionException::class,
+                       "rev_page field must not be 0!"
+               ];
+
+               yield 'no comment' => [
+                       [
+                               'content' => $content,
+                               'page' => 7,
+                               'user' => $user,
+                       ],
+                       IncompleteRevisionException::class,
+                       "comment must not be NULL!"
+               ];
+
+               yield 'no content' => [
+                       [
+                               'comment' => 'test',
+                               'page' => 7,
+                               'user' => $user,
+                       ],
+                       IncompleteRevisionException::class,
+                       "Uninitialized field: content_address" // XXX: message may change
+               ];
+       }
+
        /**
+        * @dataProvider provideInsertOn_exceptionOnIncomplete
         * @covers Revision::insertOn
         */
-       public function testInsertOn_exceptionOnNoPage() {
+       public function testInsertOn_exceptionOnIncomplete( $array, $expException, $expMessage ) {
                // If an ExternalStore is set don't use it.
                $this->setMwGlobals( 'wgDefaultExternalStore', false );
-               $this->setExpectedException(
-                       IncompleteRevisionException::class,
-                       "rev_page field must not be 0!"
-               );
+               $this->setExpectedException( $expException, $expMessage );
 
                $title = Title::newFromText( 'Nonexistant-' . __METHOD__ );
-               $rev = new Revision( [], 0, $title );
+               $rev = new Revision( $array, 0, $title );
 
                $rev->insertOn( wfGetDB( DB_MASTER ) );
        }
@@ -348,12 +401,6 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                                return $f + [ 'ar_namespace', 'ar_title' ];
                        },
                ];
-               yield [
-                       function ( $f ) {
-                               unset( $f['ar_text'] );
-                               return $f;
-                       },
-               ];
                yield [
                        function ( $f ) {
                                unset( $f['ar_text_id'] );
@@ -398,6 +445,9 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                        $services->getService( '_SqlBlobStore' ),
                        $services->getMainWANObjectCache(),
                        $services->getCommentStore(),
+                       $services->getContentModelStore(),
+                       $services->getSlotRoleStore(),
+                       $this->getMcrMigrationStage(),
                        $services->getActorMigration()
                );
 
@@ -903,7 +953,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                $rev = new Revision( [
                        'page' => $this->testPage->getId(),
                        'content_model' => $this->testPage->getContentModel(),
-                       'text_id' => 123456789, // not in the test DB
+                       'id' => 123456789, // not in the test DB
                ] );
 
                Wikimedia\suppressWarnings(); // bad text_id will trigger a warning.
@@ -1352,6 +1402,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
         */
        public function testNewKnownCurrent() {
                // Setup the services
+               $this->resetGlobalServices();
                $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
                $this->setService( 'MainWANObjectCache', $cache );
                $db = wfGetDB( DB_MASTER );
@@ -1361,7 +1412,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                $rev = $this->testPage->getRevision();
 
                // Clear any previous cache for the revision during creation
-               $key = $cache->makeGlobalKey( 'revision-row-1.29',
+               $key = $cache->makeGlobalKey( RevisionStore::ROW_CACHE_KEY,
                        $db->getDomainID(),
                        $rev->getPage(),
                        $rev->getId()