MediaWiki REL1_31
SpecialWatchlistTest.php
Go to the documentation of this file.
1<?php
2
3use Wikimedia\TestingAccessWrapper;
4
13 public function setUp() {
14 parent::setUp();
15
16 $this->setTemporaryHook(
17 'ChangesListSpecialPageFilters',
18 null
19 );
20
21 $this->setTemporaryHook(
22 'SpecialWatchlistQuery',
23 null
24 );
25
26 $this->setTemporaryHook(
27 'ChangesListSpecialPageQuery',
28 null
29 );
30
31 $this->setMwGlobals(
32 'wgDefaultUserOptions',
33 [
34 'extendwatchlist' => 1,
35 'watchlistdays' => 3.0,
36 'watchlisthideanons' => 0,
37 'watchlisthidebots' => 0,
38 'watchlisthideliu' => 0,
39 'watchlisthideminor' => 0,
40 'watchlisthideown' => 0,
41 'watchlisthidepatrolled' => 0,
42 'watchlisthidecategorization' => 1,
43 'watchlistreloadautomatically' => 0,
44 'watchlistunwatchlinks' => 0,
45 ]
46 );
47 }
48
54 protected function newSpecialPage() {
55 return new SpecialWatchlist();
56 }
57
59 $this->setExpectedException( UserNotLoggedIn::class );
60 $this->executeSpecialPage();
61 }
62
64 $user = new TestUser( __METHOD__ );
65 list( $html, ) = $this->executeSpecialPage( '', null, 'qqx', $user->getUser() );
66 $this->assertContains( '(nowatchlist)', $html );
67 }
68
72 public function testFetchOptionsFromRequest( $expectedValues, $preferences, $inputParams ) {
73 $page = TestingAccessWrapper::newFromObject(
74 $this->newSpecialPage()
75 );
76
77 $context = new DerivativeContext( $page->getContext() );
78
79 $fauxRequest = new FauxRequest( $inputParams, /* $wasPosted= */ false );
80 $user = $this->getTestUser()->getUser();
81
82 foreach ( $preferences as $key => $value ) {
83 $user->setOption( $key, $value );
84 }
85
86 $context->setRequest( $fauxRequest );
87 $context->setUser( $user );
88 $page->setContext( $context );
89
90 $page->registerFilters();
91 $formOptions = $page->getDefaultOptions();
92 $page->fetchOptionsFromRequest( $formOptions );
93
94 $this->assertArrayEquals(
95 $expectedValues,
96 $formOptions->getAllValues(),
97 /* $ordered= */ false,
98 /* $named= */ true
99 );
100 }
101
103 // $defaults and $allFalse are just to make the expected values below
104 // shorter by hiding the background.
105
106 $page = TestingAccessWrapper::newFromObject(
107 $this->newSpecialPage()
108 );
109
110 $this->setTemporaryHook(
111 'ChangesListSpecialPageFilters',
112 null
113 );
114
115 $page->registerFilters();
116
117 // Does not consider $preferences, just wiki's defaults
118 $wikiDefaults = $page->getDefaultOptions()->getAllValues();
119
120 $allFalse = $wikiDefaults;
121
122 foreach ( $allFalse as $key => &$value ) {
123 if ( $value === true ) {
124 $value = false;
125 }
126 }
127
128 // This is not exposed on the form (only in preferences) so it
129 // respects the preference.
130 $allFalse['extended'] = true;
131
132 return [
133 [
134 [
135 'hideminor' => true,
136 ] + $wikiDefaults,
137 [],
138 [
139 'hideMinor' => 1,
140 ],
141 ],
142
143 [
144 [
145 // First two same as prefs
146 'hideminor' => true,
147 'hidebots' => false,
148
149 // Second two overriden
150 'hideanons' => false,
151 'hideliu' => true,
152 'userExpLevel' => 'registered'
153 ] + $wikiDefaults,
154 [
155 'watchlisthideminor' => 1,
156 'watchlisthidebots' => 0,
157
158 'watchlisthideanons' => 1,
159 'watchlisthideliu' => 0,
160 ],
161 [
162 'hideanons' => 0,
163 'hideliu' => 1,
164 ],
165 ],
166
167 // Defaults/preferences for form elements are entirely ignored for
168 // action=submit and omitted elements become false
169 [
170 [
171 'hideminor' => false,
172 'hidebots' => true,
173 'hideanons' => false,
174 'hideliu' => true,
175 'userExpLevel' => 'unregistered'
176 ] + $allFalse,
177 [
178 'watchlisthideminor' => 0,
179 'watchlisthidebots' => 1,
180
181 'watchlisthideanons' => 0,
182 'watchlisthideliu' => 1,
183 ],
184 [
185 'hidebots' => 1,
186 'hideliu' => 1,
187 'action' => 'submit',
188 ],
189 ],
190 ];
191 }
192}
An IContextSource implementation which will inherit context from another source but allow individual ...
WebRequest clone which takes values from a provided array.
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.
Base class for testing special pages.
executeSpecialPage( $subPage='', WebRequest $request=null, $language=null, User $user=null)
testFetchOptionsFromRequest( $expectedValues, $preferences, $inputParams)
provideFetchOptionsFromRequest
newSpecialPage()
Returns a new instance of the special page under test.
A special page that lists last changes made to the wiki, limited to user-defined list of titles.
Wraps the user object, so we can also retain full access to properties like password if we log in via...
Definition TestUser.php:7
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
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 means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition hooks.txt:2013