3 use Wikimedia\TestingAccessWrapper
;
10 * @covers SpecialWatchlist
12 class SpecialWatchlistTest
extends SpecialPageTestBase
{
13 public function setUp() {
16 $this->setTemporaryHook(
17 'ChangesListSpecialPageQuery',
22 'wgDefaultUserOptions',
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,
40 * Returns a new instance of the special page under test.
44 protected function newSpecialPage() {
45 return new SpecialWatchlist();
48 public function testNotLoggedIn_throwsException() {
49 $this->setExpectedException( UserNotLoggedIn
::class );
50 $this->executeSpecialPage();
53 public function testUserWithNoWatchedItems_displaysNoWatchlistMessage() {
54 $user = new TestUser( __METHOD__
);
55 list( $html, ) = $this->executeSpecialPage( '', null, 'qqx', $user->getUser() );
56 $this->assertContains( '(nowatchlist)', $html );
60 * @dataProvider provideFetchOptionsFromRequest
62 public function testFetchOptionsFromRequest(
63 $expectedValuesDefaults, $expectedValues, $preferences, $inputParams
65 // $defaults and $allFalse are just to make the expected values below
66 // shorter by hiding the background.
68 $page = TestingAccessWrapper
::newFromObject(
69 $this->newSpecialPage()
72 $page->registerFilters();
74 // Does not consider $preferences, just wiki's defaults
75 $wikiDefaults = $page->getDefaultOptions()->getAllValues();
77 switch ( $expectedValuesDefaults ) {
79 $allFalse = $wikiDefaults;
81 foreach ( $allFalse as $key => $value ) {
82 if ( $value === true ) {
83 $allFalse[$key] = false;
87 // This is not exposed on the form (only in preferences) so it
88 // respects the preference.
89 $allFalse['extended'] = true;
91 $expectedValues +
= $allFalse;
94 $expectedValues +
= $wikiDefaults;
97 $this->fail( "Unknown \$expectedValuesDefaults: $expectedValuesDefaults" );
100 $page = TestingAccessWrapper
::newFromObject(
101 $this->newSpecialPage()
104 $context = new DerivativeContext( $page->getContext() );
106 $fauxRequest = new FauxRequest( $inputParams, /* $wasPosted= */ false );
107 $user = $this->getTestUser()->getUser();
109 foreach ( $preferences as $key => $value ) {
110 $user->setOption( $key, $value );
113 $context->setRequest( $fauxRequest );
114 $context->setUser( $user );
115 $page->setContext( $context );
117 $page->registerFilters();
118 $formOptions = $page->getDefaultOptions();
119 $page->fetchOptionsFromRequest( $formOptions );
121 $this->assertArrayEquals(
123 $formOptions->getAllValues(),
124 /* $ordered= */ false,
129 public function provideFetchOptionsFromRequest() {
131 'ignores casing' => [
132 'expectedValuesDefaults' => 'wikiDefaults',
133 'expectedValues' => [
142 'first two same as prefs, second two overriden' => [
143 'expectedValuesDefaults' => 'wikiDefaults',
144 'expectedValues' => [
145 // First two same as prefs
149 // Second two overriden
150 'hideanons' => false,
152 'userExpLevel' => 'registered'
155 'watchlisthideminor' => 1,
156 'watchlisthidebots' => 0,
158 'watchlisthideanons' => 1,
159 'watchlisthideliu' => 0,
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,
173 'hideanons' => false,
175 'userExpLevel' => 'unregistered'
178 'watchlisthideminor' => 0,
179 'watchlisthidebots' => 1,
181 'watchlisthideanons' => 0,
182 'watchlisthideliu' => 1,
187 'action' => 'submit',