mediawiki-extensions-Echo/tests/phpunit/BundlerTest.php
Stephane Bisson 24caf50ff6 Dynamic bundles
To allow individual notifications to be
marked as read/unread or moderated,
bundles are created by grouping associated
notifications when they are fetched for display
instead of when they are created.

From a product perspective, this change doesn't
introduce moderation or expandable bundles but
it counts each individual notifications.
For instance, the bundled notification
"3 new topics on PageA" now counts as 3
notifications.

Bug: T93673
Bug: T120153
Change-Id: Iacd098573efd92bb1e3fcd7da4cd40cea9522f15
2016-06-27 09:49:13 -04:00

46 lines
1.6 KiB
PHP

<?php
class BundlerTest extends MediaWikiTestCase {
public function testBundle() {
$read = true;
$unread = false;
$n1 = $this->createNotificationForBundling( 'bundle_hash_1', 'timestamp_4', $read );
$n2 = $this->createNotificationForBundling( 'bundle_hash_1', 'timestamp_1', $read );
$n3 = $this->createNotificationForBundling( 'bundle_hash_2', 'timestamp_3', $unread );
$n4 = $this->createNotificationForBundling( 'bundle_hash_2', 'timestamp_2', $unread );
$n5 = $this->createNotificationForBundling( 'bundle_hash_2', 'timestamp_5', $read );
$notifications = array( $n1, $n2, $n3, $n4, $n5 );
$bundler = new Bundler();
$bundledNotifications = $bundler->bundle( $notifications );
$this->assertCount( 4, $bundledNotifications );
$this->assertSame( $n5, $bundledNotifications[0] );
$this->assertSame( $n1, $bundledNotifications[1] );
$this->assertSame( $n3, $bundledNotifications[2] );
$this->assertCount( 1, $bundledNotifications[2]->getBundledNotifications() );
$this->assertSame( $n4, $bundledNotifications[2]->getBundledNotifications()[0] );
$this->assertSame( $n2, $bundledNotifications[3] );
}
private function createNotificationForBundling( $bundleHash, $timestamp, $readStatus ) {
$mock = $this->getMockBuilder( 'EchoNotification' )
->disableOriginalConstructor()
->setMethods( array(
'getBundlingKey',
'getSortingKey',
'canBeBundled',
) )
->getMock();
$mock->method( 'getBundlingKey' )->willReturn( $bundleHash );
$mock->method( 'getSortingKey' )->willReturn( $timestamp );
$mock->method( 'canBeBundled' )->willReturn( !$readStatus );
return $mock;
}
}