Some combinations of RC filters should never appear together because they guarantee to return no data and cannot be visually represented in the new RC filters UI (ERI project). Examples include: * 'hidemyself' and 'hidebyothers' * 'hideminor' and 'hidemajor' * All of the filters in the changeType group (which is extended by extensions) This also handles an old special case, but it now redirects instead of doing it silently: hideanons=1 & hideliu=1 & hidebots=1 -> hideliu=1 & hidebots=1 hideanons=1 & hideliu=1 & hidebots=0 -> hidehumans=1 Bug: T151873 Change-Id: Id08dccd07b262ce61c9d38563f19a0ab181e2341
144 lines
3.5 KiB
PHP
144 lines
3.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Abstract base class for shared logic when testing ChangesListSpecialPage
|
|
* and subclasses
|
|
*
|
|
* @group Database
|
|
*/
|
|
abstract class AbstractChangesListSpecialPageTestCase extends MediaWikiTestCase {
|
|
// Must be initialized by subclass
|
|
/**
|
|
* @var ChangesListSpecialPage
|
|
*/
|
|
protected $changesListSpecialPage;
|
|
|
|
protected $oldPatrollersGroup;
|
|
|
|
protected function setUp() {
|
|
global $wgGroupPermissions;
|
|
|
|
parent::setUp();
|
|
$this->setMwGlobals( 'wgRCWatchCategoryMembership', true );
|
|
|
|
if ( isset( $wgGroupPermissions['patrollers'] ) ) {
|
|
$this->oldPatrollersGroup = $wgGroupPermissions['patrollers'];
|
|
}
|
|
|
|
$wgGroupPermissions['patrollers'] = [
|
|
'patrol' => true,
|
|
];
|
|
|
|
// Deprecated
|
|
$this->setTemporaryHook(
|
|
'ChangesListSpecialPageFilters',
|
|
null
|
|
);
|
|
|
|
# setup the ChangesListSpecialPage (or subclass) object
|
|
$this->changesListSpecialPage = $this->getPage();
|
|
$context = $this->changesListSpecialPage->getContext();
|
|
$context = new DerivativeContext( $context );
|
|
$context->setUser( $this->getTestUser( [ 'patrollers' ] )->getUser() );
|
|
$this->changesListSpecialPage->setContext( $context );
|
|
$this->changesListSpecialPage->registerFilters();
|
|
}
|
|
|
|
protected function tearDown() {
|
|
global $wgGroupPermissions;
|
|
|
|
parent::tearDown();
|
|
|
|
if ( $this->oldPatrollersGroup !== null ) {
|
|
$wgGroupPermissions['patrollers'] = $this->oldPatrollersGroup;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideParseParameters
|
|
*/
|
|
public function testParseParameters( $params, $expected ) {
|
|
$opts = new FormOptions();
|
|
foreach ( $expected as $key => $value ) {
|
|
// Register it as null so sets aren't rejected.
|
|
$opts->add(
|
|
$key,
|
|
null,
|
|
FormOptions::guessType( $expected )
|
|
);
|
|
}
|
|
|
|
$this->changesListSpecialPage->parseParameters(
|
|
$params,
|
|
$opts
|
|
);
|
|
|
|
$this->assertArrayEquals(
|
|
$expected,
|
|
$opts->getAllValues(),
|
|
/** ordered= */ false,
|
|
/** named= */ true
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider validateOptionsProvider
|
|
*/
|
|
public function testValidateOptions( $optionsToSet, $expectedRedirect, $expectedRedirectOptions ) {
|
|
$redirectQuery = [];
|
|
$redirected = false;
|
|
$output = $this->getMockBuilder( OutputPage::class )
|
|
->disableProxyingToOriginalMethods()
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$output->method( 'redirect' )->willReturnCallback(
|
|
function ( $url ) use ( &$redirectQuery, &$redirected ) {
|
|
$urlParts = wfParseUrl( $url );
|
|
$query = isset( $urlParts[ 'query' ] ) ? $urlParts[ 'query' ] : '';
|
|
parse_str( $query, $redirectQuery );
|
|
$redirected = true;
|
|
}
|
|
);
|
|
$ctx = new RequestContext();
|
|
|
|
// Give users patrol permissions so we can test that.
|
|
$user = $this->getTestSysop()->getUser();
|
|
$ctx->setUser( $user );
|
|
|
|
// Disable this hook or it could break changeType
|
|
// depending on which other extensions are running.
|
|
$this->setTemporaryHook(
|
|
'ChangesListSpecialPageStructuredFilters',
|
|
null
|
|
);
|
|
|
|
$ctx->setOutput( $output );
|
|
$clsp = $this->changesListSpecialPage;
|
|
$clsp->setContext( $ctx );
|
|
$opts = $clsp->getDefaultOptions();
|
|
|
|
foreach ( $optionsToSet as $option => $value ) {
|
|
$opts->setValue( $option, $value );
|
|
}
|
|
|
|
$clsp->validateOptions( $opts );
|
|
|
|
$this->assertEquals( $expectedRedirect, $redirected, 'redirection' );
|
|
|
|
if ( $expectedRedirect ) {
|
|
if ( count( $expectedRedirectOptions ) > 0 ) {
|
|
$expectedRedirectOptions += [
|
|
'title' => $clsp->getPageTitle()->getPrefixedText(),
|
|
];
|
|
}
|
|
|
|
$this->assertArrayEquals(
|
|
$expectedRedirectOptions,
|
|
$redirectQuery,
|
|
/* $ordered= */ false,
|
|
/* $named= */ true,
|
|
'redirection query'
|
|
);
|
|
}
|
|
}
|
|
}
|