Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / specialpage / AbstractChangesListSpecialPageTestCase.php
blobc8ca68c1021a66990077642c67ae41d3f662a2c8
1 <?php
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;
14 /**
15 * Abstract base class for shared logic when testing ChangesListSpecialPage
16 * and subclasses
18 * @group Database
20 abstract class AbstractChangesListSpecialPageTestCase extends MediaWikiIntegrationTestCase {
21 // Must be initialized by subclass
22 /**
23 * @var ChangesListSpecialPage
25 protected $changesListSpecialPage;
27 protected function setUp(): void {
28 parent::setUp();
29 $this->overrideConfigValues( [
30 MainConfigNames::RCWatchCategoryMembership => true,
31 MainConfigNames::UseRCPatrol => true,
32 ] );
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();
45 /**
46 * @return ChangesListSpecialPage
48 abstract protected function getPageAccessWrapper();
50 abstract public function provideParseParameters();
52 /**
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.
59 $opts->add(
60 $key,
61 null,
62 FormOptions::guessType( $expected )
66 $this->changesListSpecialPage->parseParameters(
67 $params,
68 $opts
71 $this->assertArrayEquals(
72 $expected,
73 $opts->getAllValues(),
74 /** ordered= */ false,
75 /** named= */ true
79 /**
80 * @dataProvider validateOptionsProvider
82 public function testValidateOptions(
83 $optionsToSet,
84 $expectedRedirect,
85 $expectedRedirectOptions,
86 $rcfilters
87 ) {
88 $redirectQuery = [];
89 $redirected = false;
90 $output = $this->getMockBuilder( OutputPage::class )
91 ->disableProxyingToOriginalMethods()
92 ->disableOriginalConstructor()
93 ->getMock();
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 );
98 $redirected = true;
102 // Disable this hook or it could break changeType
103 // depending on which other extensions are running.
104 $this->setTemporaryHook(
105 'ChangesListSpecialPageStructuredFilters',
106 HookContainer::NOOP
109 // Give users patrol permissions so we can test that.
110 $user = $this->getTestSysop()->getUser();
111 $this->getServiceContainer()->getUserOptionsManager()->setOption(
112 $user,
113 'rcenhancedfilters-disable',
114 $rcfilters ? 0 : 1
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,
141 $redirectQuery,
142 /* $ordered= */ false,
143 /* $named= */ true,
144 'redirection query'
149 abstract public function validateOptionsProvider();