<?php
+use Wikimedia\TestingAccessWrapper;
+
/**
* @group API
+ * @group Database
* @group medium
*
* @covers ApiMain
* @param string|bool $error False if no error expected
*/
public function testAssert( $registered, $rights, $assert, $error ) {
- $user = new User();
if ( $registered ) {
- $user->setId( 1 );
+ $user = $this->getMutableTestUser()->getUser();
+ $user->load(); // load before setting mRights
+ } else {
+ $user = new User();
}
$user->mRights = $rights;
try {
], null, null, $user );
$this->assertFalse( $error ); // That no error was expected
} catch ( ApiUsageException $e ) {
- $this->assertTrue( self::apiExceptionHasCode( $e, $error ) );
+ $this->assertTrue( self::apiExceptionHasCode( $e, $error ),
+ "Error '{$e->getMessage()}' matched expected '$error'" );
}
}
* Test if all classes in the main module manager exists
*/
public function testClassNamesInModuleManager() {
- global $wgAutoloadLocalClasses, $wgAutoloadClasses;
-
- // wgAutoloadLocalClasses has precedence, just like in includes/AutoLoader.php
- $classes = $wgAutoloadLocalClasses + $wgAutoloadClasses;
-
$api = new ApiMain(
new FauxRequest( [ 'action' => 'query', 'meta' => 'siteinfo' ] )
);
$modules = $api->getModuleManager()->getNamesWithClasses();
+
foreach ( $modules as $name => $class ) {
- $this->assertArrayHasKey(
- $class,
- $classes,
- 'Class ' . $class . ' for api module ' . $name . ' not in autoloader (with exact case)'
+ $this->assertTrue(
+ class_exists( $class ),
+ 'Class ' . $class . ' for api module ' . $name . ' does not exist (with exact case)'
);
}
}
}
public static function provideApiErrorFormatterCreation() {
- global $wgContLang;
-
return [
'Default (BC)' => [ [], [
'uselang' => 'ru',
'uselang=content' => [
[ 'uselang' => 'content', 'errorformat' => 'plaintext' ],
[
- 'uselang' => $wgContLang->getCode(),
+ 'uselang' => 'en',
'class' => ApiErrorFormatter::class,
- 'lang' => $wgContLang->getCode(),
+ 'lang' => 'en',
'format' => 'plaintext',
'usedb' => false,
]
[
'uselang' => 'ru',
'class' => ApiErrorFormatter::class,
- 'lang' => $wgContLang->getCode(),
+ 'lang' => 'en',
'format' => 'plaintext',
'usedb' => false,
]
$context->setRequest( new FauxRequest( [ 'errorformat' => 'plaintext' ] ) );
$context->setLanguage( 'en' );
$context->setConfig( new MultiConfig( [
- new HashConfig( [ 'ShowHostnames' => true, 'ShowSQLErrors' => false ] ),
+ new HashConfig( [
+ 'ShowHostnames' => true, 'ShowSQLErrors' => false,
+ 'ShowExceptionDetails' => true, 'ShowDBErrorBacktrace' => true,
+ ] ),
$context->getConfig()
] ) );
);
}
- // Not static so $this->getMock() can be used
+ // Not static so $this can be used
public function provideExceptionErrors() {
$reqId = WebRequest::getRequestId();
$doclink = wfExpandUrl( wfScript( 'api' ) );
MWExceptionHandler::getRedactedTraceAsString( $ex )
)->inLanguage( 'en' )->useDatabase( false )->text();
- $dbex = new DBQueryError( $this->getMock( 'IDatabase' ), 'error', 1234, 'SELECT 1', __METHOD__ );
+ $dbex = new DBQueryError(
+ $this->createMock( 'IDatabase' ),
+ 'error', 1234, 'SELECT 1', __METHOD__ );
$dbtrace = wfMessage( 'api-exception-trace',
get_class( $dbex ),
$dbex->getFile(),
MWExceptionHandler::getRedactedTraceAsString( $dbex )
)->inLanguage( 'en' )->useDatabase( false )->text();
+ MediaWiki\suppressWarnings();
+ $usageEx = new UsageException( 'Usage exception!', 'ue', 0, [ 'foo' => 'bar' ] );
+ MediaWiki\restoreWarnings();
+
$apiEx1 = new ApiUsageException( null,
StatusValue::newFatal( new ApiRawMessage( 'An error', 'sv-error1' ) ) );
TestingAccessWrapper::newFromObject( $apiEx1 )->modulePath = 'foo+bar';
]
],
[
- new UsageException( 'Usage exception!', 'ue', 0, [ 'foo' => 'bar' ] ),
+ $usageEx,
[ 'existing-error', 'ue' ],
[
'warnings' => [
[ 'code' => 'existing-error', 'text' => 'existing error', 'module' => 'main' ],
[ 'code' => 'ue', 'text' => "Usage exception!", 'data' => [ 'foo' => 'bar' ] ]
],
- 'docref' => "See $doclink for API usage.",
+ 'docref' => "See $doclink for API usage. Subscribe to the mediawiki-api-announce mailing " .
+ "list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> " .
+ "for notice of API deprecations and breaking changes.",
'servedby' => wfHostname(),
]
],
[ 'code' => 'sv-error1', 'text' => 'An error', 'module' => 'foo+bar' ],
[ 'code' => 'sv-error2', 'text' => 'Another error', 'module' => 'foo+bar' ],
],
- 'docref' => "See $doclink for API usage.",
+ 'docref' => "See $doclink for API usage. Subscribe to the mediawiki-api-announce mailing " .
+ "list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> " .
+ "for notice of API deprecations and breaking changes.",
'servedby' => wfHostname(),
]
],