MediaWiki REL1_33
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 'ChangesListSpecialPageQuery',
18 null
19 );
20
21 $this->setMwGlobals(
22 'wgDefaultUserOptions',
23 [
24 'extendwatchlist' => 1,
25 'watchlistdays' => 3.0,
26 'watchlisthideanons' => 0,
27 'watchlisthidebots' => 0,
28 'watchlisthideliu' => 0,
29 'watchlisthideminor' => 0,
30 'watchlisthideown' => 0,
31 'watchlisthidepatrolled' => 0,
32 'watchlisthidecategorization' => 1,
33 'watchlistreloadautomatically' => 0,
34 'watchlistunwatchlinks' => 0,
35 ]
36 );
37 }
38
44 protected function newSpecialPage() {
45 return new SpecialWatchlist();
46 }
47
49 $this->setExpectedException( UserNotLoggedIn::class );
50 $this->executeSpecialPage();
51 }
52
54 $user = new TestUser( __METHOD__ );
55 list( $html, ) = $this->executeSpecialPage( '', null, 'qqx', $user->getUser() );
56 $this->assertContains( '(nowatchlist)', $html );
57 }
58
63 $expectedValuesDefaults, $expectedValues, $preferences, $inputParams
64 ) {
65 // $defaults and $allFalse are just to make the expected values below
66 // shorter by hiding the background.
67
68 $page = TestingAccessWrapper::newFromObject(
69 $this->newSpecialPage()
70 );
71
72 $page->registerFilters();
73
74 // Does not consider $preferences, just wiki's defaults
75 $wikiDefaults = $page->getDefaultOptions()->getAllValues();
76
77 switch ( $expectedValuesDefaults ) {
78 case 'allFalse':
79 $allFalse = $wikiDefaults;
80
81 foreach ( $allFalse as $key => $value ) {
82 if ( $value === true ) {
83 $allFalse[$key] = false;
84 }
85 }
86
87 // This is not exposed on the form (only in preferences) so it
88 // respects the preference.
89 $allFalse['extended'] = true;
90
91 $expectedValues += $allFalse;
92 break;
93 case 'wikiDefaults':
94 $expectedValues += $wikiDefaults;
95 break;
96 default:
97 $this->fail( "Unknown \$expectedValuesDefaults: $expectedValuesDefaults" );
98 }
99
100 $page = TestingAccessWrapper::newFromObject(
101 $this->newSpecialPage()
102 );
103
104 $context = new DerivativeContext( $page->getContext() );
105
106 $fauxRequest = new FauxRequest( $inputParams, /* $wasPosted= */ false );
107 $user = $this->getTestUser()->getUser();
108
109 foreach ( $preferences as $key => $value ) {
110 $user->setOption( $key, $value );
111 }
112
113 $context->setRequest( $fauxRequest );
114 $context->setUser( $user );
115 $page->setContext( $context );
116
117 $page->registerFilters();
118 $formOptions = $page->getDefaultOptions();
119 $page->fetchOptionsFromRequest( $formOptions );
120
121 $this->assertArrayEquals(
122 $expectedValues,
123 $formOptions->getAllValues(),
124 /* $ordered= */ false,
125 /* $named= */ true
126 );
127 }
128
130 return [
131 'ignores casing' => [
132 'expectedValuesDefaults' => 'wikiDefaults',
133 'expectedValues' => [
134 'hideminor' => true,
135 ],
136 'preferences' => [],
137 'inputParams' => [
138 'hideMinor' => 1,
139 ],
140 ],
141
142 'first two same as prefs, second two overriden' => [
143 'expectedValuesDefaults' => 'wikiDefaults',
144 'expectedValues' => [
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 ],
154 'preferences' => [
155 'watchlisthideminor' => 1,
156 'watchlisthidebots' => 0,
157
158 'watchlisthideanons' => 1,
159 'watchlisthideliu' => 0,
160 ],
161 'inputParams' => [
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 'expectedValuesDefaults' => 'allFalse',
170 'expectedValues' => [
171 'hideminor' => false,
172 'hidebots' => true,
173 'hideanons' => false,
174 'hideliu' => true,
175 'userExpLevel' => 'unregistered'
176 ],
177 'preferences' => [
178 'watchlisthideminor' => 0,
179 'watchlisthidebots' => 1,
180
181 'watchlisthideanons' => 0,
182 'watchlisthideliu' => 1,
183 ],
184 'inputParams' => [
185 'hidebots' => 1,
186 'hideliu' => 1,
187 'action' => 'submit',
188 ],
189 ],
190 ];
191 }
192}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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)
newSpecialPage()
Returns a new instance of the special page under test.
testFetchOptionsFromRequest( $expectedValuesDefaults, $expectedValues, $preferences, $inputParams)
provideFetchOptionsFromRequest
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:9
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
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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 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:2011
return true to allow those checks to and false if checking is done & $user
Definition hooks.txt:1510
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37