MediaWiki REL1_32
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
62 public function testFetchOptionsFromRequest( $expectedValues, $preferences, $inputParams ) {
63 $page = TestingAccessWrapper::newFromObject(
64 $this->newSpecialPage()
65 );
66
67 $context = new DerivativeContext( $page->getContext() );
68
69 $fauxRequest = new FauxRequest( $inputParams, /* $wasPosted= */ false );
70 $user = $this->getTestUser()->getUser();
71
72 foreach ( $preferences as $key => $value ) {
73 $user->setOption( $key, $value );
74 }
75
76 $context->setRequest( $fauxRequest );
77 $context->setUser( $user );
78 $page->setContext( $context );
79
80 $page->registerFilters();
81 $formOptions = $page->getDefaultOptions();
82 $page->fetchOptionsFromRequest( $formOptions );
83
84 $this->assertArrayEquals(
85 $expectedValues,
86 $formOptions->getAllValues(),
87 /* $ordered= */ false,
88 /* $named= */ true
89 );
90 }
91
93 // $defaults and $allFalse are just to make the expected values below
94 // shorter by hiding the background.
95
96 $page = TestingAccessWrapper::newFromObject(
97 $this->newSpecialPage()
98 );
99
100 $page->registerFilters();
101
102 // Does not consider $preferences, just wiki's defaults
103 $wikiDefaults = $page->getDefaultOptions()->getAllValues();
104
105 $allFalse = $wikiDefaults;
106
107 foreach ( $allFalse as $key => &$value ) {
108 if ( $value === true ) {
109 $value = false;
110 }
111 }
112
113 // This is not exposed on the form (only in preferences) so it
114 // respects the preference.
115 $allFalse['extended'] = true;
116
117 return [
118 [
119 [
120 'hideminor' => true,
121 ] + $wikiDefaults,
122 [],
123 [
124 'hideMinor' => 1,
125 ],
126 ],
127
128 [
129 [
130 // First two same as prefs
131 'hideminor' => true,
132 'hidebots' => false,
133
134 // Second two overriden
135 'hideanons' => false,
136 'hideliu' => true,
137 'userExpLevel' => 'registered'
138 ] + $wikiDefaults,
139 [
140 'watchlisthideminor' => 1,
141 'watchlisthidebots' => 0,
142
143 'watchlisthideanons' => 1,
144 'watchlisthideliu' => 0,
145 ],
146 [
147 'hideanons' => 0,
148 'hideliu' => 1,
149 ],
150 ],
151
152 // Defaults/preferences for form elements are entirely ignored for
153 // action=submit and omitted elements become false
154 [
155 [
156 'hideminor' => false,
157 'hidebots' => true,
158 'hideanons' => false,
159 'hideliu' => true,
160 'userExpLevel' => 'unregistered'
161 ] + $allFalse,
162 [
163 'watchlisthideminor' => 0,
164 'watchlisthidebots' => 1,
165
166 'watchlisthideanons' => 0,
167 'watchlisthideliu' => 1,
168 ],
169 [
170 'hidebots' => 1,
171 'hideliu' => 1,
172 'action' => 'submit',
173 ],
174 ],
175 ];
176 }
177}
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)
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: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:2885
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:2062
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
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