rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / specials / SpecialWatchlistTest.php
blob1c43919955204415fcbfb4b6b6b6b1ad1c617bb7
1 <?php
3 use Wikimedia\TestingAccessWrapper;
5 /**
6 * @author Addshore
8 * @group Database
10 * @covers SpecialWatchlist
12 class SpecialWatchlistTest extends SpecialPageTestBase {
13 public function setUp() {
14 parent::setUp();
16 $this->setTemporaryHook(
17 'ChangesListSpecialPageFilters',
18 null
21 $this->setTemporaryHook(
22 'SpecialWatchlistQuery',
23 null
26 $this->setTemporaryHook(
27 'ChangesListSpecialPageQuery',
28 null
31 $this->setMwGlobals(
32 'wgDefaultUserOptions',
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,
49 /**
50 * Returns a new instance of the special page under test.
52 * @return SpecialPage
54 protected function newSpecialPage() {
55 return new SpecialWatchlist();
58 public function testNotLoggedIn_throwsException() {
59 $this->setExpectedException( 'UserNotLoggedIn' );
60 $this->executeSpecialPage();
63 public function testUserWithNoWatchedItems_displaysNoWatchlistMessage() {
64 $user = new TestUser( __METHOD__ );
65 list( $html, ) = $this->executeSpecialPage( '', null, 'qqx', $user->getUser() );
66 $this->assertContains( '(nowatchlist)', $html );
69 /**
70 * @dataProvider provideFetchOptionsFromRequest
72 public function testFetchOptionsFromRequest( $expectedValues, $preferences, $inputParams ) {
73 $page = TestingAccessWrapper::newFromObject(
74 $this->newSpecialPage()
77 $context = new DerivativeContext( $page->getContext() );
79 $fauxRequest = new FauxRequest( $inputParams, /* $wasPosted= */ false );
80 $user = $this->getTestUser()->getUser();
82 foreach ( $preferences as $key => $value ) {
83 $user->setOption( $key, $value );
86 $context->setRequest( $fauxRequest );
87 $context->setUser( $user );
88 $page->setContext( $context );
90 $page->registerFilters();
91 $formOptions = $page->getDefaultOptions();
92 $page->fetchOptionsFromRequest( $formOptions );
94 $this->assertArrayEquals(
95 $expectedValues,
96 $formOptions->getAllValues(),
97 /* $ordered= */ false,
98 /* $named= */ true
102 public function provideFetchOptionsFromRequest() {
103 // $defaults and $allFalse are just to make the expected values below
104 // shorter by hiding the background.
106 $page = TestingAccessWrapper::newFromObject(
107 $this->newSpecialPage()
110 $this->setTemporaryHook(
111 'ChangesListSpecialPageFilters',
112 null
115 $page->registerFilters();
117 // Does not consider $preferences, just wiki's defaults
118 $wikiDefaults = $page->getDefaultOptions()->getAllValues();
120 $allFalse = $wikiDefaults;
122 foreach ( $allFalse as $key => &$value ) {
123 if ( $value === true ) {
124 $value = false;
128 // This is not exposed on the form (only in preferences) so it
129 // respects the preference.
130 $allFalse['extended'] = true;
132 return [
135 'hideminor' => true,
136 ] + $wikiDefaults,
139 'hideMinor' => 1,
145 // First two same as prefs
146 'hideminor' => true,
147 'hidebots' => false,
149 // Second two overriden
150 'hideanons' => false,
151 'hideliu' => true,
152 ] + $wikiDefaults,
154 'watchlisthideminor' => 1,
155 'watchlisthidebots' => 0,
157 'watchlisthideanons' => 1,
158 'watchlisthideliu' => 0,
161 'hideanons' => 0,
162 'hideliu' => 1,
166 // Defaults/preferences for form elements are entirely ignored for
167 // action=submit and omitted elements become false
170 'hideminor' => false,
171 'hidebots' => true,
172 'hideanons' => false,
173 'hideliu' => true,
174 ] + $allFalse,
176 'watchlisthideminor' => 0,
177 'watchlisthidebots' => 1,
178 'watchlisthideanons' => 1,
179 'watchlisthideliu' => 0,
182 'hidebots' => 1,
183 'hideliu' => 1,
184 'action' => 'submit',