diff --git a/includes/AttributeManager.php b/includes/AttributeManager.php index e4d14c055..20c7156fb 100644 --- a/includes/AttributeManager.php +++ b/includes/AttributeManager.php @@ -358,12 +358,11 @@ class EchoAttributeManager { /** * Get notification section for a notification type - * @todo add a unit test case * @param string $notificationType * @return string */ public function getNotificationSection( $notificationType ) { - return $this->notifications[$notificationType]['section'] ?? 'alert'; + return $this->notifications[$notificationType]['section'] ?? self::$DEFAULT_SECTION; } /** diff --git a/tests/phpunit/unit/AttributeManagerTest.php b/tests/phpunit/unit/AttributeManagerTest.php index 3d138b06a..29a7f5846 100644 --- a/tests/phpunit/unit/AttributeManagerTest.php +++ b/tests/phpunit/unit/AttributeManagerTest.php @@ -32,6 +32,13 @@ class EchoAttributeManagerTest extends MediaWikiUnitTestCase { ); } + /** + * @return UserIdentity + */ + protected function getUser(): UserIdentity { + return new UserIdentityValue( 1, 'ExampleUserName' ); + } + public static function getUserLocatorsProvider() { return [ [ @@ -546,10 +553,28 @@ class EchoAttributeManagerTest extends MediaWikiUnitTestCase { $this->assertEquals( $expected, $actual, $message ); } - /** - * @return UserIdentity - */ - protected function getUser() { - return new UserIdentityValue( 1, 'ExampleUserName' ); + public function getNotificationSectionProvider() { + yield [ 'event_one', 'alert' ]; + yield [ 'event_two', 'message' ]; + yield [ 'event_three', 'alert' ]; + yield [ 'event_undefined', 'alert' ]; } + + /** + * @dataProvider getNotificationSectionProvider + */ + public function testGetNotificationSection( $type, $expected ) { + $am = $this->getAttributeManager( [ + 'event_one' => [ + 'section' => 'alert', + ], + 'event_two' => [ + 'section' => 'message', + ], + 'event_three' => [], + ] ); + $actual = $am->getNotificationSection( $type ); + $this->assertSame( $expected, $actual ); + } + }