MediaWiki REL1_31
AbstractChangesListSpecialPageTestCase.php
Go to the documentation of this file.
1<?php
2
10 // Must be initialized by subclass
15
17
18 protected function setUp() {
20
21 parent::setUp();
22 $this->setMwGlobals( [
23 'wgRCWatchCategoryMembership' => true,
24 'wgUseRCPatrol' => true,
25 ] );
26
27 if ( isset( $wgGroupPermissions['patrollers'] ) ) {
28 $this->oldPatrollersGroup = $wgGroupPermissions['patrollers'];
29 }
30
31 $wgGroupPermissions['patrollers'] = [
32 'patrol' => true,
33 ];
34
35 // Deprecated
36 $this->setTemporaryHook(
37 'ChangesListSpecialPageFilters',
38 null
39 );
40
41 # setup the ChangesListSpecialPage (or subclass) object
42 $this->changesListSpecialPage = $this->getPage();
43 $context = $this->changesListSpecialPage->getContext();
45 $context->setUser( $this->getTestUser( [ 'patrollers' ] )->getUser() );
46 $this->changesListSpecialPage->setContext( $context );
47 $this->changesListSpecialPage->registerFilters();
48 }
49
50 abstract protected function getPage();
51
52 protected function tearDown() {
54
55 parent::tearDown();
56
57 if ( $this->oldPatrollersGroup !== null ) {
59 }
60 }
61
62 abstract public function provideParseParameters();
63
67 public function testParseParameters( $params, $expected ) {
68 $opts = new FormOptions();
69 foreach ( $expected as $key => $value ) {
70 // Register it as null so sets aren't rejected.
71 $opts->add(
72 $key,
73 null,
74 FormOptions::guessType( $expected )
75 );
76 }
77
78 $this->changesListSpecialPage->parseParameters(
79 $params,
80 $opts
81 );
82
83 $this->assertArrayEquals(
84 $expected,
85 $opts->getAllValues(),
86 false,
87 true
88 );
89 }
90
94 public function testValidateOptions( $optionsToSet, $expectedRedirect, $expectedRedirectOptions ) {
95 $redirectQuery = [];
96 $redirected = false;
97 $output = $this->getMockBuilder( OutputPage::class )
98 ->disableProxyingToOriginalMethods()
99 ->disableOriginalConstructor()
100 ->getMock();
101 $output->method( 'redirect' )->willReturnCallback(
102 function ( $url ) use ( &$redirectQuery, &$redirected ) {
103 $urlParts = wfParseUrl( $url );
104 $query = isset( $urlParts[ 'query' ] ) ? $urlParts[ 'query' ] : '';
105 parse_str( $query, $redirectQuery );
106 $redirected = true;
107 }
108 );
109 $ctx = new RequestContext();
110
111 // Give users patrol permissions so we can test that.
112 $user = $this->getTestSysop()->getUser();
113 $ctx->setUser( $user );
114
115 // Disable this hook or it could break changeType
116 // depending on which other extensions are running.
117 $this->setTemporaryHook(
118 'ChangesListSpecialPageStructuredFilters',
119 null
120 );
121
122 $ctx->setOutput( $output );
124 $clsp->setContext( $ctx );
125 $opts = $clsp->getDefaultOptions();
126
127 foreach ( $optionsToSet as $option => $value ) {
128 $opts->setValue( $option, $value );
129 }
130
131 $clsp->validateOptions( $opts );
132
133 $this->assertEquals( $expectedRedirect, $redirected, 'redirection' );
134
135 if ( $expectedRedirect ) {
136 if ( count( $expectedRedirectOptions ) > 0 ) {
137 $expectedRedirectOptions += [
138 'title' => $clsp->getPageTitle()->getPrefixedText(),
139 ];
140 }
141
142 $this->assertArrayEquals(
143 $expectedRedirectOptions,
144 $redirectQuery,
145 /* $ordered= */ false,
146 /* $named= */ true,
147 'redirection query'
148 );
149 }
150 }
151}
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
$wgGroupPermissions['sysop']['replacetext']
Abstract base class for shared logic when testing ChangesListSpecialPage and subclasses.
testParseParameters( $params, $expected)
provideParseParameters
testValidateOptions( $optionsToSet, $expectedRedirect, $expectedRedirectOptions)
validateOptionsProvider
Special page which uses a ChangesList to show query results.
An IContextSource implementation which will inherit context from another source but allow individual ...
Helper class to keep track of options when mixing links and form elements.
static guessType( $data)
Used to find out which type the data is.
static getTestSysop()
Convenience method for getting an immutable admin test user.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
setTemporaryHook( $hookName, $handler)
Create a temporary hook handler which will be reset by tearDown.
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Group all the pieces relevant to the context of a request into one instance.
setContext( $context)
Sets the context this SpecialPage is executed in.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2255
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2811
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1620
$params