wiki.techinc.nl/tests/phpunit/structure/ApiPrefixUniquenessTest.php
addshore 959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00

48 lines
1.3 KiB
PHP

<?php
/**
* Checks that all API query modules, core and extensions, have unique prefixes.
*
* @group API
*/
class ApiPrefixUniquenessTest extends MediaWikiIntegrationTestCase {
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
}
}