Merge "selenium: invoke jobs to enforce eventual consistency"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index 114ad7e..af014b9 100644 (file)
@@ -196,9 +196,17 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
         *
         * @param Title|string|null $title
         * @return WikiPage
-        * @throws MWException
+        * @throws MWException If this test cases's needsDB() method doesn't return true.
+        *         Test cases can use "@group Database" to enable database test support,
+        *         or list the tables under testing in $this->tablesUsed, or override the
+        *         needsDB() method.
         */
        protected function getExistingTestPage( $title = null ) {
+               if ( !$this->needsDB() ) {
+                       throw new MWException( 'When testing which pages, the test cases\'s needsDB()' .
+                               ' method should return true. Use @group Database or $this->tablesUsed.' );
+               }
+
                $title = ( $title === null ) ? 'UTPage' : $title;
                $title = is_string( $title ) ? Title::newFromText( $title ) : $title;
                $page = WikiPage::factory( $title );
@@ -224,9 +232,17 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
         *
         * @param Title|string|null $title
         * @return WikiPage
-        * @throws MWException
+        * @throws MWException If this test cases's needsDB() method doesn't return true.
+        *         Test cases can use "@group Database" to enable database test support,
+        *         or list the tables under testing in $this->tablesUsed, or override the
+        *         needsDB() method.
         */
        protected function getNonexistingTestPage( $title = null ) {
+               if ( !$this->needsDB() ) {
+                       throw new MWException( 'When testing which pages, the test cases\'s needsDB()' .
+                               ' method should return true. Use @group Database or $this->tablesUsed.' );
+               }
+
                $title = ( $title === null ) ? 'UTPage-' . rand( 0, 100000 ) : $title;
                $title = is_string( $title ) ? Title::newFromText( $title ) : $title;
                $page = WikiPage::factory( $title );
@@ -1140,6 +1156,10 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
         * @param int|null $namespace Namespace id (name cannot already contain namespace)
         * @param User|null $user If null, static::getTestSysop()->getUser() is used.
         * @return array Title object and page id
+        * @throws MWException If this test cases's needsDB() method doesn't return true.
+        *         Test cases can use "@group Database" to enable database test support,
+        *         or list the tables under testing in $this->tablesUsed, or override the
+        *         needsDB() method.
         */
        protected function insertPage(
                $pageName,
@@ -1147,6 +1167,11 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
                $namespace = null,
                User $user = null
        ) {
+               if ( !$this->needsDB() ) {
+                       throw new MWException( 'When testing which pages, the test cases\'s needsDB()' .
+                               ' method should return true. Use @group Database or $this->tablesUsed.' );
+               }
+
                if ( is_string( $pageName ) ) {
                        $title = Title::newFromText( $pageName, $namespace );
                } else {
@@ -1288,52 +1313,6 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
                self::$dbSetup = false;
        }
 
-       /**
-        * Prepares the given database connection for usage in the context of usage tests.
-        * This sets up clones database tables and changes the table prefix as appropriate.
-        * If the database connection already has cloned tables, calling this method has no
-        * effect. The tables are not re-cloned or reset in that case.
-        *
-        * @param IMaintainableDatabase $db
-        */
-       protected function prepareConnectionForTesting( IMaintainableDatabase $db ) {
-               if ( !self::$dbSetup ) {
-                       throw new LogicException(
-                               'Cannot use prepareConnectionForTesting()'
-                               . ' if the test case is not defined to use the database!'
-                       );
-               }
-
-               if ( isset( $db->_originalTablePrefix ) ) {
-                       // The DB connection was already prepared for testing.
-                       return;
-               }
-
-               $testPrefix = self::getTestPrefixFor( $db );
-               $oldPrefix = $db->tablePrefix();
-
-               $tablesCloned = self::listTables( $db );
-
-               if ( $oldPrefix === $testPrefix ) {
-                       // The database connection already has the test prefix, but presumably not
-                       // the cloned tables. This is the typical case, since the LBFactory will
-                       // have the prefix set during testing, but LoadBalancers will still return
-                       // connections that don't have the cloned table structure.
-                       $oldPrefix = self::$oldTablePrefix;
-               }
-
-               $dbClone = new CloneDatabase( $db, $tablesCloned, $testPrefix, $oldPrefix );
-               $dbClone->useTemporaryTables( self::$useTemporaryTables );
-
-               $db->_originalTablePrefix = $oldPrefix;
-
-               if ( ( $db->getType() == 'oracle' || !self::$useTemporaryTables ) && self::$reuseDB ) {
-                       throw new LogicException( 'Cannot clone database tables' );
-               } else {
-                       $dbClone->cloneTableStructure();
-               }
-       }
-
        /**
         * Setups a database with cloned tables using the given prefix.
         *
@@ -2291,8 +2270,17 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
         * @param string $summary Optional summary string for the revision
         * @param int $defaultNs Optional namespace id
         * @return array Array as returned by WikiPage::doEditContent()
+        * @throws MWException If this test cases's needsDB() method doesn't return true.
+        *         Test cases can use "@group Database" to enable database test support,
+        *         or list the tables under testing in $this->tablesUsed, or override the
+        *         needsDB() method.
         */
        protected function editPage( $pageName, $text, $summary = '', $defaultNs = NS_MAIN ) {
+               if ( !$this->needsDB() ) {
+                       throw new MWException( 'When testing which pages, the test cases\'s needsDB()' .
+                               ' method should return true. Use @group Database or $this->tablesUsed.' );
+               }
+
                $title = Title::newFromText( $pageName, $defaultNs );
                $page = WikiPage::factory( $title );