MediaWiki REL1_30
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( 'wgRCWatchCategoryMembership', true );
23
24 if ( isset( $wgGroupPermissions['patrollers'] ) ) {
25 $this->oldPatrollersGroup = $wgGroupPermissions['patrollers'];
26 }
27
28 $wgGroupPermissions['patrollers'] = [
29 'patrol' => true,
30 ];
31
32 // Deprecated
33 $this->setTemporaryHook(
34 'ChangesListSpecialPageFilters',
35 null
36 );
37
38 # setup the ChangesListSpecialPage (or subclass) object
39 $this->changesListSpecialPage = $this->getPage();
40 $context = $this->changesListSpecialPage->getContext();
42 $context->setUser( $this->getTestUser( [ 'patrollers' ] )->getUser() );
43 $this->changesListSpecialPage->setContext( $context );
44 $this->changesListSpecialPage->registerFilters();
45 }
46
47 protected function tearDown() {
49
50 parent::tearDown();
51
52 if ( $this->oldPatrollersGroup !== null ) {
54 }
55 }
56
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.
64 $opts->add(
65 $key,
66 null,
67 FormOptions::guessType( $expected )
68 );
69 }
70
71 $this->changesListSpecialPage->parseParameters(
72 $params,
73 $opts
74 );
75
76 $this->assertArrayEquals(
77 $expected,
78 $opts->getAllValues(),
79 false,
80 true
81 );
82 }
83
87 public function testValidateOptions( $optionsToSet, $expectedRedirect, $expectedRedirectOptions ) {
88 $redirectQuery = [];
89 $redirected = false;
90 $output = $this->getMockBuilder( OutputPage::class )
91 ->disableProxyingToOriginalMethods()
92 ->disableOriginalConstructor()
93 ->getMock();
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 );
99 $redirected = true;
100 }
101 );
102 $ctx = new RequestContext();
103
104 // Give users patrol permissions so we can test that.
105 $user = $this->getTestSysop()->getUser();
106 $ctx->setUser( $user );
107
108 // Disable this hook or it could break changeType
109 // depending on which other extensions are running.
110 $this->setTemporaryHook(
111 'ChangesListSpecialPageStructuredFilters',
112 null
113 );
114
115 $ctx->setOutput( $output );
117 $clsp->setContext( $ctx );
118 $opts = $clsp->getDefaultOptions();
119
120 foreach ( $optionsToSet as $option => $value ) {
121 $opts->setValue( $option, $value );
122 }
123
124 $clsp->validateOptions( $opts );
125
126 $this->assertEquals( $expectedRedirect, $redirected, 'redirection' );
127
128 if ( $expectedRedirect ) {
129 if ( count( $expectedRedirectOptions ) > 0 ) {
130 $expectedRedirectOptions += [
131 'title' => $clsp->getPageTitle()->getPrefixedText(),
132 ];
133 }
134
135 $this->assertArrayEquals(
136 $expectedRedirectOptions,
137 $redirectQuery,
138 /* $ordered= */ false,
139 /* $named= */ true,
140 'redirection query'
141 );
142 }
143 }
144}
$wgGroupPermissions
Permission keys given to users in each group.
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
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:2225
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:2780
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:1610
$params