Signed-off-by: Brad Jorsch <bjorsch@wikimedia.org> Change-Id: I30758f2ac95fd8ae361ef8079abdfb0a82d92e34
49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Checks that all API query modules, core and extensions, have unique prefixes.
|
|
*
|
|
* @group API
|
|
* @coversNothing
|
|
*/
|
|
class ApiPrefixUniquenessTest extends MediaWikiTestCase {
|
|
|
|
public function testPrefixes() {
|
|
$main = new ApiMain( new FauxRequest() );
|
|
$query = new ApiQuery( $main, 'foo' );
|
|
$moduleManager = $query->getModuleManager();
|
|
|
|
$modules = $moduleManager->getNames();
|
|
$prefixes = [];
|
|
|
|
foreach ( $modules as $name ) {
|
|
$module = $moduleManager->getModule( $name );
|
|
$class = get_class( $module );
|
|
|
|
$prefix = $module->getModulePrefix();
|
|
if ( $prefix === '' /* HACK: T196962 */ || $prefix === 'wbeu' ) {
|
|
continue;
|
|
}
|
|
|
|
if ( isset( $prefixes[$prefix] ) ) {
|
|
$this->fail(
|
|
"Module prefix '{$prefix}' is shared between {$class} and {$prefixes[$prefix]}"
|
|
);
|
|
}
|
|
$prefixes[$module->getModulePrefix()] = $class;
|
|
|
|
if ( $module instanceof ApiQueryGeneratorBase ) {
|
|
// namespace with 'g', a generator can share a prefix with a module
|
|
$prefix = 'g' . $prefix;
|
|
if ( isset( $prefixes[$prefix] ) ) {
|
|
$this->fail(
|
|
"Module prefix '{$prefix}' is shared between {$class} and {$prefixes[$prefix]}" .
|
|
" (as a generator)"
|
|
);
|
|
}
|
|
$prefixes[$module->getModulePrefix()] = $class;
|
|
}
|
|
}
|
|
$this->assertTrue( true ); // dummy call to make this test non-incomplete
|
|
}
|
|
}
|