From: Krinkle Date: Tue, 22 Dec 2015 00:10:38 +0000 (+0000) Subject: Revert "API: Add a unit test to check all modules' i18n" X-Git-Tag: 1.31.0-rc.0~8589^2 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=7076a79e8649ad0478bd4bce4743f2919c5f3c69;p=lhc%2Fweb%2Fwiklou.git Revert "API: Add a unit test to check all modules' i18n" Reverting for now in the sake of productivity and restoration of the passing unit test status of extensions' master branches. Would recommend re-applying when the CI gate extensions are passing and ideally some notification ahead of time to wikitech-l. This reverts commit 0d3712dd6091b49ff79056388710ac502bed73a1. Change-Id: I9142e6161257459cd11db0ca4cdd57793cfee8fa --- diff --git a/tests/phpunit/structure/ApiDocumentationTest.php b/tests/phpunit/structure/ApiDocumentationTest.php deleted file mode 100644 index d2f96dc9cb..0000000000 --- a/tests/phpunit/structure/ApiDocumentationTest.php +++ /dev/null @@ -1,177 +0,0 @@ - false, - 'AllowCategorizedRecentChanges' => false, - ), - array( - 'MiserMode' => true, - 'AllowCategorizedRecentChanges' => true, - ), - ); - - /** - * Initialize/fetch the ApiMain instance for testing - * @return ApiMain - */ - private static function getMain() { - if ( !self::$main ) { - self::$main = new ApiMain( RequestContext::getMain() ); - self::$main->getContext()->setLanguage( 'en' ); - } - return self::$main; - } - - /** - * Test a message - * @param Message $msg - * @param string $what Which message is being checked - */ - private function checkMessage( $msg, $what ) { - $msg = ApiBase::makeMessage( $msg, self::getMain()->getContext() ); - $this->assertInstanceOf( 'Message', $msg, "$what message" ); - $this->assertTrue( $msg->exists(), "$what message {$msg->getKey()} exists" ); - } - - /** - * @dataProvider provideDocumentationExists - * @param string $path Module path - * @param array $globals Globals to set - */ - public function testDocumentationExists( $path, array $globals ) { - $main = self::getMain(); - - // Set configuration variables - $main->getContext()->setConfig( new MultiConfig( array( - new HashConfig( $globals ), - RequestContext::getMain()->getConfig(), - ) ) ); - foreach ( $globals as $k => $v ) { - $this->setMWGlobals( "wg$k", $v ); - } - - // Fetch module. - $module = TestingAccessWrapper::newFromObject( $main->getModuleFromPath( $path ) ); - - // Test messages for flags. - foreach ( $module->getHelpFlags() as $flag ) { - $this->checkMessage( "api-help-flag-$flag", "Flag $flag" ); - } - - // Module description messages. - $this->checkMessage( $module->getDescriptionMessage(), 'Module description' ); - - // Parameters. Lots of messages in here. - $params = $module->getFinalParams( ApiBase::GET_VALUES_FOR_HELP ); - $tags = array(); - foreach ( $params as $name => $settings ) { - if ( !is_array( $settings ) ) { - $settings = array(); - } - - // Basic description message - if ( isset( $settings[ApiBase::PARAM_HELP_MSG] ) ) { - $msg = $settings[ApiBase::PARAM_HELP_MSG]; - } else { - $msg = "apihelp-{$path}-param-{$name}"; - } - $this->checkMessage( $msg, "Parameter $name description" ); - - // If param-per-value is in use, each value's message - if ( isset( $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE] ) ) { - $this->assertInternalType( 'array', $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE], - "Parameter $name PARAM_HELP_MSG_PER_VALUE is array" ); - $this->assertInternalType( 'array', $settings[ApiBase::PARAM_TYPE], - "Parameter $name PARAM_TYPE is array for msg-per-value mode" ); - $valueMsgs = $settings[ApiBase::PARAM_HELP_MSG_PER_VALUE]; - foreach ( $settings[ApiBase::PARAM_TYPE] as $value ) { - if ( isset( $valueMsgs[$value] ) ) { - $msg = $valueMsgs[$value]; - } else { - $msg = "apihelp-{$path}-paramvalue-{$name}-{$value}"; - } - $this->checkMessage( $msg, "Parameter $name value $value" ); - } - } - - // Appended messages (e.g. "disabled in miser mode") - if ( isset( $settings[ApiBase::PARAM_HELP_MSG_APPEND] ) ) { - $this->assertInternalType( 'array', $settings[ApiBase::PARAM_HELP_MSG_APPEND], - "Parameter $name PARAM_HELP_MSG_APPEND is array" ); - foreach ( $settings[ApiBase::PARAM_HELP_MSG_APPEND] as $i => $msg ) { - $this->checkMessage( $msg, "Parameter $name HELP_MSG_APPEND #$i" ); - } - } - - // Info tags (e.g. "only usable in mode 1") are typically shared by - // several parameters, so accumulate them and test them later. - if ( !empty( $settings[ApiBase::PARAM_HELP_MSG_INFO] ) ) { - foreach ( $settings[ApiBase::PARAM_HELP_MSG_INFO] as $i ) { - $tags[array_shift( $i )] = 1; - } - } - } - - // Info tags (e.g. "only usable in mode 1") accumulated above - foreach ( $tags as $tag => $dummy ) { - $this->checkMessage( "apihelp-{$path}-paraminfo-{$tag}", "HELP_MSG_INFO tag $tag" ); - } - - // Messages for examples. - foreach ( $module->getExamplesMessages() as $qs => $msg ) { - $this->checkMessage( $msg, "Example $qs" ); - } - } - - public static function provideDocumentationExists() { - $main = self::getMain(); - $paths = self::getSubModulePaths( $main->getModuleManager() ); - array_unshift( $paths, $main->getModulePath() ); - - $ret = array(); - foreach ( $paths as $path ) { - foreach ( self::$testGlobals as $globals ) { - $g = array(); - foreach ( $globals as $k => $v ) { - $g[] = "$k=" . var_export( $v, 1 ); - } - $k = "Module $path with " . join( ', ', $g ); - $ret[$k] = array( $path, $globals ); - } - } - return $ret; - } - - /** - * Return paths of all submodules in an ApiModuleManager, recursively - * @param ApiModuleManager $manager - * @return string[] - */ - protected static function getSubModulePaths( ApiModuleManager $manager ) { - $paths = array(); - foreach ( $manager->getNames() as $name ) { - $module = $manager->getModule( $name ); - $paths[] = $module->getModulePath(); - $subManager = $module->getModuleManager(); - if ( $subManager ) { - $paths = array_merge( $paths, self::getSubModulePaths( $subManager ) ); - } - } - return $paths; - } -}