| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Nuke\Test\Integration; |
| 4 |
|
| 5 |
use MediaWiki\Extension\Nuke\Hooks; |
| 6 |
use MediaWiki\Permissions\UltimateAuthority; |
| 7 |
use MediaWiki\Specials\SpecialContributions; |
| 8 |
use MediaWiki\Title\Title; |
| 9 |
use MediaWikiIntegrationTestCase; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class HooksTest extends MediaWikiIntegrationTestCase { |
| 16 |
|
| 17 |
public function testNormal() { |
| 18 |
$sysop = $this->getTestSysop()->getUser(); |
| 19 |
$performer = new UltimateAuthority( $sysop ); |
| 20 |
|
| 21 |
$specialPage = $this->newSpecialContribsPage(); |
| 22 |
$context = $specialPage->getContext(); |
| 23 |
$context->setAuthority( $performer ); |
| 24 |
|
| 25 |
$this->setUserLang( "qqx" ); |
| 26 |
$tools = []; |
| 27 |
( new Hooks() )->onContributionsToolLinks( |
| 28 |
$sysop->getId(), |
| 29 |
$sysop->getUserPage(), |
| 30 |
$tools, |
| 31 |
$specialPage |
| 32 |
); |
| 33 |
|
| 34 |
$this->assertArrayHasKey( 'nuke', $tools ); |
| 35 |
} |
| 36 |
|
| 37 |
public function testNoPermission() { |
| 38 |
$this->overrideConfigValues( [ |
| 39 |
"GroupPermissions" => [ |
| 40 |
"testgroup" => [ |
| 41 |
"nuke" => false, |
| 42 |
"delete" => true |
| 43 |
] |
| 44 |
] |
| 45 |
] ); |
| 46 |
|
| 47 |
$testUser = $this->getTestUser( [ "testgroup" ] ); |
| 48 |
|
| 49 |
$specialPage = $this->newSpecialContribsPage(); |
| 50 |
$context = $specialPage->getContext(); |
| 51 |
$context->setAuthority( $testUser->getAuthority() ); |
| 52 |
|
| 53 |
$this->setUserLang( "qqx" ); |
| 54 |
$tools = []; |
| 55 |
( new Hooks() )->onContributionsToolLinks( |
| 56 |
$testUser->getUser()->getId(), |
| 57 |
$testUser->getUser()->getUserPage(), |
| 58 |
$tools, |
| 59 |
$specialPage |
| 60 |
); |
| 61 |
|
| 62 |
$this->assertArrayNotHasKey( 'nuke', $tools ); |
| 63 |
} |
| 64 |
|
| 65 |
public function testIPRange() { |
| 66 |
$sysop = $this->getTestSysop()->getUser(); |
| 67 |
$performer = new UltimateAuthority( $sysop ); |
| 68 |
|
| 69 |
$specialPage = $this->newSpecialContribsPage(); |
| 70 |
$context = $specialPage->getContext(); |
| 71 |
$context->setAuthority( $performer ); |
| 72 |
|
| 73 |
$this->setUserLang( "qqx" ); |
| 74 |
$tools = []; |
| 75 |
( new Hooks() )->onContributionsToolLinks( |
| 76 |
0, |
| 77 |
Title::makeTitle( NS_USER, '127.0.0.1/24' ), |
| 78 |
$tools, |
| 79 |
$specialPage |
| 80 |
); |
| 81 |
|
| 82 |
$this->assertArrayNotHasKey( 'nuke', $tools ); |
| 83 |
} |
| 84 |
|
| 85 |
private function newSpecialContribsPage(): SpecialContributions { |
| 86 |
$services = $this->getServiceContainer(); |
| 87 |
|
| 88 |
return new SpecialContributions( |
| 89 |
$services->getLinkBatchFactory(), |
| 90 |
$services->getPermissionManager(), |
| 91 |
$services->getDBLoadBalancerFactory(), |
| 92 |
$services->getRevisionStore(), |
| 93 |
$services->getNamespaceInfo(), |
| 94 |
$services->getUserNameUtils(), |
| 95 |
$services->getUserNamePrefixSearch(), |
| 96 |
$services->getUserOptionsLookup(), |
| 97 |
$services->getCommentFormatter(), |
| 98 |
$services->getUserFactory(), |
| 99 |
$services->getUserIdentityLookup(), |
| 100 |
$services->getDatabaseBlockStore(), |
| 101 |
$services->getTempUserConfig() |
| 102 |
); |
| 103 |
} |
| 104 |
|
| 105 |
} |