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,
49 * Returns a new instance of the special page under test.
53 protected function newSpecialPage() {
54 return new SpecialWatchlist();
57 public function testNotLoggedIn_throwsException() {
58 $this->setExpectedException( 'UserNotLoggedIn' );
59 $this->executeSpecialPage();
62 public function testUserWithNoWatchedItems_displaysNoWatchlistMessage() {
63 $user = new TestUser( __METHOD__
);
64 list( $html, ) = $this->executeSpecialPage( '', null, 'qqx', $user->getUser() );
65 $this->assertContains( '(nowatchlist)', $html );
69 * @dataProvider provideFetchOptionsFromRequest
71 public function testFetchOptionsFromRequest( $expectedValues, $preferences, $inputParams ) {
72 $page = TestingAccessWrapper
::newFromObject(
73 $this->newSpecialPage()
76 $context = new DerivativeContext( $page->getContext() );
78 $fauxRequest = new FauxRequest( $inputParams, /* $wasPosted= */ false );
79 $user = $this->getTestUser()->getUser();
81 foreach ( $preferences as $key => $value ) {
82 $user->setOption( $key, $value );
85 $context->setRequest( $fauxRequest );
86 $context->setUser( $user );
87 $page->setContext( $context );
89 $page->registerFilters();
90 $formOptions = $page->getDefaultOptions();
91 $page->fetchOptionsFromRequest( $formOptions );
93 $this->assertArrayEquals(
95 $formOptions->getAllValues(),
96 /* $ordered= */ false,
101 public function provideFetchOptionsFromRequest() {
102 // $defaults and $allFalse are just to make the expected values below
103 // shorter by hiding the background.
105 $page = TestingAccessWrapper
::newFromObject(
106 $this->newSpecialPage()
109 $this->setTemporaryHook(
110 'ChangesListSpecialPageFilters',
114 $page->registerFilters();
116 // Does not consider $preferences, just wiki's defaults
117 $wikiDefaults = $page->getDefaultOptions()->getAllValues();
119 $allFalse = $wikiDefaults;
121 foreach ( $allFalse as $key => &$value ) {
122 if ( $value === true ) {
127 // This is not exposed on the form (only in preferences) so it
128 // respects the preference.
129 $allFalse['extended'] = true;
144 // First two same as prefs
148 // Second two overriden
149 'hideanons' => false,
153 'watchlisthideminor' => 1,
154 'watchlisthidebots' => 0,
156 'watchlisthideanons' => 1,
157 'watchlisthideliu' => 0,
165 // Defaults/preferences for form elements are entirely ignored for
166 // action=submit and omitted elements become false
169 'hideminor' => false,
171 'hideanons' => false,
175 'watchlisthideminor' => 0,
176 'watchlisthidebots' => 1,
177 'watchlisthideanons' => 1,
178 'watchlisthideliu' => 0,
183 'action' => 'submit',