Debian Codegraph @

tests/phpunit/unit/includes/block/BlockActionInfoTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Block\BlockActionInfo;
4
5 /**
6 * @group Blocking
7 * @coversDefaultClass \MediaWiki\Block\BlockActionInfo
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 * @covers ::getAllBlockActions
25 */
26 public function testAddBlockAction() {
27 // 'test' action in added by hook with id 100
28 $blockActions = $this->blockActionInfo->getAllBlockActions();
29
30 // Confirm new action is added
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 * @dataProvider provideIdAndAction
37 * @param string|false $action False if the id is invalid
38 * @param int|false $id False if the action is invalid
39 * @covers ::getIdFromAction
40 * @covers ::getActionFromId
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 }