summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Echo/tests/phpunit/AttributeManagerTest.php')
-rw-r--r--Echo/tests/phpunit/AttributeManagerTest.php90
1 files changed, 67 insertions, 23 deletions
diff --git a/Echo/tests/phpunit/AttributeManagerTest.php b/Echo/tests/phpunit/AttributeManagerTest.php
index 42ccb992..856c51c7 100644
--- a/Echo/tests/phpunit/AttributeManagerTest.php
+++ b/Echo/tests/phpunit/AttributeManagerTest.php
@@ -1,12 +1,12 @@
<?php
/**
- * @covers EchoAttributeManager
+ * @covers \EchoAttributeManager
*/
class EchoAttributeManagerTest extends MediaWikiTestCase {
public function testNewFromGlobalVars() {
- $this->assertInstanceOf( 'EchoAttributeManager', EchoAttributeManager::newFromGlobalVars() );
+ $this->assertInstanceOf( EchoAttributeManager::class, EchoAttributeManager::newFromGlobalVars() );
}
public static function getUserLocatorsProvider() {
@@ -139,10 +139,10 @@ class EchoAttributeManagerTest extends MediaWikiTestCase {
'category_four' => []
];
$manager = new EchoAttributeManager( $notif, $category, [], [] );
- $this->assertEquals( 6, $manager->getCategoryPriority( 'category_one' ) );
- $this->assertEquals( 10, $manager->getCategoryPriority( 'category_two' ) );
- $this->assertEquals( 10, $manager->getCategoryPriority( 'category_three' ) );
- $this->assertEquals( 10, $manager->getCategoryPriority( 'category_four' ) );
+ $this->assertSame( 6, $manager->getCategoryPriority( 'category_one' ) );
+ $this->assertSame( 10, $manager->getCategoryPriority( 'category_two' ) );
+ $this->assertSame( 10, $manager->getCategoryPriority( 'category_three' ) );
+ $this->assertSame( 10, $manager->getCategoryPriority( 'category_four' ) );
}
public function testGetNotificationPriority() {
@@ -173,10 +173,10 @@ class EchoAttributeManagerTest extends MediaWikiTestCase {
'category_four' => []
];
$manager = new EchoAttributeManager( $notif, $category, [], [] );
- $this->assertEquals( 6, $manager->getNotificationPriority( 'event_one' ) );
- $this->assertEquals( 10, $manager->getNotificationPriority( 'event_two' ) );
- $this->assertEquals( 10, $manager->getNotificationPriority( 'event_three' ) );
- $this->assertEquals( 10, $manager->getNotificationPriority( 'event_four' ) );
+ $this->assertSame( 6, $manager->getNotificationPriority( 'event_one' ) );
+ $this->assertSame( 10, $manager->getNotificationPriority( 'event_two' ) );
+ $this->assertSame( 10, $manager->getNotificationPriority( 'event_three' ) );
+ $this->assertSame( 10, $manager->getNotificationPriority( 'event_four' ) );
}
public static function getEventsForSectionProvider() {
@@ -240,6 +240,9 @@ class EchoAttributeManagerTest extends MediaWikiTestCase {
'event_three' => [
'category' => 'category_three'
],
+ 'event_four' => [
+ 'category' => 'category_four'
+ ]
];
$category = [
'category_one' => [
@@ -257,10 +260,30 @@ class EchoAttributeManagerTest extends MediaWikiTestCase {
'category_three' => [
'priority' => 10,
],
+ 'category_four' => [
+ 'priority' => 10,
+ ]
];
- $manager = new EchoAttributeManager( $notif, $category, [], [] );
- $this->assertEquals( $manager->getUserEnabledEvents( $this->mockUser(), 'web' ),
- [ 'event_two', 'event_three' ] );
+ $defaultNotifyTypeAvailability = [
+ 'web' => true,
+ 'email' => true,
+ ];
+ $notifyTypeAvailabilityByCategory = [
+ 'category_three' => [
+ 'web' => false,
+ 'email' => true,
+ ]
+ ];
+ $manager = new EchoAttributeManager(
+ $notif,
+ $category,
+ $defaultNotifyTypeAvailability,
+ $notifyTypeAvailabilityByCategory
+ );
+ $this->assertEquals(
+ [ 'event_two', 'event_four' ],
+ $manager->getUserEnabledEvents( $this->mockUser(), 'web' )
+ );
}
public function testGetUserEnabledEventsbySections() {
@@ -279,6 +302,9 @@ class EchoAttributeManagerTest extends MediaWikiTestCase {
'event_four' => [
'category' => 'category_three',
],
+ 'event_five' => [
+ 'category' => 'category_five'
+ ]
];
$category = [
'category_one' => [
@@ -290,26 +316,44 @@ class EchoAttributeManagerTest extends MediaWikiTestCase {
'category_three' => [
'priority' => 10
],
+ 'category_five' => [
+ 'priority' => 10
+ ]
];
- $manager = new EchoAttributeManager( $notif, $category, [], [] );
+ $defaultNotifyTypeAvailability = [
+ 'web' => true,
+ 'email' => true,
+ ];
+ $notifyTypeAvailabilityByCategory = [
+ 'category_five' => [
+ 'web' => false,
+ 'email' => true,
+ ]
+ ];
+ $manager = new EchoAttributeManager(
+ $notif,
+ $category,
+ $defaultNotifyTypeAvailability,
+ $notifyTypeAvailabilityByCategory
+ );
$expected = [ 'event_one', 'event_three', 'event_four' ];
- $actual = $manager->getUserEnabledEventsBySections( $this->mockUser(), 'web', [ 'alert' ] );
+ $actual = $manager->getUserEnabledEventsbySections( $this->mockUser(), 'web', [ 'alert' ] );
sort( $expected );
sort( $actual );
- $this->assertEquals( $actual, $expected );
+ $this->assertEquals( $expected, $actual );
$expected = [ 'event_two' ];
- $actual = $manager->getUserEnabledEventsBySections( $this->mockUser(), 'web', [ 'message' ] );
+ $actual = $manager->getUserEnabledEventsbySections( $this->mockUser(), 'web', [ 'message' ] );
sort( $expected );
sort( $actual );
- $this->assertEquals( $actual, $expected );
+ $this->assertEquals( $expected, $actual );
$expected = [ 'event_one', 'event_two', 'event_three', 'event_four' ];
- $actual = $manager->getUserEnabledEventsBySections( $this->mockUser(), 'web',
+ $actual = $manager->getUserEnabledEventsbySections( $this->mockUser(), 'web',
[ 'message', 'alert' ] );
sort( $expected );
sort( $actual );
- $this->assertEquals( $actual, $expected );
+ $this->assertEquals( $expected, $actual );
}
public static function getEventsByCategoryProvider() {
@@ -406,8 +450,8 @@ class EchoAttributeManagerTest extends MediaWikiTestCase {
}
/**
- @dataProvider isNotifyTypeAvailableForCategoryProvider
- */
+ * @dataProvider isNotifyTypeAvailableForCategoryProvider
+ */
public function testIsNotifyTypeAvailableForCategory(
$message,
$expected,
@@ -479,7 +523,7 @@ class EchoAttributeManagerTest extends MediaWikiTestCase {
* Mock object of User
*/
protected function mockUser() {
- $user = $this->getMockBuilder( 'User' )
+ $user = $this->getMockBuilder( User::class )
->disableOriginalConstructor()
->getMock();
$user->expects( $this->any() )