MediaWiki REL1_33
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 # setup the ChangesListSpecialPage (or subclass) object
36 $this->changesListSpecialPage = $this->getPage();
37 $context = $this->changesListSpecialPage->getContext();
39 $context->setUser( $this->getTestUser( [ 'patrollers' ] )->getUser() );
40 $this->changesListSpecialPage->setContext( $context );
41 $this->changesListSpecialPage->registerFilters();
42 }
43
44 abstract protected function getPage();
45
46 protected function tearDown() {
48
49 parent::tearDown();
50
51 if ( $this->oldPatrollersGroup !== null ) {
53 }
54 }
55
56 abstract public function provideParseParameters();
57
61 public function testParseParameters( $params, $expected ) {
62 $opts = new FormOptions();
63 foreach ( $expected as $key => $value ) {
64 // Register it as null so sets aren't rejected.
65 $opts->add(
66 $key,
67 null,
68 FormOptions::guessType( $expected )
69 );
70 }
71
72 $this->changesListSpecialPage->parseParameters(
73 $params,
74 $opts
75 );
76
77 $this->assertArrayEquals(
78 $expected,
79 $opts->getAllValues(),
80 false,
81 true
82 );
83 }
84
88 public function testValidateOptions(
89 $optionsToSet,
90 $expectedRedirect,
91 $expectedRedirectOptions,
92 $rcfilters
93 ) {
94 $redirectQuery = [];
95 $redirected = false;
96 $output = $this->getMockBuilder( OutputPage::class )
97 ->disableProxyingToOriginalMethods()
98 ->disableOriginalConstructor()
99 ->getMock();
100 $output->method( 'redirect' )->willReturnCallback(
101 function ( $url ) use ( &$redirectQuery, &$redirected ) {
102 $urlParts = wfParseUrl( $url );
103 $query = $urlParts[ 'query' ] ?? '';
104 parse_str( $query, $redirectQuery );
105 $redirected = true;
106 }
107 );
108 $ctx = new RequestContext();
109
110 // Give users patrol permissions so we can test that.
111 $user = $this->getTestSysop()->getUser();
112 $user->setOption( 'rcenhancedfilters-disable', $rcfilters ? 0 : 1 );
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}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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, $rcfilters)
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.
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:2848
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:1617
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2272
$params