3 namespace MediaWiki\Tests\SpecialPage
;
5 use MediaWiki\Context\DerivativeContext
;
6 use MediaWiki\Context\RequestContext
;
7 use MediaWiki\HookContainer\HookContainer
;
8 use MediaWiki\Html\FormOptions
;
9 use MediaWiki\MainConfigNames
;
10 use MediaWiki\Output\OutputPage
;
11 use MediaWiki\SpecialPage\ChangesListSpecialPage
;
12 use MediaWikiIntegrationTestCase
;
15 * Abstract base class for shared logic when testing ChangesListSpecialPage
20 abstract class AbstractChangesListSpecialPageTestCase
extends MediaWikiIntegrationTestCase
{
21 // Must be initialized by subclass
23 * @var ChangesListSpecialPage
25 protected $changesListSpecialPage;
27 protected function setUp(): void
{
29 $this->overrideConfigValues( [
30 MainConfigNames
::RCWatchCategoryMembership
=> true,
31 MainConfigNames
::UseRCPatrol
=> true,
34 $this->setGroupPermissions( 'patrollers', 'patrol', true );
36 # setup the ChangesListSpecialPage (or subclass) object
37 $this->changesListSpecialPage
= $this->getPageAccessWrapper();
38 $context = $this->changesListSpecialPage
->getContext();
39 $context = new DerivativeContext( $context );
40 $context->setUser( $this->getTestUser( [ 'patrollers' ] )->getUser() );
41 $this->changesListSpecialPage
->setContext( $context );
42 $this->changesListSpecialPage
->registerFilters();
46 * @return ChangesListSpecialPage
48 abstract protected function getPageAccessWrapper();
50 abstract public function provideParseParameters();
53 * @dataProvider provideParseParameters
55 public function testParseParameters( $params, $expected ) {
56 $opts = new FormOptions();
57 foreach ( $expected as $key => $value ) {
58 // Register it as null so sets aren't rejected.
62 FormOptions
::guessType( $expected )
66 $this->changesListSpecialPage
->parseParameters(
71 $this->assertArrayEquals(
73 $opts->getAllValues(),
74 /** ordered= */ false,
80 * @dataProvider validateOptionsProvider
82 public function testValidateOptions(
85 $expectedRedirectOptions,
90 $output = $this->getMockBuilder( OutputPage
::class )
91 ->disableProxyingToOriginalMethods()
92 ->disableOriginalConstructor()
94 $output->method( 'redirect' )->willReturnCallback(
95 static function ( $url ) use ( &$redirectQuery, &$redirected ) {
96 $query = parse_url( $url, PHP_URL_QUERY
) ??
'';
97 parse_str( $query, $redirectQuery );
102 // Disable this hook or it could break changeType
103 // depending on which other extensions are running.
104 $this->setTemporaryHook(
105 'ChangesListSpecialPageStructuredFilters',
109 // Give users patrol permissions so we can test that.
110 $user = $this->getTestSysop()->getUser();
111 $this->getServiceContainer()->getUserOptionsManager()->setOption(
113 'rcenhancedfilters-disable',
116 $ctx = new RequestContext();
117 $ctx->setUser( $user );
119 $ctx->setOutput( $output );
120 $clsp = $this->changesListSpecialPage
;
121 $clsp->setContext( $ctx );
122 $opts = $clsp->getDefaultOptions();
124 foreach ( $optionsToSet as $option => $value ) {
125 $opts->setValue( $option, $value );
128 $clsp->validateOptions( $opts );
130 $this->assertEquals( $expectedRedirect, $redirected, 'redirection - ' . print_r( $optionsToSet, true ) );
132 if ( $expectedRedirect ) {
133 if ( count( $expectedRedirectOptions ) > 0 ) {
134 $expectedRedirectOptions +
= [
135 'title' => $clsp->getPageTitle()->getPrefixedText(),
139 $this->assertArrayEquals(
140 $expectedRedirectOptions,
142 /* $ordered= */ false,
149 abstract public function validateOptionsProvider();