diff options
author | daniel <dkinzler@wikimedia.org> | 2022-12-04 18:51:37 +0100 |
---|---|---|
committer | daniel <dkinzler@wikimedia.org> | 2024-06-13 21:40:36 +0200 |
commit | c01b7c7b4b7f1b6f75dd94915220081a6e29981e (patch) | |
tree | 87799e3dbff4839fe0a604ca5f7e3906e2842551 /tests/phpunit/structure | |
parent | 4e05de07d92b619f719fbb36915465aa0e86795c (diff) | |
download | mediawikicore-c01b7c7b4b7f1b6f75dd94915220081a6e29981e.tar.gz mediawikicore-c01b7c7b4b7f1b6f75dd94915220081a6e29981e.zip |
Add Special:RestSandbox for exploring REST API
Special:RestSandbox presents a Swagger-UI interface for exploring REST APIs. The available APIs can be configured using RestSandboxSpecs.
For now, the default is to support no APIs, so the feature is disabled in production. In the future, it would make sense to expose the wiki's own REST API per default. The corresponding entry in $wgRestSandboxSpecs in LocalSettings.php would look like this:
'mw' => [
'url' => $wgScriptPath . '/rest.php/',
'name' => 'MediaWiki REST API',
]
Note that the spec URL may still change.
To also explore the endpoints exposed through RESTbase, we might add:
'wmf-restbase' => [
'url' => $wgServer . '/api/rest_v1/',
'name' => 'Wikimedia RESTbase API',
]
Similarly, we could expose a spec for endpoints on api.wikimedia.org, which could then be explored using the new special page.
NOTE: This adds a dependency on the swagger-ui npm library. See T325558 for the security review.
Bug: T362006
Change-Id: I1dd5ed82680a28f9c15136b446a2de0398525061
Diffstat (limited to 'tests/phpunit/structure')
-rw-r--r-- | tests/phpunit/structure/SpecialPageFatalTest.php | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/tests/phpunit/structure/SpecialPageFatalTest.php b/tests/phpunit/structure/SpecialPageFatalTest.php index 7e953d0232a2..b7778ba34e45 100644 --- a/tests/phpunit/structure/SpecialPageFatalTest.php +++ b/tests/phpunit/structure/SpecialPageFatalTest.php @@ -25,34 +25,42 @@ class SpecialPageFatalTest extends MediaWikiIntegrationTestCase { $this->filterDeprecated( '//' ); } - public function testSpecialPageDoesNotFatal() { + public static function provideSpecialPageDoesNotFatal() { $spf = MediaWikiServices::getInstance()->getSpecialPageFactory(); foreach ( $spf->getNames() as $name ) { + yield $name => [ $name ]; + } + } - $page = $spf->getPage( $name ); - if ( !$page ) { - $this->markTestSkipped( "Could not create special page $name" ); - } - - $executor = new SpecialPageExecutor(); - $authority = new UltimateAuthority( new UserIdentityValue( 42, 'SpecialPageTester' ) ); - - try { - $executor->executeSpecialPage( $page, '', null, 'qqx', $authority ); - } catch ( \PHPUnit\Framework\Error\Error $error ) { - // Let phpunit settings working: - // - convertDeprecationsToExceptions="true" - // - convertErrorsToExceptions="true" - // - convertNoticesToExceptions="true" - // - convertWarningsToExceptions="true" - throw $error; - } catch ( Exception $e ) { - // Other exceptions are allowed - } - - // If the page fataled phpunit will have already died - $this->addToAssertionCount( 1 ); + /** + * @dataProvider provideSpecialPageDoesNotFatal + */ + public function testSpecialPageDoesNotFatal( string $name ) { + $spf = $this->getServiceContainer()->getSpecialPageFactory(); + + $page = $spf->getPage( $name ); + if ( !$page ) { + $this->markTestSkipped( "Could not create special page $name" ); } + + $executor = new SpecialPageExecutor(); + $authority = new UltimateAuthority( new UserIdentityValue( 42, 'SpecialPageTester' ) ); + + try { + $executor->executeSpecialPage( $page, '', null, 'qqx', $authority ); + } catch ( \PHPUnit\Framework\Error\Error $error ) { + // Let phpunit settings working: + // - convertDeprecationsToExceptions="true" + // - convertErrorsToExceptions="true" + // - convertNoticesToExceptions="true" + // - convertWarningsToExceptions="true" + throw $error; + } catch ( Exception $e ) { + // Other exceptions are allowed + } + + // If the page fataled phpunit will have already died + $this->addToAssertionCount( 1 ); } } |