3 use Wikimedia\TestingAccessWrapper
;
10 * @covers SpecialWatchlist
12 class SpecialWatchlistTest
extends SpecialPageTestBase
{
13 public function setUp() {
16 $this->setTemporaryHook(
17 'ChangesListSpecialPageFilters',
21 $this->setTemporaryHook(
22 'SpecialWatchlistQuery',
26 $this->setTemporaryHook(
27 'ChangesListSpecialPageQuery',
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,
50 * Returns a new instance of the special page under test.
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 );
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(
96 $formOptions->getAllValues(),
97 /* $ordered= */ false,
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',
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 ) {
128 // This is not exposed on the form (only in preferences) so it
129 // respects the preference.
130 $allFalse['extended'] = true;
145 // First two same as prefs
149 // Second two overriden
150 'hideanons' => false,
154 'watchlisthideminor' => 1,
155 'watchlisthidebots' => 0,
157 'watchlisthideanons' => 1,
158 'watchlisthideliu' => 0,
166 // Defaults/preferences for form elements are entirely ignored for
167 // action=submit and omitted elements become false
170 'hideminor' => false,
172 'hideanons' => false,
176 'watchlisthideminor' => 0,
177 'watchlisthidebots' => 1,
178 'watchlisthideanons' => 1,
179 'watchlisthideliu' => 0,
184 'action' => 'submit',