2020-04-17 14:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
2022-08-14 13:47:11 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2021-01-08 01:14:21 +00:00
|
|
|
use MediaWiki\Permissions\UltimateAuthority;
|
2022-10-28 10:04:25 +00:00
|
|
|
use MediaWiki\Request\FauxRequest;
|
2023-03-17 15:04:04 +00:00
|
|
|
use MediaWiki\Specials\SpecialContributions;
|
2021-01-08 01:14:21 +00:00
|
|
|
|
2020-04-17 14:46:31 +00:00
|
|
|
/**
|
|
|
|
|
* @author Ammarpad
|
|
|
|
|
* @group Database
|
2023-05-27 09:43:12 +00:00
|
|
|
* @covers MediaWiki\Specials\SpecialContributions
|
2020-04-17 14:46:31 +00:00
|
|
|
*/
|
|
|
|
|
class SpecialContributionsTest extends SpecialPageTestBase {
|
2021-11-02 01:51:10 +00:00
|
|
|
private $pageName = __CLASS__ . 'BlaBlaTest';
|
2020-04-17 14:46:31 +00:00
|
|
|
private $admin;
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
2022-08-14 13:47:11 +00:00
|
|
|
$this->overrideConfigValue(
|
|
|
|
|
MainConfigNames::RangeContributionsCIDRLimit,
|
|
|
|
|
[
|
2020-04-17 14:46:31 +00:00
|
|
|
'IPv4' => 16,
|
|
|
|
|
'IPv6' => 32,
|
|
|
|
|
]
|
2022-08-14 13:47:11 +00:00
|
|
|
);
|
2020-04-17 14:46:31 +00:00
|
|
|
$this->setTemporaryHook(
|
|
|
|
|
'SpecialContributionsBeforeMainOutput',
|
2021-02-07 13:10:36 +00:00
|
|
|
static function () {
|
2020-04-17 14:46:31 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
);
|
2021-01-08 01:14:21 +00:00
|
|
|
$this->admin = new UltimateAuthority( $this->getTestSysop()->getUser() );
|
2021-11-02 01:51:10 +00:00
|
|
|
$this->assertTrue(
|
|
|
|
|
$this->editPage(
|
|
|
|
|
$this->pageName, 'Test Content', 'test', NS_MAIN, $this->admin
|
|
|
|
|
)->isOK(),
|
2021-11-21 16:23:11 +00:00
|
|
|
'Admin contributed'
|
2021-11-02 01:51:10 +00:00
|
|
|
);
|
2020-04-17 14:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-05-27 09:43:12 +00:00
|
|
|
* @covers MediaWiki\Specials\SpecialContributions::execute
|
2020-04-17 14:46:31 +00:00
|
|
|
* @dataProvider provideTestExecuteRange
|
|
|
|
|
*/
|
|
|
|
|
public function testExecuteRange( $username, $shouldShowLinks ) {
|
2022-10-21 04:32:38 +00:00
|
|
|
[ $html ] = $this->executeSpecialPage( $username, null, 'qqx', $this->admin, true );
|
2020-04-17 14:46:31 +00:00
|
|
|
|
|
|
|
|
if ( $shouldShowLinks ) {
|
|
|
|
|
$this->assertStringContainsString( 'blocklink', $html );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertStringNotContainsString( 'blocklink', $html );
|
|
|
|
|
$this->assertStringContainsString( 'sp-contributions-outofrange', $html );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-05-27 09:43:12 +00:00
|
|
|
* @covers MediaWiki\Specials\SpecialContributions::execute
|
2020-04-17 14:46:31 +00:00
|
|
|
* @dataProvider provideTestExecuteNonRange
|
|
|
|
|
*/
|
|
|
|
|
public function testExecuteNonRange( $username, $shouldShowLinks ) {
|
2022-10-21 04:32:38 +00:00
|
|
|
[ $html ] = $this->executeSpecialPage( $username, null, 'qqx', $this->admin, true );
|
2020-04-17 14:46:31 +00:00
|
|
|
|
|
|
|
|
if ( $shouldShowLinks ) {
|
|
|
|
|
$this->assertStringContainsString( 'blocklink', $html );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertStringNotContainsString( 'blocklink', $html );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideTestExecuteRange() {
|
2020-04-17 14:46:31 +00:00
|
|
|
yield 'Queryable IPv4 range should have blocklink for admin'
|
|
|
|
|
=> [ '24.237.208.166/30', true ];
|
|
|
|
|
yield 'Queryable IPv6 range should have blocklink for admin'
|
|
|
|
|
=> [ '2001:DB8:0:0:0:0:0:01/43', true ];
|
|
|
|
|
yield 'Unqueryable IPv4 range should not have blocklink for admin'
|
|
|
|
|
=> [ '212.35.31.121/14', false ];
|
|
|
|
|
yield 'Unqueryable IPv6 range should not have blocklink for admin'
|
|
|
|
|
=> [ '2000::/24', false ];
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideTestExecuteNonRange() {
|
2020-04-17 14:46:31 +00:00
|
|
|
yield 'Valid IPv4 should have blocklink for admin' => [ '124.24.52.13', true ];
|
|
|
|
|
yield 'Valid IPv6 should have blocklink for admin' => [ '2001:db8::', true ];
|
|
|
|
|
yield 'Local user should have blocklink for admin' => [ 'UTSysop', true ];
|
|
|
|
|
yield 'Invalid IP should not have blocklink for admin' => [ '24.237.222208.166', false ];
|
|
|
|
|
yield 'External user should not have blocklink for admin' => [ 'imported>UTSysop', false ];
|
|
|
|
|
yield 'Nonexistent user should not have blocklink for admin' => [ __CLASS__, false ];
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-23 11:36:19 +00:00
|
|
|
public static function provideYearMonthParams() {
|
2021-11-02 01:51:10 +00:00
|
|
|
yield 'Current year/month' => [
|
|
|
|
|
'year' => date( 'Y' ),
|
|
|
|
|
'month' => date( 'm' ),
|
|
|
|
|
'expect' => true,
|
|
|
|
|
];
|
|
|
|
|
yield 'Old year/moth' => [
|
|
|
|
|
'year' => '2007',
|
|
|
|
|
'month' => '01',
|
|
|
|
|
'expect' => false,
|
|
|
|
|
];
|
|
|
|
|
yield 'Garbage' => [
|
|
|
|
|
'year' => '123garbage123',
|
|
|
|
|
'month' => date( 'm' ),
|
|
|
|
|
'expect' => true,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-05-27 09:43:12 +00:00
|
|
|
* @covers MediaWiki\Specials\SpecialContributions::execute
|
2021-11-02 01:51:10 +00:00
|
|
|
* @dataProvider provideYearMonthParams
|
|
|
|
|
*/
|
|
|
|
|
public function testYearMonthParams( string $year, string $month, bool $expect ) {
|
|
|
|
|
[ $html ] = $this->executeSpecialPage(
|
|
|
|
|
$this->admin->getUser()->getName(),
|
|
|
|
|
new FauxRequest( [
|
|
|
|
|
'year' => $year,
|
|
|
|
|
'month' => $month,
|
|
|
|
|
] ) );
|
|
|
|
|
if ( $expect ) {
|
|
|
|
|
$this->assertStringContainsString( $this->pageName, $html );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertStringNotContainsString( $this->pageName, $html );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 14:46:31 +00:00
|
|
|
protected function newSpecialPage(): SpecialContributions {
|
2022-01-12 20:13:39 +00:00
|
|
|
$services = $this->getServiceContainer();
|
2020-04-17 14:46:31 +00:00
|
|
|
|
|
|
|
|
return new SpecialContributions(
|
|
|
|
|
$services->getLinkBatchFactory(),
|
|
|
|
|
$services->getPermissionManager(),
|
2023-04-19 15:35:34 +00:00
|
|
|
$services->getDBLoadBalancerFactory(),
|
2020-04-17 14:46:31 +00:00
|
|
|
$services->getRevisionStore(),
|
|
|
|
|
$services->getNamespaceInfo(),
|
|
|
|
|
$services->getUserNameUtils(),
|
|
|
|
|
$services->getUserNamePrefixSearch(),
|
|
|
|
|
$services->getUserOptionsLookup()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|