mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Nuke
synced 2024-11-27 17:50:21 +00:00
Add tests for hook handler
This *should* get Nuke to 100% line coverage now. Also moves SpecialNukeTest to an integration/ subfolder, and makes applicable changes, since there's now two integration tests. Follow-Up: Ic15d4431dc8509ac2732ebce7517522e27d8f5a3 Change-Id: I4355b12647cb1a4cc163467d23166d7fa1aade9e
This commit is contained in:
parent
2794f04b35
commit
a0eb145847
104
tests/phpunit/integration/HooksTest.php
Normal file
104
tests/phpunit/integration/HooksTest.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Nuke\Test\Integration;
|
||||
|
||||
use MediaWiki\Extension\Nuke\Hooks;
|
||||
use MediaWiki\Permissions\UltimateAuthority;
|
||||
use MediaWiki\Specials\SpecialContributions;
|
||||
use MediaWiki\Title\Title;
|
||||
use MediaWikiIntegrationTestCase;
|
||||
|
||||
/**
|
||||
* @group Database
|
||||
* @covers \MediaWiki\Extension\Nuke\Hooks
|
||||
*/
|
||||
class HooksTest extends MediaWikiIntegrationTestCase {
|
||||
|
||||
public function testNormal() {
|
||||
$sysop = $this->getTestSysop()->getUser();
|
||||
$performer = new UltimateAuthority( $sysop );
|
||||
|
||||
$specialPage = $this->newSpecialContribsPage();
|
||||
$context = $specialPage->getContext();
|
||||
$context->setAuthority( $performer );
|
||||
|
||||
$this->setUserLang( "qqx" );
|
||||
$tools = [];
|
||||
( new Hooks() )->onContributionsToolLinks(
|
||||
$sysop->getId(),
|
||||
$sysop->getUserPage(),
|
||||
$tools,
|
||||
$specialPage
|
||||
);
|
||||
|
||||
$this->assertArrayHasKey( 'nuke', $tools );
|
||||
}
|
||||
|
||||
public function testNoPermission() {
|
||||
$this->overrideConfigValues( [
|
||||
"GroupPermissions" => [
|
||||
"testgroup" => [
|
||||
"nuke" => false,
|
||||
"delete" => true
|
||||
]
|
||||
]
|
||||
] );
|
||||
|
||||
$testUser = $this->getTestUser( [ "testgroup" ] );
|
||||
|
||||
$specialPage = $this->newSpecialContribsPage();
|
||||
$context = $specialPage->getContext();
|
||||
$context->setAuthority( $testUser->getAuthority() );
|
||||
|
||||
$this->setUserLang( "qqx" );
|
||||
$tools = [];
|
||||
( new Hooks() )->onContributionsToolLinks(
|
||||
$testUser->getUser()->getId(),
|
||||
$testUser->getUser()->getUserPage(),
|
||||
$tools,
|
||||
$specialPage
|
||||
);
|
||||
|
||||
$this->assertArrayNotHasKey( 'nuke', $tools );
|
||||
}
|
||||
|
||||
public function testIPRange() {
|
||||
$sysop = $this->getTestSysop()->getUser();
|
||||
$performer = new UltimateAuthority( $sysop );
|
||||
|
||||
$specialPage = $this->newSpecialContribsPage();
|
||||
$context = $specialPage->getContext();
|
||||
$context->setAuthority( $performer );
|
||||
|
||||
$this->setUserLang( "qqx" );
|
||||
$tools = [];
|
||||
( new Hooks() )->onContributionsToolLinks(
|
||||
0,
|
||||
Title::makeTitle( NS_USER, '127.0.0.1/24' ),
|
||||
$tools,
|
||||
$specialPage
|
||||
);
|
||||
|
||||
$this->assertArrayNotHasKey( 'nuke', $tools );
|
||||
}
|
||||
|
||||
private function newSpecialContribsPage(): SpecialContributions {
|
||||
$services = $this->getServiceContainer();
|
||||
|
||||
return new SpecialContributions(
|
||||
$services->getLinkBatchFactory(),
|
||||
$services->getPermissionManager(),
|
||||
$services->getDBLoadBalancerFactory(),
|
||||
$services->getRevisionStore(),
|
||||
$services->getNamespaceInfo(),
|
||||
$services->getUserNameUtils(),
|
||||
$services->getUserNamePrefixSearch(),
|
||||
$services->getUserOptionsLookup(),
|
||||
$services->getCommentFormatter(),
|
||||
$services->getUserFactory(),
|
||||
$services->getUserIdentityLookup(),
|
||||
$services->getDatabaseBlockStore()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Nuke\Tests;
|
||||
namespace MediaWiki\Extension\Nuke\Test\Integration;
|
||||
|
||||
use MediaWiki\Extension\Nuke\SpecialNuke;
|
||||
use MediaWiki\Permissions\UltimateAuthority;
|
||||
|
@ -601,7 +601,7 @@ class SpecialNukeTest extends SpecialPageTestBase {
|
|||
}
|
||||
|
||||
private function uploadTestFile() {
|
||||
$exampleFilePath = realpath( __DIR__ . "/../assets/Example.png" );
|
||||
$exampleFilePath = realpath( __DIR__ . "/../../assets/Example.png" );
|
||||
$tempFilePath = $this->getNewTempFile();
|
||||
copy( $exampleFilePath, $tempFilePath );
|
||||
|
||||
|
@ -622,7 +622,7 @@ class SpecialNukeTest extends SpecialPageTestBase {
|
|||
);
|
||||
}
|
||||
|
||||
private function getDeleteLogHtml() {
|
||||
private function getDeleteLogHtml(): string {
|
||||
$services = $this->getServiceContainer();
|
||||
$specialLog = new SpecialLog(
|
||||
$services->getLinkBatchFactory(),
|
Loading…
Reference in a new issue