4 * Abstract base class for shared logic when testing ChangesListSpecialPage
9 abstract class AbstractChangesListSpecialPageTestCase
extends MediaWikiTestCase
{
10 // Must be initialized by subclass
12 * @var ChangesListSpecialPage
14 protected $changesListSpecialPage;
16 protected $oldPatrollersGroup;
18 protected function setUp() {
19 global $wgGroupPermissions;
22 $this->setMwGlobals( 'wgRCWatchCategoryMembership', true );
24 if ( isset( $wgGroupPermissions['patrollers'] ) ) {
25 $this->oldPatrollersGroup
= $wgGroupPermissions['patrollers'];
28 $wgGroupPermissions['patrollers'] = [
33 $this->setTemporaryHook(
34 'ChangesListSpecialPageFilters',
38 # setup the ChangesListSpecialPage (or subclass) object
39 $this->changesListSpecialPage
= $this->getPage();
40 $context = $this->changesListSpecialPage
->getContext();
41 $context = new DerivativeContext( $context );
42 $context->setUser( $this->getTestUser( [ 'patrollers' ] )->getUser() );
43 $this->changesListSpecialPage
->setContext( $context );
44 $this->changesListSpecialPage
->registerFilters();
47 protected function tearDown() {
48 global $wgGroupPermissions;
52 if ( $this->oldPatrollersGroup
!== null ) {
53 $wgGroupPermissions['patrollers'] = $this->oldPatrollersGroup
;
58 * @dataProvider provideParseParameters
60 public function testParseParameters( $params, $expected ) {
61 $opts = new FormOptions();
62 foreach ( $expected as $key => $value ) {
63 // Register it as null so sets aren't rejected.
67 FormOptions
::guessType( $expected )
71 $this->changesListSpecialPage
->parseParameters(
76 $this->assertArrayEquals(
78 $opts->getAllValues(),
79 /** ordered= */ false,
85 * @dataProvider validateOptionsProvider
87 public function testValidateOptions( $optionsToSet, $expectedRedirect, $expectedRedirectOptions ) {
90 $output = $this->getMockBuilder( OutputPage
::class )
91 ->disableProxyingToOriginalMethods()
92 ->disableOriginalConstructor()
94 $output->method( 'redirect' )->willReturnCallback(
95 function ( $url ) use ( &$redirectQuery, &$redirected ) {
96 $urlParts = wfParseUrl( $url );
97 $query = isset( $urlParts[ 'query' ] ) ?
$urlParts[ 'query' ] : '';
98 parse_str( $query, $redirectQuery );
102 $ctx = new RequestContext();
104 // Give users patrol permissions so we can test that.
105 $user = $this->getTestSysop()->getUser();
106 $ctx->setUser( $user );
108 // Disable this hook or it could break changeType
109 // depending on which other extensions are running.
110 $this->setTemporaryHook(
111 'ChangesListSpecialPageStructuredFilters',
115 $ctx->setOutput( $output );
116 $clsp = $this->changesListSpecialPage
;
117 $clsp->setContext( $ctx );
118 $opts = $clsp->getDefaultOptions();
120 foreach ( $optionsToSet as $option => $value ) {
121 $opts->setValue( $option, $value );
124 $clsp->validateOptions( $opts );
126 $this->assertEquals( $expectedRedirect, $redirected, 'redirection' );
128 if ( $expectedRedirect ) {
129 if ( count( $expectedRedirectOptions ) > 0 ) {
130 $expectedRedirectOptions +
= [
131 'title' => $clsp->getPageTitle()->getPrefixedText(),
135 $this->assertArrayEquals(
136 $expectedRedirectOptions,
138 /* $ordered= */ false,