MediaWiki  1.30.0
SpecialWatchlistTest.php
Go to the documentation of this file.
1 <?php
2 
3 use 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 
58  public function testNotLoggedIn_throwsException() {
59  $this->setExpectedException( 'UserNotLoggedIn' );
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 
102  public function provideFetchOptionsFromRequest() {
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  ] + $wikiDefaults,
153  [
154  'watchlisthideminor' => 1,
155  'watchlisthidebots' => 0,
156 
157  'watchlisthideanons' => 1,
158  'watchlisthideliu' => 0,
159  ],
160  [
161  'hideanons' => 0,
162  'hideliu' => 1,
163  ],
164  ],
165 
166  // Defaults/preferences for form elements are entirely ignored for
167  // action=submit and omitted elements become false
168  [
169  [
170  'hideminor' => false,
171  'hidebots' => true,
172  'hideanons' => false,
173  'hideliu' => true,
174  ] + $allFalse,
175  [
176  'watchlisthideminor' => 0,
177  'watchlisthidebots' => 1,
178  'watchlisthideanons' => 1,
179  'watchlisthideliu' => 0,
180  ],
181  [
182  'hidebots' => 1,
183  'hideliu' => 1,
184  'action' => 'submit',
185  ],
186  ],
187  ];
188  }
189 }
$user
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 account $user
Definition: hooks.txt:244
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:1552
$context
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:2581
MediaWikiTestCase\getTestUser
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
Definition: MediaWikiTestCase.php:148
SpecialWatchlistTest\testNotLoggedIn_throwsException
testNotLoggedIn_throwsException()
Definition: SpecialWatchlistTest.php:58
SpecialWatchlistTest
Definition: SpecialWatchlistTest.php:12
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
php
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:35
TestUser
Wraps the user object, so we can also retain full access to properties like password if we log in via...
Definition: TestUser.php:7
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:31
SpecialPageTestBase
Base class for testing special pages.
Definition: SpecialPageTestBase.php:14
$html
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:1965
SpecialWatchlistTest\provideFetchOptionsFromRequest
provideFetchOptionsFromRequest()
Definition: SpecialWatchlistTest.php:102
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:672
list
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
SpecialWatchlist
A special page that lists last changes made to the wiki, limited to user-defined list of titles.
Definition: SpecialWatchlist.php:34
$value
$value
Definition: styleTest.css.php:45
SpecialPageTestBase\executeSpecialPage
executeSpecialPage( $subPage='', WebRequest $request=null, $language=null, User $user=null)
Definition: SpecialPageTestBase.php:57
SpecialWatchlistTest\testUserWithNoWatchedItems_displaysNoWatchlistMessage
testUserWithNoWatchedItems_displaysNoWatchlistMessage()
Definition: SpecialWatchlistTest.php:63
as
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
Definition: distributors.txt:9
true
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 true
Definition: hooks.txt:1965
MediaWikiTestCase\setTemporaryHook
setTemporaryHook( $hookName, $handler)
Create a temporary hook handler which will be reset by tearDown.
Definition: MediaWikiTestCase.php:1850
SpecialWatchlistTest\testFetchOptionsFromRequest
testFetchOptionsFromRequest( $expectedValues, $preferences, $inputParams)
provideFetchOptionsFromRequest
Definition: SpecialWatchlistTest.php:72
SpecialWatchlistTest\setUp
setUp()
Definition: SpecialWatchlistTest.php:13
SpecialWatchlistTest\newSpecialPage
newSpecialPage()
Returns a new instance of the special page under test.
Definition: SpecialWatchlistTest.php:54