X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiMainTest.php;h=a5518a125249b1bcde6a4d36da2b97cd749d9393;hb=a88f1d6b58613cbfa5c24c97887197a41ce66908;hp=20d758e3aa70ae737dadcbf7cf6173b5e143a8b3;hpb=5354c219cd436583c0a0e401718018e8569f84e2;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiMainTest.php b/tests/phpunit/includes/api/ApiMainTest.php index 20d758e3aa..a5518a1252 100644 --- a/tests/phpunit/includes/api/ApiMainTest.php +++ b/tests/phpunit/includes/api/ApiMainTest.php @@ -1,5 +1,6 @@ true Request is a POST - * cdn => true CDN is enabled ($wgUseSquid) + * cdn => true CDN is enabled ($wgUseCdn) */ public function testCheckConditionalRequestHeaders( $headers, $conditions, $status, $options = [] @@ -507,7 +508,7 @@ class ApiMainTest extends ApiTestCase { $priv->mInternalMode = false; if ( !empty( $options['cdn'] ) ) { - $this->setMwGlobals( 'wgUseSquid', true ); + $this->setMwGlobals( 'wgUseCdn', true ); } // Can't do this in TestSetup.php because Setup.php will override it @@ -530,7 +531,7 @@ class ApiMainTest extends ApiTestCase { } public static function provideCheckConditionalRequestHeaders() { - global $wgSquidMaxage; + global $wgCdnMaxAge; $now = time(); return [ @@ -613,15 +614,15 @@ class ApiMainTest extends ApiTestCase { [ [ 'If-Modified-Since' => 'a potato' ], [ 'last-modified' => wfTimestamp( TS_MW, $now - 1 ) ], 200 ], - // Anything before $wgSquidMaxage seconds ago should be considered + // Anything before $wgCdnMaxAge seconds ago should be considered // expired. 'If-Modified-Since with CDN post-expiry' => - [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now - $wgSquidMaxage * 2 ) ], - [ 'last-modified' => wfTimestamp( TS_MW, $now - $wgSquidMaxage * 3 ) ], + [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now - $wgCdnMaxAge * 2 ) ], + [ 'last-modified' => wfTimestamp( TS_MW, $now - $wgCdnMaxAge * 3 ) ], 200, [ 'cdn' => true ] ], 'If-Modified-Since with CDN pre-expiry' => - [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now - $wgSquidMaxage / 2 ) ], - [ 'last-modified' => wfTimestamp( TS_MW, $now - $wgSquidMaxage * 3 ) ], + [ [ 'If-Modified-Since' => wfTimestamp( TS_RFC2822, $now - $wgCdnMaxAge / 2 ) ], + [ 'last-modified' => wfTimestamp( TS_MW, $now - $wgCdnMaxAge * 3 ) ], 304, [ 'cdn' => true ] ], ]; } @@ -1010,9 +1011,14 @@ class ApiMainTest extends ApiTestCase { MWExceptionHandler::getRedactedTraceAsString( $dbex ) )->inLanguage( 'en' )->useDatabase( false )->text(); - Wikimedia\suppressWarnings(); - $usageEx = new UsageException( 'Usage exception!', 'ue', 0, [ 'foo' => 'bar' ] ); - Wikimedia\restoreWarnings(); + // The specific exception doesn't matter, as long as it's namespaced. + $nsex = new MediaWiki\ShellDisabledError(); + $nstrace = wfMessage( 'api-exception-trace', + get_class( $nsex ), + $nsex->getFile(), + $nsex->getLine(), + MWExceptionHandler::getRedactedTraceAsString( $nsex ) + )->inLanguage( 'en' )->useDatabase( false )->text(); $apiEx1 = new ApiUsageException( null, StatusValue::newFatal( new ApiRawMessage( 'An error', 'sv-error1' ) ) ); @@ -1021,6 +1027,13 @@ class ApiMainTest extends ApiTestCase { $apiEx1->getStatusValue()->warning( new ApiRawMessage( 'Another warning', 'sv-warn2' ) ); $apiEx1->getStatusValue()->fatal( new ApiRawMessage( 'Another error', 'sv-error2' ) ); + $badMsg = $this->getMockBuilder( ApiRawMessage::class ) + ->setConstructorArgs( [ 'An error', 'ignored' ] ) + ->setMethods( [ 'getApiCode' ] ) + ->getMock(); + $badMsg->method( 'getApiCode' )->willReturn( "bad\nvalue" ); + $apiEx2 = new ApiUsageException( null, StatusValue::newFatal( $badMsg ) ); + return [ [ $ex, @@ -1034,6 +1047,9 @@ class ApiMainTest extends ApiTestCase { [ 'code' => 'internal_api_error_InvalidArgumentException', 'text' => "[$reqId] Exception caught: Random exception", + 'data' => [ + 'errorclass' => InvalidArgumentException::class, + ], ] ], 'trace' => $trace, @@ -1053,6 +1069,9 @@ class ApiMainTest extends ApiTestCase { 'code' => 'internal_api_error_DBQueryError', 'text' => "[$reqId] Exception caught: A database query error has occurred. " . "This may indicate a bug in the software.", + 'data' => [ + 'errorclass' => DBQueryError::class, + ], ] ], 'trace' => $dbtrace, @@ -1060,19 +1079,23 @@ class ApiMainTest extends ApiTestCase { ] ], [ - $usageEx, - [ 'existing-error', 'ue' ], + $nsex, + [ 'existing-error', 'internal_api_error_MediaWiki\ShellDisabledError' ], [ 'warnings' => [ [ 'code' => 'existing-warning', 'text' => 'existing warning', 'module' => 'main' ], ], 'errors' => [ [ 'code' => 'existing-error', 'text' => 'existing error', 'module' => 'main' ], - [ 'code' => 'ue', 'text' => "Usage exception!", 'data' => [ 'foo' => 'bar' ] ] + [ + 'code' => 'internal_api_error_MediaWiki\ShellDisabledError', + 'text' => "[$reqId] Exception caught: " . $nsex->getMessage(), + 'data' => [ + 'errorclass' => MediaWiki\ShellDisabledError::class, + ], + ] ], - '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.", + 'trace' => $nstrace, 'servedby' => wfHostname(), ] ], @@ -1096,6 +1119,23 @@ class ApiMainTest extends ApiTestCase { 'servedby' => wfHostname(), ] ], + [ + $apiEx2, + [ 'existing-error', '' ], + [ + 'warnings' => [ + [ 'code' => 'existing-warning', 'text' => 'existing warning', 'module' => 'main' ], + ], + 'errors' => [ + [ 'code' => 'existing-error', 'text' => 'existing error', 'module' => 'main' ], + [ 'code' => "bad\nvalue", 'text' => 'An error' ], + ], + '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(), + ] + ] ]; }