wiki.techinc.nl/tests/phpunit/includes/api/ApiTestContext.php
Petr Pchelko edb3a9a692 Allow passing mock Authority in API integration tests
This is a demo, a lot of tests could be rewritten as a followup
to pass proper Authority when executing tests instead of writing
globals. Much cleaner imho.

An improvement idea is to allow overriding 'default permissions'
when creating a mock Authority.

Change-Id: I38570024e0d5a67a8e1c52f7456c458090ec2b6e
2021-06-07 11:50:42 -07:00

23 lines
599 B
PHP

<?php
use MediaWiki\Permissions\Authority;
class ApiTestContext extends RequestContext {
/**
* Returns a DerivativeContext with the request variables in place
*
* @param WebRequest $request WebRequest request object including parameters and session
* @param Authority|null $performer
* @return DerivativeContext
*/
public function newTestContext( WebRequest $request, Authority $performer = null ) {
$context = new DerivativeContext( $this );
$context->setRequest( $request );
if ( $performer !== null ) {
$context->setAuthority( $performer );
}
return $context;
}
}