jenkins-bot has submitted this change and it was merged.

Change subject: Switch to use ChangesListSpecialPageFilters hook in client
......................................................................


Switch to use ChangesListSpecialPageFilters hook in client

Not in scope of this patch is to rename the recent changes
option name etc. While this might seem simple, it needs a
migration strategy to convert existing preferences and
b/w compat for the old filter name and should be done
carefully in a separate patch.

Bug: T64798
Change-Id: I66d345e4355accf44f93ce8c6d765c41cebbcc3b
---
M client/WikibaseClient.hooks.php
M client/WikibaseClient.php
A client/includes/Hooks/ChangesListSpecialPageFilterHandler.php
D client/includes/Hooks/ChangesPageWikibaseFilterHandler.php
A 
client/tests/phpunit/includes/Hooks/ChangesListSpecialPageFilterHandlerTest.php
D client/tests/phpunit/includes/Hooks/ChangesPageWikibaseFilterHandlerTest.php
6 files changed, 395 insertions(+), 299 deletions(-)

Approvals:
  Hoo man: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index dbf0e26..9178629 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -439,54 +439,6 @@
        }
 
        /**
-        * Adds a toggle for showing/hiding Wikidata entries in recent changes
-        *
-        * @param SpecialRecentChanges $special
-        * @param array &$filters
-        *
-        * @return bool
-        */
-       public static function onSpecialRecentChangesFilters( 
SpecialRecentChanges $special, array &$filters ) {
-               $hookHandler = new ChangesPageWikibaseFilterHandler(
-                       $special->getContext(),
-                       
WikibaseClient::getDefaultInstance()->getSettings()->getSetting( 
'showExternalRecentChanges' ),
-                       'hidewikidata',
-                       'rcshowwikidata',
-                       'wikibase-rc-hide-wikidata'
-               );
-
-               // @fixme remove wikidata-specific stuff!
-               $filters = $hookHandler->addFilterIfEnabled( $filters );
-
-               return true;
-       }
-
-       /**
-        * Modifies watchlist options to show a toggle for Wikibase changes
-        * @see 
https://www.mediawiki.org/wiki/Manual:Hooks/SpecialWatchlistFilters
-        *
-        * @since 0.4
-        *
-        * @param SpecialWatchlist $special
-        * @param array $filters
-        *
-        * @return bool
-        */
-       public static function onSpecialWatchlistFilters( $special, &$filters ) 
{
-               $hookHandler = new ChangesPageWikibaseFilterHandler(
-                       $special->getContext(),
-                       
WikibaseClient::getDefaultInstance()->getSettings()->getSetting( 
'showExternalRecentChanges' ),
-                       'hideWikibase',
-                       'wlshowwikibase',
-                       'wikibase-rc-hide-wikidata'
-               );
-
-               $filters = $hookHandler->addFilterIfEnabled( $filters );
-
-               return true;
-       }
-
-       /**
         * Adds a preference for showing or hiding Wikidata entries in recent 
changes
         *
         * @param User $user
diff --git a/client/WikibaseClient.php b/client/WikibaseClient.php
index f59b086..0140d0a 100644
--- a/client/WikibaseClient.php
+++ b/client/WikibaseClient.php
@@ -36,6 +36,8 @@
  * @defgroup WikibaseClient Wikibase Client
  */
 
+// @codingStandardsIgnoreFile
+
 if ( !defined( 'MEDIAWIKI' ) ) {
        die( "Not an entry point.\n" );
 }
@@ -110,14 +112,10 @@
        $wgHooks['ParserGetVariableValueSwitch'][] = 
'\Wikibase\ClientHooks::onParserGetVariableValueSwitch';
        $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 
'\Wikibase\ClientHooks::onSkinTemplateOutputPageBeforeExec';
        $wgHooks['SpecialMovepageAfterMove'][] = 
'\Wikibase\Client\Hooks\MovePageNotice::onSpecialMovepageAfterMove';
-       $wgHooks['SpecialWatchlistQuery'][] = 
'\Wikibase\ClientHooks::onSpecialWatchlistQuery';
-       $wgHooks['SpecialRecentChangesQuery'][] = 
'\Wikibase\ClientHooks::onSpecialRecentChangesQuery';
-       $wgHooks['SpecialRecentChangesFilters'][] = 
'\Wikibase\ClientHooks::onSpecialRecentChangesFilters';
        $wgHooks['GetPreferences'][] = 
'\Wikibase\ClientHooks::onGetPreferences';
        $wgHooks['BeforePageDisplay'][] = 
'\Wikibase\ClientHooks::onBeforePageDisplay';
        $wgHooks['BeforePageDisplay'][] = 
'\Wikibase\ClientHooks::onBeforePageDisplayAddJsConfig';
        $wgHooks['ScribuntoExternalLibraries'][] = 
'\Wikibase\ClientHooks::onScribuntoExternalLibraries';
-       $wgHooks['SpecialWatchlistFilters'][] = 
'\Wikibase\ClientHooks::onSpecialWatchlistFilters';
        $wgHooks['InfoAction'][] = '\Wikibase\ClientHooks::onInfoAction';
        $wgHooks['TitleMoveComplete'][] = 
'\Wikibase\Client\Hooks\UpdateRepoHookHandlers::onTitleMoveComplete';
        $wgHooks['BaseTemplateAfterPortlet'][] = 
'\Wikibase\ClientHooks::onBaseTemplateAfterPortlet';
@@ -128,6 +126,11 @@
        $wgHooks['ParserLimitReportPrepare'][] = 
'\Wikibase\Client\Hooks\ParserLimitHookHandlers::onParserLimitReportPrepare';
        $wgHooks['FormatAutocomments'][] = '\Wikibase\ClientHooks::onFormat';
 
+       // recent changes / watchlist hooks
+       $wgHooks['ChangesListSpecialPageFilters'][] = 
'\Wikibase\Client\Hooks\ChangesListSpecialPageFilterHandler::onChangesListSpecialPageFilters';
+       $wgHooks['SpecialWatchlistQuery'][] = 
'\Wikibase\ClientHooks::onSpecialWatchlistQuery';
+       $wgHooks['SpecialRecentChangesQuery'][] = 
'\Wikibase\ClientHooks::onSpecialRecentChangesQuery';
+
        // update hooks
        $wgHooks['LoadExtensionSchemaUpdates'][] = 
'\Wikibase\Client\Usage\Sql\SqlUsageTrackerSchemaUpdater::onSchemaUpdate';
 
diff --git a/client/includes/Hooks/ChangesListSpecialPageFilterHandler.php 
b/client/includes/Hooks/ChangesListSpecialPageFilterHandler.php
new file mode 100644
index 0000000..0b0ecad
--- /dev/null
+++ b/client/includes/Hooks/ChangesListSpecialPageFilterHandler.php
@@ -0,0 +1,164 @@
+<?php
+
+namespace Wikibase\Client\Hooks;
+
+use ChangesListSpecialPage;
+use User;
+use WebRequest;
+use Wikibase\Client\WikibaseClient;
+
+/**
+ * @since 0.5
+ *
+ * @licence GNU GPL v2+
+ * @author Katie Filbert < [email protected] >
+ */
+class ChangesListSpecialPageFilterHandler {
+
+       /**
+        * @var WebRequest
+        */
+       private $request;
+
+       /**
+        * @var User
+        */
+       private $user;
+
+       /**
+        * @var string
+        */
+       private $pageName;
+
+       /**
+        * @var bool
+        */
+       private $showExternalChanges;
+
+       /**
+        * @param WebRequest $request
+        * @param User $user
+        * @param string $pageName
+        * @param bool $showExternalChanges
+        */
+       public function __construct(
+               WebRequest $request,
+               User $user,
+               $pageName,
+               $showExternalChanges
+       ) {
+               $this->request = $request;
+               $this->user = $user;
+               $this->pageName = $pageName;
+               $this->showExternalChanges = $showExternalChanges;
+       }
+
+       /**
+        * @param ChangesListSpecialPage $specialPage
+        *
+        * @return ChangesListSpecialPageFilterHandler
+        */
+       private static function newFromGlobalState(
+               ChangesListSpecialPage $specialPage
+       ) {
+               $context = $specialPage->getContext();
+               $settings = WikibaseClient::getDefaultInstance()->getSettings();
+
+               return new self(
+                       $context->getRequest(),
+                       $context->getUser(),
+                       $specialPage->getName(),
+                       $settings->getSetting( 'showExternalRecentChanges' )
+               );
+       }
+
+       /**
+        * Modifies recent changes and watchlist options to show a toggle for 
Wikibase changes
+        * @see 
https://www.mediawiki.org/wiki/Manual:Hooks/ChangesListSpecialPageFilters
+        *
+        * @param ChangesListSpecialPage $specialPage
+        * @param array &$filters
+        *
+        * @return bool
+        */
+       public static function onChangesListSpecialPageFilters(
+               ChangesListSpecialPage $specialPage,
+               array &$filters
+       ) {
+               $hookHandler = self::newFromGlobalState( $specialPage );
+               $hookHandler->addFilterIfEnabled( $filters );
+
+               return true;
+       }
+
+       /**
+        * @param array &$filters
+        */
+       public function addFilterIfEnabled( array &$filters ) {
+               if ( $this->shouldAddFilter() ) {
+                       // if preference enabled, then Wikibase edits are 
included by default and
+                       // the toggle default value needs to be the inverse to 
hide them, and vice versa.
+                       $toggleDefault = 
!$this->hasShowWikibaseEditsPrefEnabled();
+                       $this->addFilter( $filters, $toggleDefault );
+               }
+       }
+
+       /**
+        * @return bool
+        */
+       private function shouldAddFilter() {
+               return $this->showExternalChanges && 
!$this->isEnhancedChangesEnabled();
+       }
+
+       /**
+        * @param array &$filters
+        * @param bool $toggleDefault
+        */
+       private function addFilter( array &$filters, $toggleDefault ) {
+               $filterName = $this->getFilterName();
+
+               $filters[$filterName] = array(
+                       'msg' => 'wikibase-rc-hide-wikidata',
+                       'default' => $toggleDefault
+               );
+       }
+
+       /**
+        * @return bool
+        */
+       private function hasShowWikibaseEditsPrefEnabled() {
+               return (bool)$this->user->getOption( $this->getOptionName() );
+       }
+
+       /**
+        * @return bool
+        */
+       private function isEnhancedChangesEnabled() {
+               $enhancedChangesUserOption = $this->user->getOption( 'usenewrc' 
);
+
+               return $this->request->getBool( 'enhanced', 
$enhancedChangesUserOption );
+       }
+
+       /**
+        * @return string
+        */
+       private function getFilterName() {
+               if ( $this->pageName === 'Watchlist' ) {
+                       return 'hideWikibase';
+               }
+
+               return 'hidewikidata';
+       }
+
+       /**
+        * @return string
+        */
+       private function getOptionName() {
+               if ( $this->pageName === 'Watchlist' ) {
+                       return 'wlshowwikibase';
+               }
+
+               return 'rcshowwikidata';
+       }
+
+}
diff --git a/client/includes/Hooks/ChangesPageWikibaseFilterHandler.php 
b/client/includes/Hooks/ChangesPageWikibaseFilterHandler.php
deleted file mode 100644
index 45f358b..0000000
--- a/client/includes/Hooks/ChangesPageWikibaseFilterHandler.php
+++ /dev/null
@@ -1,130 +0,0 @@
-<?php
-
-namespace Wikibase\Client\Hooks;
-
-use IContextSource;
-use User;
-
-/**
- * @since 0.5
- *
- * @licence GNU GPL v2+
- * @author Katie Filbert < [email protected] >
- */
-class ChangesPageWikibaseFilterHandler {
-
-       /**
-        * @var IContextSource
-        */
-       private $context;
-
-       /**
-        * @var boolean
-        */
-       private $showExternalChanges;
-
-       /**
-        * @var string
-        */
-       private $filterName;
-
-       /**
-        * @var string
-        */
-       private $optionName;
-
-       /**
-        * @var string
-        */
-       private $toggleMessageKey;
-
-       /**
-        * @param IContextSource $context
-        * @param boolean $showExternalChanges
-        * @param string $filterName - name for Wikibase toggle in FormOptions
-        * @param string $optionName - user option name for showing Wikibase 
edits by default
-        * @param string $toggleMessageKey
-        */
-       public function __construct(
-               IContextSource $context,
-               $showExternalChanges,
-               $filterName,
-               $optionName,
-               $toggleMessageKey
-       ) {
-               $this->context = $context;
-               $this->showExternalChanges = $showExternalChanges;
-               $this->filterName = $filterName;
-               $this->optionName = $optionName;
-               $this->toggleMessageKey = $toggleMessageKey;
-       }
-
-       /**
-        * @param array $filters
-        *
-        * @return array
-        */
-       public function addFilterIfEnabled( array $filters ) {
-               $user = $this->context->getUser();
-
-               if ( !$this->shouldAddFilter( $user ) ) {
-                       return $filters;
-               }
-
-               $toggleDefault = $this->showWikibaseEditsByDefault( $user );
-               $filters = $this->addFilter( $filters, $toggleDefault );
-
-               return $filters;
-       }
-
-       /**
-        * @param User $user
-        *
-        * @return boolean
-        */
-       private function shouldAddFilter( User $user ) {
-               if ( $this->showExternalChanges && 
!$this->isEnhancedChangesEnabled( $user ) ) {
-                       return true;
-               }
-
-               return false;
-       }
-
-       /**
-        * @param array $filters
-        * @param boolean $toggleDefault
-        *
-        * @return array
-        */
-       private function addFilter( array $filters, $toggleDefault ) {
-               $filters["{$this->filterName}"] = array(
-                       'msg' => $this->toggleMessageKey,
-                       'default' => $toggleDefault
-               );
-
-               return $filters;
-       }
-
-       /**
-        * @param User $user
-        *
-        * @return boolean
-        */
-       private function showWikibaseEditsByDefault( User $user ) {
-               return !$user->getOption( $this->optionName );
-       }
-
-       /**
-        * @param User $user
-        *
-        * @return boolean
-        */
-       private function isEnhancedChangesEnabled( User $user ) {
-               $enhancedChangesUserOption = $user->getOption( 'usenewrc' );
-
-               $isEnabled = $this->context->getRequest()->getBool( 'enhanced', 
$enhancedChangesUserOption );
-
-               return $isEnabled;
-       }
-
-}
diff --git 
a/client/tests/phpunit/includes/Hooks/ChangesListSpecialPageFilterHandlerTest.php
 
b/client/tests/phpunit/includes/Hooks/ChangesListSpecialPageFilterHandlerTest.php
new file mode 100644
index 0000000..eb18101
--- /dev/null
+++ 
b/client/tests/phpunit/includes/Hooks/ChangesListSpecialPageFilterHandlerTest.php
@@ -0,0 +1,224 @@
+<?php
+
+namespace Wikibase\Client\Tests\Hooks;
+
+use FauxRequest;
+use Wikibase\Client\Hooks\ChangesListSpecialPageFilterHandler;
+
+/**
+ * @covers Wikibase\Client\Hooks\ChangesListSpecialPageFilterHandler
+ *
+ * @group WikibaseClientHooks
+ * @group WikibaseClient
+ * @group Wikibase
+ */
+class ChangesListSpecialPageFilterHandlerTest extends 
\PHPUnit_Framework_TestCase {
+
+       /**
+        * @dataProvider filterNotAddedWhenUsingEnhancedChangesProvider
+        */
+       public function testFilterNotAddedWhenUsingEnhancedChanges(
+               array $requestParams,
+               array $userPreferences,
+               $pageName,
+               $message
+       ) {
+               $hookHandler = new ChangesListSpecialPageFilterHandler(
+                       $this->getRequest( $requestParams ),
+                       $this->getUser( $userPreferences ),
+                       $pageName,
+                       true
+               );
+
+               $filters = array();
+               $hookHandler->addFilterIfEnabled( $filters );
+
+               $this->assertSame( array(), $filters, $message );
+       }
+
+       public function filterNotAddedWhenUsingEnhancedChangesProvider() {
+               return array(
+                       array(
+                               array(),
+                               array( 'usenewrc' => 1 ),
+                               'Watchlist',
+                               'enhanced default pref for Watchlist'
+                       ),
+                       array(
+                               array(),
+                               array( 'usenewrc' => 1 ),
+                               'RecentChanges',
+                               'enhanced default pref for RecentChanges'
+                       ),
+                       array(
+                               array( 'enhanced' => 1 ),
+                               array( 'usenewrc' => 0 ),
+                               'Watchlist',
+                               'enhanced not default but has enhanced=1 req 
param'
+                       ),
+                       array(
+                               array( 'enhanced' => 1 ),
+                               array( 'usenewrc' => 0 ),
+                               'RecentChanges',
+                               'enhanced not default but has enhanced=1 req 
param'
+                       ),
+                       array(
+                               array( 'enhanced' => 1 ),
+                               array( 'usenewrc' => 1 ),
+                               'Watchlist',
+                               'enhanced default and has enhanced=1 req param'
+                       ),
+                       array(
+                               array( 'enhanced' => 1 ),
+                               array( 'usenewrc' => 1 ),
+                               'RecentChangesLinked',
+                               'enhanced default and has enhanced=1 req param'
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider filterAddedWhenNotUsingEnhancedChangesProvider
+        */
+       public function 
testFilterAddedWhenNotUsingEnhancedChanges_notShowWikibaseEditsByDefault(
+               array $requestParams,
+               array $userPreferences,
+               $expectedFilterName,
+               $specialPageName
+       ) {
+               $hookHandler = new ChangesListSpecialPageFilterHandler(
+                       $this->getRequest( $requestParams ),
+                       $this->getUser( $userPreferences ),
+                       $specialPageName,
+                       true
+               );
+
+               $filters = array();
+               $hookHandler->addFilterIfEnabled( $filters );
+
+               $expected = array(
+                       $expectedFilterName => array(
+                               'msg' => 'wikibase-rc-hide-wikidata',
+                               'default' => true
+                       )
+               );
+
+               $this->assertSame( $expected, $filters );
+       }
+
+       public function filterAddedWhenNotUsingEnhancedChangesProvider() {
+               return array(
+                       array(
+                               array(),
+                               array( 'usenewrc' => 0 ),
+                               'hideWikibase',
+                               'Watchlist'
+                       ),
+                       array(
+                               array( 'enhanced' => 0 ),
+                               array( 'usenewrc' => 1 ),
+                               'hidewikidata',
+                               'RecentChanges'
+                       ),
+                       array(
+                               array(),
+                               array( 'usenewrc' => 0 ),
+                               'hidewikidata',
+                               'RecentChangesLinked'
+                       )
+               );
+       }
+
+       /**
+        * @dataProvider 
filterAddedInNonEnhanced_withPrefToShowWikibaseEditsByDefaultProvider
+        */
+       public function 
testFilterAddedInNonEnhanced_withPrefToShowWikibaseEditsByDefault(
+               array $userPreferences,
+               $expectedFilterName,
+               $specialPageName
+       ) {
+               $hookHandler = new ChangesListSpecialPageFilterHandler(
+                       $this->getRequest( array() ),
+                       $this->getUser( $userPreferences ),
+                       $specialPageName,
+                       true
+               );
+
+               $filters = array();
+               $hookHandler->addFilterIfEnabled( $filters );
+
+               $expected = array(
+                       $expectedFilterName => array(
+                               'msg' => 'wikibase-rc-hide-wikidata',
+                               'default' => false
+                       )
+               );
+
+               $this->assertSame( $expected, $filters );
+       }
+
+       public function 
filterAddedInNonEnhanced_withPrefToShowWikibaseEditsByDefaultProvider() {
+               return array(
+                       array(
+                               array( 'wlshowwikibase' => 1, 'usenewrc' => 0 ),
+                               'hideWikibase',
+                               'Watchlist'
+                       ),
+                       array(
+                               array( 'rcshowwikidata' => 1, 'usenewrc' => 0 ),
+                               'hidewikidata',
+                               'RecentChanges'
+                       )
+               );
+       }
+
+       /**
+        * @dataProvider 
filterNotAddedWhenExternalRecentChangesDisabledProvider() {
+        */
+       public function testFilterNotAddedWhenExternalRecentChangesDisabled( 
$specialPageName ) {
+               $hookHandler = new ChangesListSpecialPageFilterHandler(
+                       $this->getRequest( array() ),
+                       $this->getUser( array( 'usenewrc' => 0 ) ),
+                       $specialPageName,
+                       false
+               );
+
+               $filters = array();
+               $hookHandler->addFilterIfEnabled( $filters );
+
+               $this->assertSame( array(), $filters );
+       }
+
+       public function 
filterNotAddedWhenExternalRecentChangesDisabledProvider() {
+               return array(
+                       array( 'Watchlist' ),
+                       array( 'RecentChanges' ),
+                       array( 'RecentChangesLinked' )
+               );
+       }
+
+       private function getRequest( array $requestParams ) {
+               return new FauxRequest( $requestParams );
+       }
+
+       private function getUser( array $options ) {
+               $user = $this->getMockBuilder( 'User' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $user->expects( $this->any() )
+                       ->method( 'getOption' )
+                       ->will( $this->returnCallback( function( $optionName ) 
use ( $options ) {
+                               foreach ( $options as $key => $value ) {
+                                       if ( $optionName === $key ) {
+                                               return $value;
+                                       }
+                               }
+
+                               return null;
+                       } ) );
+
+               return $user;
+       }
+
+}
diff --git 
a/client/tests/phpunit/includes/Hooks/ChangesPageWikibaseFilterHandlerTest.php 
b/client/tests/phpunit/includes/Hooks/ChangesPageWikibaseFilterHandlerTest.php
deleted file mode 100644
index e557709..0000000
--- 
a/client/tests/phpunit/includes/Hooks/ChangesPageWikibaseFilterHandlerTest.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-
-namespace Wikibase\Client\Tests\Hooks;
-
-use DerivativeContext;
-use FauxRequest;
-use RequestContext;
-use Wikibase\Client\Hooks\ChangesPageWikibaseFilterHandler;
-
-/**
- * @covers Wikibase\Client\Hooks\ChangesPageWikibaseFilterHandler
- *
- * @group WikibaseClientHooks
- * @group WikibaseClient
- * @group Wikibase
- */
-class ChangesPageWikibaseFilterHandlerTest extends \PHPUnit_Framework_TestCase 
{
-
-       /**
-        * @dataProvider filterNotAddedWhenUsingEnhancedChangesProvider
-        */
-       public function testFilterNotAddedWhenUsingEnhancedChanges(
-               $enhancedChangesDefault,
-               $useEnhancedChanges
-       ) {
-               $context = $this->getContext( $enhancedChangesDefault, 
$useEnhancedChanges, false );
-               $hookHandler = new ChangesPageWikibaseFilterHandler( $context, 
true, 'foo', 'bar', 'foobar' );
-
-               $filters = array();
-               $filters = $hookHandler->addFilterIfEnabled( $filters );
-
-               $this->assertEquals( array(), $filters );
-       }
-
-       public function filterNotAddedWhenUsingEnhancedChangesProvider() {
-               return array(
-                       array( true, true, 'enhanced changes default preference 
and using' ),
-                       array( false, true, 'enhanced changes not default but 
using' )
-               );
-       }
-
-       public function testFilterAddedWhenNotUsingEnhancedChanges() {
-               $context = $this->getContext( false, false, true );
-               $hookHandler = new ChangesPageWikibaseFilterHandler( $context, 
true, 'foo', 'bar', 'foobar' );
-
-               $filters = array();
-               $filters = $hookHandler->addFilterIfEnabled( $filters );
-
-               $expected = array(
-                       'foo' => array(
-                               'msg' => 'foobar',
-                               'default' => false
-                       )
-               );
-
-               $this->assertEquals( $expected, $filters );
-       }
-
-       public function 
testFilterAddedAndEnabledByDefault_WhenNotUsingEnhancedChanges() {
-               $context = $this->getContext( false, false, false );
-               $hookHandler = new ChangesPageWikibaseFilterHandler( $context, 
true, 'foo', 'bar', 'foobar' );
-
-               $filters = array();
-               $filters = $hookHandler->addFilterIfEnabled( $filters );
-
-               $expected = array(
-                       'foo' => array(
-                               'msg' => 'foobar',
-                               'default' => true
-                       )
-               );
-
-               $this->assertEquals( $expected, $filters );
-       }
-
-       public function testFilterNotAddedWhenExternalRecentChangesDisabled() {
-               $context = $this->getContext( false, false, false );
-               $hookHandler = new ChangesPageWikibaseFilterHandler( $context, 
false, 'foo', 'bar', 'foobar' );
-
-               $filters = array();
-               $filters = $hookHandler->addFilterIfEnabled( $filters );
-
-               $this->assertEquals( array(), $filters );
-       }
-
-       private function getContext( $enhancedChangesPref, $useEnhanced, 
$hideWikibaseEditsByDefault ) {
-               $context = new DerivativeContext( RequestContext::getMain() );
-               $context->setUser( $this->getUser( $enhancedChangesPref, 
$hideWikibaseEditsByDefault ) );
-
-               $request = new FauxRequest( array( 'enhanced' => $useEnhanced ) 
);
-               $context->setRequest( $request );
-
-               return $context;
-       }
-
-       private function getUser( $enhancedChangesPref, 
$hideWikibaseEditsByDefault ) {
-               $user = $this->getMockBuilder( 'User' )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
-               $user->expects( $this->any() )
-                       ->method( 'getOption' )
-                       ->will( $this->returnCallback( function( $optionName ) 
use (
-                               $enhancedChangesPref,
-                               $hideWikibaseEditsByDefault
-                       ) {
-                               if ( $optionName === 'usenewrc' ) {
-                                       return $enhancedChangesPref;
-                               } else {
-                                       return $hideWikibaseEditsByDefault;
-                               }
-                       } ) );
-
-               return $user;
-       }
-
-}

-- 
To view, visit https://gerrit.wikimedia.org/r/252162
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I66d345e4355accf44f93ce8c6d765c41cebbcc3b
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to