Make LocalisationCache a service
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiIntegrationTestCase.php
index 07d135d..af5d88b 100644 (file)
@@ -23,8 +23,9 @@ use Wikimedia\TestingAccessWrapper;
 abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
 
        use MediaWikiCoversValidator;
-       use PHPUnit4And6Compat;
        use MediaWikiGroupValidator;
+       use MediaWikiTestCaseTrait;
+       use PHPUnit4And6Compat;
 
        /**
         * The original service locator. This is overridden during setUp().
@@ -136,10 +137,9 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
        private $overriddenServices = [];
 
        /**
-        * Table name prefixes. Oracle likes it shorter.
+        * Table name prefix.
         */
        const DB_PREFIX = 'unittest_';
-       const ORA_DB_PREFIX = 'ut_';
 
        /**
         * @var array
@@ -149,7 +149,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                'mysql',
                'sqlite',
                'postgres',
-               'oracle'
        ];
 
        public function __construct( $name = null, array $data = [], $dataName = '' ) {
@@ -224,7 +223,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
         *
         * @since 1.28
         *
-        * @param string[] $groups Groups the test user should be added to.
         * @return TestUser
         */
        public static function getTestSysop() {
@@ -256,7 +254,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                if ( !$page->exists() ) {
                        $user = self::getTestSysop()->getUser();
                        $page->doEditContent(
-                               new WikitextContent( 'UTContent' ),
+                               ContentHandler::makeContent( 'UTContent', $title ),
                                'UTPageSummary',
                                EDIT_NEW | EDIT_SUPPRESS_RC,
                                false,
@@ -406,6 +404,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
 
                $wgRequest = new FauxRequest();
                MediaWiki\Session\SessionManager::resetCache();
+               Language::clearCaches();
        }
 
        public function run( PHPUnit_Framework_TestResult $result = null ) {
@@ -635,6 +634,9 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                        }
                }
 
+               // Clear any cached test users so they don't retain references to old services
+               TestUserRegistry::clear();
+
                // Re-enable any disabled deprecation warnings
                MWDebug::clearLog();
                // Restore mw globals
@@ -1318,7 +1320,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
         * @since 1.32
         */
        public static function getTestPrefixFor( IDatabase $db ) {
-               return $db->getType() == 'oracle' ? self::ORA_DB_PREFIX : self::DB_PREFIX;
+               return self::DB_PREFIX;
        }
 
        /**
@@ -1411,32 +1413,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
         * @since 1.32
         */
        protected function addCoreDBData() {
-               if ( $this->db->getType() == 'oracle' ) {
-                       # Insert 0 user to prevent FK violations
-                       # Anonymous user
-                       if ( !$this->db->selectField( 'user', '1', [ 'user_id' => 0 ] ) ) {
-                               $this->db->insert( 'user', [
-                                       'user_id' => 0,
-                                       'user_name' => 'Anonymous' ], __METHOD__, [ 'IGNORE' ] );
-                       }
-
-                       # Insert 0 page to prevent FK violations
-                       # Blank page
-                       if ( !$this->db->selectField( 'page', '1', [ 'page_id' => 0 ] ) ) {
-                               $this->db->insert( 'page', [
-                                       'page_id' => 0,
-                                       'page_namespace' => 0,
-                                       'page_title' => ' ',
-                                       'page_restrictions' => null,
-                                       'page_is_redirect' => 0,
-                                       'page_is_new' => 0,
-                                       'page_random' => 0,
-                                       'page_touched' => $this->db->timestamp(),
-                                       'page_latest' => 0,
-                                       'page_len' => 0 ], __METHOD__, [ 'IGNORE' ] );
-                       }
-               }
-
                SiteStatsInit::doPlaceholderInit();
 
                User::resetIdByNameCache();
@@ -1520,7 +1496,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                        $prefix = self::getTestPrefixFor( $db );
                }
 
-               if ( ( $db->getType() == 'oracle' || !self::$useTemporaryTables ) && self::$reuseDB ) {
+               if ( !self::$useTemporaryTables && self::$reuseDB ) {
                        $db->tablePrefix( $prefix );
                        return false;
                }
@@ -1609,12 +1585,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                        return;
                }
 
-               // Assuming this isn't needed for External Store database, and not sure if the procedure
-               // would be available there.
-               if ( $db->getType() == 'oracle' ) {
-                       $db->query( 'BEGIN FILL_WIKI_INFO; END;', __METHOD__ );
-               }
-
                Hooks::run( 'UnitTestsAfterDatabaseSetup', [ $db, $prefix ] );
        }
 
@@ -1928,7 +1898,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                                $tablesUsed = array_unique( array_merge( $tablesUsed, $pageTables ) );
                        }
 
-                       // Postgres, Oracle, and MSSQL all use mwuser/pagecontent
+                       // Postgres uses mwuser/pagecontent
                        // instead of user/text. But Postgres does not remap the
                        // table name in tableExists(), so we mark the real table
                        // names as being used.
@@ -1971,7 +1941,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                        return;
                }
 
-               $truncate = in_array( $db->getType(), [ 'oracle', 'mysql' ] );
+               $truncate = in_array( $db->getType(), [ 'mysql' ] );
 
                if ( $truncate ) {
                        $db->query( 'TRUNCATE TABLE ' . $db->tableName( $tableName ), __METHOD__ );
@@ -2542,20 +2512,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                        'comment' => $comment,
                ] );
        }
-
-       /**
-        * Returns a PHPUnit constraint that matches anything other than a fixed set of values. This can
-        * be used to whitelist values, e.g.
-        *   $mock->expects( $this->never() )->method( $this->anythingBut( 'foo', 'bar' ) );
-        * which will throw if any unexpected method is called.
-        *
-        * @param mixed ...$values Values that are not matched
-        */
-       protected function anythingBut( ...$values ) {
-               return $this->logicalNot( $this->logicalOr(
-                       ...array_map( [ $this, 'matches' ], $values )
-               ) );
-       }
 }
 
 class_alias( 'MediaWikiIntegrationTestCase', 'MediaWikiTestCase' );