| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Block\BlockActionInfo; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class BlockActionInfoTest extends MediaWikiUnitTestCase { |
| 10 |
private BlockActionInfo $blockActionInfo; |
| 11 |
|
| 12 |
protected function setUp(): void { |
| 13 |
parent::setUp(); |
| 14 |
$this->blockActionInfo = new BlockActionInfo( |
| 15 |
$this->createHookContainer( [ |
| 16 |
'GetAllBlockActions' => static function ( array &$actions ) { |
| 17 |
$actions[ 'test' ] = 100; |
| 18 |
}, |
| 19 |
] ) |
| 20 |
); |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public function testAddBlockAction() { |
| 27 |
|
| 28 |
$blockActions = $this->blockActionInfo->getAllBlockActions(); |
| 29 |
|
| 30 |
|
| 31 |
$this->assertArrayHasKey( 'test', $blockActions, 'Action added via hook' ); |
| 32 |
$this->assertSame( 100, $blockActions['test'], 'Id of action added via hook' ); |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function testIdAndAction( $action, $id ) { |
| 43 |
if ( $id !== false ) { |
| 44 |
$this->assertSame( $action, $this->blockActionInfo->getActionFromId( $id ) ); |
| 45 |
} |
| 46 |
if ( $action !== false ) { |
| 47 |
$this->assertSame( $id, $this->blockActionInfo->getIdFromAction( $action ) ); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
public static function provideIdAndAction() { |
| 52 |
return [ |
| 53 |
'Valid core action' => [ 'upload', 1 ], |
| 54 |
'Valid hook action' => [ 'test', 100 ], |
| 55 |
'Invalid action name' => [ 'invalid', false ], |
| 56 |
'Invalid action id' => [ false, 200 ], |
| 57 |
]; |
| 58 |
} |
| 59 |
|
| 60 |
} |