3use Wikimedia\TestingAccessWrapper;
23 'AllowCategorizedRecentChanges' =>
false,
27 'AllowCategorizedRecentChanges' =>
true,
38 self::$main->getContext()->setLanguage(
'en' );
39 self::$main->getContext()->setTitle(
40 Title::makeTitle(
NS_SPECIAL,
'Badtitle/dummy title for ApiStructureTest' )
53 $this->assertInstanceOf(
'Message', $msg,
"$what message" );
54 $this->assertTrue( $msg->exists(),
"$what message {$msg->getKey()} exists" );
70 foreach ( $globals as $k => $v ) {
75 $module = TestingAccessWrapper::newFromObject(
$main->getModuleFromPath( $path ) );
78 foreach ( $module->getHelpFlags() as $flag ) {
79 $this->
checkMessage(
"api-help-flag-$flag",
"Flag $flag" );
83 $this->
checkMessage( $module->getSummaryMessage(),
'Module summary' );
84 $this->
checkMessage( $module->getExtendedDescription(),
'Module help top text' );
89 foreach (
$params as $name => $settings ) {
90 if ( !is_array( $settings ) ) {
98 $msg =
"apihelp-{$path}-param-{$name}";
100 $this->
checkMessage( $msg,
"Parameter $name description" );
105 "Parameter $name PARAM_HELP_MSG_PER_VALUE is array" );
107 "Parameter $name PARAM_TYPE is array for msg-per-value mode" );
110 if ( isset( $valueMsgs[
$value] ) ) {
111 $msg = $valueMsgs[
$value];
113 $msg =
"apihelp-{$path}-paramvalue-{$name}-{$value}";
115 $this->
checkMessage( $msg,
"Parameter $name value $value" );
122 "Parameter $name PARAM_HELP_MSG_APPEND is array" );
124 $this->
checkMessage( $msg,
"Parameter $name HELP_MSG_APPEND #$i" );
132 $tags[array_shift( $i )] = 1;
138 foreach ( $tags as $tag => $dummy ) {
139 $this->
checkMessage(
"apihelp-{$path}-paraminfo-{$tag}",
"HELP_MSG_INFO tag $tag" );
143 foreach ( $module->getExamplesMessages() as $qs => $msg ) {
144 $this->assertStringStartsNotWith(
'api.php?', $qs,
145 "Query string must not begin with 'api.php?'" );
153 array_unshift( $paths,
$main->getModulePath() );
156 foreach ( $paths as $path ) {
157 foreach ( self::$testGlobals as $globals ) {
159 foreach ( $globals as $k => $v ) {
160 $g[] =
"$k=" . var_export( $v, 1 );
162 $k =
"Module $path with " . implode(
', ', $g );
175 $module = TestingAccessWrapper::newFromObject(
$main->getModuleFromPath( $path ) );
177 $paramsPlain = $module->getFinalParams();
181 $this->assertTrue(
true );
183 foreach ( [ $paramsPlain, $paramsForHelp ] as
$params ) {
184 foreach (
$params as $param => $config ) {
190 .
': PARAM_ISMULTI_LIMIT* only makes sense when PARAM_ISMULTI is true' );
193 .
': PARAM_ISMULTI_LIMIT1 and PARAM_ISMULTI_LIMIT2 must be used together' );
195 .
'PARAM_ISMULTI_LIMIT1 must be an integer' );
197 .
'PARAM_ISMULTI_LIMIT2 must be an integer' );
200 .
'PARAM_ISMULTI limit cannot be smaller for users with apihighlimits rights' );
212 array_unshift( $paths,
$main->getModulePath() );
215 foreach ( $paths as $path ) {
228 foreach ( $manager->
getNames() as $name ) {
230 $paths[] = $module->getModulePath();
231 $subManager = $module->getModuleManager();
233 $paths = array_merge( $paths, self::getSubModulePaths( $subManager ) );
static makeMessage( $msg, IContextSource $context, array $params=null)
Create a Message from a string or array.
const PARAM_ISMULTI_LIMIT1
(integer) Maximum number of values, for normal users.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
const PARAM_ISMULTI_LIMIT2
(integer) Maximum number of values, for users with the apihighimits right.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thoro...
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
This is the main API class, used for both external and internal processing.
This class holds a list of modules and handles instantiation.
getModule( $moduleName, $group=null, $ignoreCache=false)
Get module instance by name, or instantiate it if it does not exist.
getNames( $group=null)
Get an array of modules in a specific group or all if no group is set.
Checks that all API modules, core and extensions, conform to the conventions:
static provideDocumentationExists()
static array $testGlobals
Sets of globals to test.
static provideParameterConsistency()
static getSubModulePaths(ApiModuleManager $manager)
Return paths of all submodules in an ApiModuleManager, recursively.
testDocumentationExists( $path, array $globals)
provideDocumentationExists
testParameterConsistency( $path)
provideParameterConsistency
checkMessage( $msg, $what)
Test a message.
static getMain()
Initialize/fetch the ApiMain instance for testing.
A Config instance which stores all settings as a member variable.
Provides a fallback sequence for Config objects.
static getMain()
Static methods.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret