Matěj Suchánek has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/352130 )

Change subject: Simplify EchoNotificationsHandlersTestCase with a provider
......................................................................

Simplify EchoNotificationsHandlersTestCase with a provider

Change-Id: If4bf00cc7164a679ef4fe9a3491804065c867998
---
M client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php
1 file changed, 33 insertions(+), 49 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/30/352130/1

diff --git 
a/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php 
b/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php
index 337b814..1703108 100644
--- a/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php
+++ b/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php
@@ -158,63 +158,47 @@
                );
        }
 
-       public function testBeforeCreateEchoEvent() {
-               $settings = new SettingsArray();
-               $settings->setSetting( 'siteGlobalID', 'enwiki' );
-               $settings->setSetting( 'sendEchoNotification', false );
-               $settings->setSetting( 'echoIcon', false );
+       public function beforeCreateEchoEventProvider() {
+               return [
+                       'no registration' => [],
+                       'registered with custome icon' => [
+                               'register' => true,
+                               'icon' => [ 'url' => 'some_url_here' ],
+                               'expectedIcon' => [ 'url' => 'some_url_here' ],
+                       ],
+                       'registered with default icon' => [
+                               'register' => true,
+                               'icon' => false,
+                               'expectedIcon' => [ 'path' => 
'Wikibase/client/includes/Hooks/../../resources/images/echoIcon.svg' ],
+                       ]
+               ];
+       }
 
+       /**
+        * @dataProvider beforeCreateEchoEventProvider
+        */
+       public function testBeforeCreateEchoEvent( $register = false, $icon = 
false, $expectedIcon = false ) {
                $notifications = [];
                $categories = [];
                $icons = [];
 
-               $handlers = $this->getHandlers( $settings );
+               $handlers = new EchoNotificationsHandlers(
+                       $this->repoLinker,
+                       'enwiki',
+                       $register,
+                       $icon,
+                       'repoSiteName'
+               );
+
                $handlers->doBeforeCreateEchoEvent( $notifications, 
$categories, $icons );
 
-               $this->assertFalse(
-                       isset( $notifications[$handlers::NOTIFICATION_TYPE] ),
-                       "Failed asserting that the notification type is 
registered to Echo"
-               );
+               $this->assertSame( $register, isset( 
$notifications[$handlers::NOTIFICATION_TYPE] ) );
+               $this->assertSame( $register, isset( 
$categories['wikibase-action'] ) );
+               $this->assertSame( $register, isset( 
$icons[$handlers::NOTIFICATION_TYPE] ) );
 
-               $settings->setSetting( 'sendEchoNotification', true );
-               $handlers = $this->getHandlers( $settings );
-               $handlers->doBeforeCreateEchoEvent( $notifications, 
$categories, $icons );
-
-               $this->assertArrayHasKey(
-                       $handlers::NOTIFICATION_TYPE,
-                       $notifications,
-                       "Failed asserting that the notification type is 
registered to Echo"
-               );
-               $this->assertArrayHasKey(
-                       'wikibase-action',
-                       $categories,
-                       "Failed asserting that the notification category is 
registered to Echo"
-               );
-               $this->assertArrayHasKey(
-                       $handlers::NOTIFICATION_TYPE,
-                       $icons,
-                       "Failed asserting that the notification icon is 
registered to Echo"
-               );
-               $this->assertEquals(
-                       [ 'path' => 
'Wikibase/client/includes/Hooks/../../resources/images/echoIcon.svg' ],
-                       $icons[$handlers::NOTIFICATION_TYPE],
-                       "Failed asserting that missing echoIcon setting 
defaults to Echo's default"
-               );
-
-               $notifications = [];
-               $categories = [];
-               $icons = [];
-
-               $echoIcon = [ 'url' => 'some_url_here' ];
-               $settings->setSetting( 'echoIcon', $echoIcon );
-               $handlers = $this->getHandlers( $settings );
-
-               $handlers->doBeforeCreateEchoEvent( $notifications, 
$categories, $icons );
-               $this->assertEquals(
-                       $echoIcon,
-                       $icons[$handlers::NOTIFICATION_TYPE],
-                       "Failed asserting that the notification icon is 
correctly registered to Echo"
-               );
+               if ( $register ) {
+                       $this->assertSame( $expectedIcon, 
$icons[$handlers::NOTIFICATION_TYPE] );
+               }
        }
 
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If4bf00cc7164a679ef4fe9a3491804065c867998
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Matěj Suchánek <matejsuchane...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to