Merge "Exclude redirects from Special:Fewestrevisions"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiIntegrationTestCase.php
index 999ba47..07d135d 100644 (file)
@@ -24,6 +24,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
 
        use MediaWikiCoversValidator;
        use PHPUnit4And6Compat;
+       use MediaWikiGroupValidator;
 
        /**
         * The original service locator. This is overridden during setUp().
@@ -179,8 +180,13 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
        }
 
        public static function setUpBeforeClass() {
+               global $IP;
                parent::setUpBeforeClass();
-               \PHPUnit\Framework\Assert::assertFileExists( 'LocalSettings.php' );
+               if ( !file_exists( "$IP/LocalSettings.php" ) ) {
+                       echo 'A working MediaWiki installation with a configured LocalSettings.php file is'
+                       . ' required for tests that extend ' . self::class;
+                       die();
+               }
                self::initializeForStandardPhpunitEntrypointIfNeeded();
 
                // Get the original service locator
@@ -534,6 +540,11 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
 
        protected function setUp() {
                parent::setUp();
+               $reflection = new ReflectionClass( $this );
+               // TODO: Eventually we should assert for test presence in /integration/
+               if ( strpos( $reflection->getFilename(), '/unit/' ) !== false ) {
+                       $this->fail( 'This integration test should not be in "tests/phpunit/unit" !' );
+               }
                $this->called['setUp'] = true;
 
                $this->phpErrorLevel = intval( ini_get( 'error_reporting' ) );
@@ -1220,8 +1231,23 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
        }
 
        /**
+        * Overrides specific user permissions until services are reloaded
         *
         * @since 1.34
+        *
+        * @param User $user
+        * @param string[]|string $permissions
+        *
+        * @throws Exception
+        */
+       public function overrideUserPermissions( $user, $permissions = [] ) {
+               MediaWikiServices::getInstance()->getPermissionManager()->overrideUserRightsForTesting(
+                       $user,
+                       $permissions
+               );
+       }
+
+       /**
         * Sets the logger for a specified channel, for the duration of the test.
         * @since 1.27
         * @param string $channel
@@ -1304,17 +1330,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                return $this->tablesUsed || $this->isTestInDatabaseGroup();
        }
 
-       /**
-        * @return bool
-        * @since 1.32
-        */
-       protected function isTestInDatabaseGroup() {
-               // If the test class says it belongs to the Database group, it needs the database.
-               // NOTE: This ONLY checks for the group in the class level doc comment.
-               $rc = new ReflectionClass( $this );
-               return (bool)preg_match( '/@group +Database/im', $rc->getDocComment() );
-       }
-
        /**
         * Insert a new page.
         *