8 * @covers SpecialWatchlist
10 class SpecialWatchlistTest
extends SpecialPageTestBase
{
11 public function setUp() {
14 $this->setTemporaryHook(
15 'ChangesListSpecialPageFilters',
19 $this->setTemporaryHook(
20 'SpecialWatchlistQuery',
24 $this->setTemporaryHook(
25 'ChangesListSpecialPageQuery',
30 'wgDefaultUserOptions',
32 'extendwatchlist' => 1,
33 'watchlistdays' => 3.0,
34 'watchlisthideanons' => 0,
35 'watchlisthidebots' => 0,
36 'watchlisthideliu' => 0,
37 'watchlisthideminor' => 0,
38 'watchlisthideown' => 0,
39 'watchlisthidepatrolled' => 0,
40 'watchlisthidecategorization' => 1,
41 'watchlistreloadautomatically' => 0,
48 * Returns a new instance of the special page under test.
52 protected function newSpecialPage() {
53 return new SpecialWatchlist();
56 public function testNotLoggedIn_throwsException() {
57 $this->setExpectedException( 'UserNotLoggedIn' );
58 $this->executeSpecialPage();
61 public function testUserWithNoWatchedItems_displaysNoWatchlistMessage() {
62 $user = new TestUser( __METHOD__
);
63 list( $html, ) = $this->executeSpecialPage( '', null, 'qqx', $user->getUser() );
64 $this->assertContains( '(nowatchlist)', $html );
68 * @dataProvider provideFetchOptionsFromRequest
70 public function testFetchOptionsFromRequest( $expectedValues, $preferences, $inputParams ) {
71 $page = TestingAccessWrapper
::newFromObject(
72 $this->newSpecialPage()
75 $context = new DerivativeContext( $page->getContext() );
77 $fauxRequest = new FauxRequest( $inputParams, /* $wasPosted= */ false );
78 $user = $this->getTestUser()->getUser();
80 foreach ( $preferences as $key => $value ) {
81 $user->setOption( $key, $value );
84 $context->setRequest( $fauxRequest );
85 $context->setUser( $user );
86 $page->setContext( $context );
88 $page->registerFilters();
89 $formOptions = $page->getDefaultOptions();
90 $page->fetchOptionsFromRequest( $formOptions );
92 $this->assertArrayEquals(
94 $formOptions->getAllValues(),
95 /* $ordered= */ false,
100 public function provideFetchOptionsFromRequest() {
101 // $defaults and $allFalse are just to make the expected values below
102 // shorter by hiding the background.
104 $page = TestingAccessWrapper
::newFromObject(
105 $this->newSpecialPage()
108 $this->setTemporaryHook(
109 'ChangesListSpecialPageFilters',
113 $page->registerFilters();
115 // Does not consider $preferences, just wiki's defaults
116 $wikiDefaults = $page->getDefaultOptions()->getAllValues();
118 $allFalse = $wikiDefaults;
120 foreach ( $allFalse as $key => &$value ) {
121 if ( $value === true ) {
126 // This is not exposed on the form (only in preferences) so it
127 // respects the preference.
128 $allFalse['extended'] = true;
143 // First two same as prefs
147 // Second two overriden
148 'hideanons' => false,
152 'watchlisthideminor' => 1,
153 'watchlisthidebots' => 0,
155 'watchlisthideanons' => 1,
156 'watchlisthideliu' => 0,
164 // Defaults/preferences for form elements are entirely ignored for
165 // action=submit and omitted elements become false
168 'hideminor' => false,
170 'hideanons' => false,
174 'watchlisthideminor' => 0,
175 'watchlisthidebots' => 1,
176 'watchlisthideanons' => 1,
177 'watchlisthideliu' => 0,
182 'action' => 'submit',