From f6d65e533c62f6deb21342d4901ece24497b433e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 4 Jun 2015 07:31:04 +0200 Subject: Update to MediaWiki 1.25.1 --- tests/phpunit/structure/AutoLoaderTest.php | 39 ++++++++++++------- tests/phpunit/structure/AvailableRightsTest.php | 51 +++++++++++++++++++++++++ tests/phpunit/structure/ResourcesTest.php | 5 ++- 3 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 tests/phpunit/structure/AvailableRightsTest.php (limited to 'tests/phpunit/structure') diff --git a/tests/phpunit/structure/AutoLoaderTest.php b/tests/phpunit/structure/AutoLoaderTest.php index 2bdc9c9a..cde6547a 100644 --- a/tests/phpunit/structure/AutoLoaderTest.php +++ b/tests/phpunit/structure/AutoLoaderTest.php @@ -2,27 +2,22 @@ class AutoLoaderTest extends MediaWikiTestCase { protected function setUp() { - global $wgAutoloadLocalClasses, $wgAutoloadClasses; - parent::setUp(); // Fancy dance to trigger a rebuild of AutoLoader::$autoloadLocalClassesLower - $this->testLocalClasses = array( - 'TestAutoloadedLocalClass' => __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php', - 'TestAutoloadedCamlClass' => __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php', + $this->mergeMwGlobalArrayValue( 'wgAutoloadLocalClasses', array( + 'TestAutoloadedLocalClass' => + __DIR__ . '/../data/autoloader/TestAutoloadedLocalClass.php', + 'TestAutoloadedCamlClass' => + __DIR__ . '/../data/autoloader/TestAutoloadedCamlClass.php', 'TestAutoloadedSerializedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedSerializedClass.php', - ); - $this->setMwGlobals( - 'wgAutoloadLocalClasses', - $this->testLocalClasses + $wgAutoloadLocalClasses - ); + ) ); AutoLoader::resetAutoloadLocalClassesLower(); - $this->testExtensionClasses = array( + $this->mergeMwGlobalArrayValue( 'wgAutoloadClasses', array( 'TestAutoloadedClass' => __DIR__ . '/../data/autoloader/TestAutoloadedClass.php', - ); - $this->setMwGlobals( 'wgAutoloadClasses', $this->testExtensionClasses + $wgAutoloadClasses ); + ) ); } /** @@ -49,7 +44,7 @@ class AutoLoaderTest extends MediaWikiTestCase { $files = array_unique( $expected ); - foreach ( $files as $file ) { + foreach ( $files as $class => $file ) { // Only prefix $IP if it doesn't have it already. // Generally local classes don't have it, and those from extensions and test suites do. if ( substr( $file, 0, 1 ) != '/' && substr( $file, 1, 1 ) != ':' ) { @@ -58,7 +53,19 @@ class AutoLoaderTest extends MediaWikiTestCase { $filePath = $file; } + if ( !file_exists( $filePath ) ) { + $actual[$class] = "[file '$filePath' does not exist]"; + continue; + } + + wfSuppressWarnings(); $contents = file_get_contents( $filePath ); + wfRestoreWarnings(); + + if ( $contents === false ) { + $actual[$class] = "[couldn't read file '$filePath']"; + continue; + } // We could use token_get_all() here, but this is faster $matches = array(); @@ -123,10 +130,14 @@ class AutoLoaderTest extends MediaWikiTestCase { } function testWrongCaseClass() { + $this->setMwGlobals( 'wgAutoloadAttemptLowercase', true ); + $this->assertTrue( class_exists( 'testautoLoadedcamlCLASS' ) ); } function testWrongCaseSerializedClass() { + $this->setMwGlobals( 'wgAutoloadAttemptLowercase', true ); + $dummyCereal = 'O:29:"testautoloadedserializedclass":0:{}'; $uncerealized = unserialize( $dummyCereal ); $this->assertFalse( $uncerealized instanceof __PHP_Incomplete_Class, diff --git a/tests/phpunit/structure/AvailableRightsTest.php b/tests/phpunit/structure/AvailableRightsTest.php new file mode 100644 index 00000000..51d31aaa --- /dev/null +++ b/tests/phpunit/structure/AvailableRightsTest.php @@ -0,0 +1,51 @@ + + */ +class AvailableRightsTest extends PHPUnit_Framework_TestCase { + + /** + * Returns all rights that should be in $wgAvailableRights + all rights + * registered via the 'UserGetAllRights' hook + all "core" rights. + * + * @return string[] + */ + private function getAllVisibleRights() { + global $wgGroupPermissions, $wgRevokePermissions; + + $rights = User::getAllRights(); + + foreach( $wgGroupPermissions as $permissions ) { + $rights = array_merge( $rights, array_keys( $permissions ) ); + } + + foreach( $wgRevokePermissions as $permissions ) { + $rights = array_merge( $rights, array_keys( $permissions ) ); + } + + $rights = array_unique( $rights ); + sort( $rights ); + + return $rights; + } + + public function testAvailableRights() { + $missingRights = array_diff( + $this->getAllVisibleRights(), + User::getAllRights() + ); + + $this->assertEquals( + array(), + // Re-index to produce nicer output, keys are meaningless. + array_values( $missingRights ), + 'Additional user rights need to be added to $wgAvailableRights or ' . + 'via the "UserGetAllRights" hook. See the instructions at: ' . + 'https://www.mediawiki.org/wiki/Manual:User_rights#Adding_new_rights' + ); + } +} diff --git a/tests/phpunit/structure/ResourcesTest.php b/tests/phpunit/structure/ResourcesTest.php index 2396ea29..d2b699d9 100644 --- a/tests/phpunit/structure/ResourcesTest.php +++ b/tests/phpunit/structure/ResourcesTest.php @@ -12,7 +12,6 @@ * @copyright © 2012, Santhosh Thottingal * @copyright © 2012, Timo Tijhof * - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ class ResourcesTest extends MediaWikiTestCase { @@ -91,6 +90,10 @@ class ResourcesTest extends MediaWikiTestCase { foreach ( $data['modules'] as $moduleName => $module ) { $moduleTargets = $module->getTargets(); foreach ( $module->getDependencies() as $dep ) { + if ( !isset( $data['modules'][$dep] ) ) { + // Missing dependencies reported by testMissingDependencies + continue; + } $targets = $data['modules'][$dep]->getTargets(); foreach ( $moduleTargets as $moduleTarget ) { $this->assertContains( -- cgit v1.2.2