| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Rest\BasicAccess; |
| 4 |
|
| 5 |
use MediaWiki\Rest\BasicAccess\BasicAuthorizerInterface; |
| 6 |
use MediaWiki\Rest\BasicAccess\CompoundAuthorizer; |
| 7 |
use MediaWiki\Rest\BasicAccess\StaticBasicAuthorizer; |
| 8 |
use MediaWiki\Rest\Handler; |
| 9 |
use MediaWiki\Rest\RequestInterface; |
| 10 |
use MediaWikiUnitTestCase; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class CompoundAuthorizerTest extends MediaWikiUnitTestCase { |
| 16 |
public static function provideAuthorize() { |
| 17 |
yield 'No authorizers' => [ |
| 18 |
[], null, null |
| 19 |
]; |
| 20 |
yield 'All success' => [ |
| 21 |
[ new StaticBasicAuthorizer( null ), new StaticBasicAuthorizer( null ) ], |
| 22 |
null, null |
| 23 |
]; |
| 24 |
yield 'First failed returned' => [ |
| 25 |
[ new StaticBasicAuthorizer( 'first' ), new StaticBasicAuthorizer( 'second' ) ], |
| 26 |
null, 'first' |
| 27 |
]; |
| 28 |
yield 'Added failed' => [ |
| 29 |
[], new StaticBasicAuthorizer( 'added' ), 'added' |
| 30 |
]; |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public function testAuthorize( |
| 40 |
array $authorizers, |
| 41 |
?BasicAuthorizerInterface $addedAuthorizer, |
| 42 |
?string $result |
| 43 |
) { |
| 44 |
$authorizer = new CompoundAuthorizer( $authorizers ); |
| 45 |
if ( $addedAuthorizer ) { |
| 46 |
$authorizer->addAuthorizer( $addedAuthorizer ); |
| 47 |
} |
| 48 |
$this->assertSame( $result, $authorizer->authorize( |
| 49 |
$this->createNoOpMock( RequestInterface::class ), |
| 50 |
$this->createNoOpMock( Handler::class ) |
| 51 |
) ); |
| 52 |
} |
| 53 |
} |