2016-03-04 19:23:02 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Model\Notification;
|
|
|
|
|
2018-01-24 00:31:53 +00:00
|
|
|
/**
|
2019-10-23 10:23:09 +00:00
|
|
|
* @covers \Bundler
|
2018-01-24 00:31:53 +00:00
|
|
|
*/
|
2019-07-10 20:47:28 +00:00
|
|
|
class BundlerTest extends MediaWikiUnitTestCase {
|
2016-03-04 19:23:02 +00:00
|
|
|
|
|
|
|
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 );
|
2016-12-05 18:51:07 +00:00
|
|
|
$notifications = [ $n1, $n2, $n3, $n4, $n5 ];
|
2016-03-04 19:23:02 +00:00
|
|
|
|
|
|
|
$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 ) {
|
2022-11-02 21:34:17 +00:00
|
|
|
$mock = $this->getMockBuilder( Notification::class )
|
2016-03-04 19:23:02 +00:00
|
|
|
->disableOriginalConstructor()
|
2021-05-03 07:28:02 +00:00
|
|
|
->onlyMethods( [
|
2016-03-04 19:23:02 +00:00
|
|
|
'getBundlingKey',
|
|
|
|
'getSortingKey',
|
|
|
|
'canBeBundled',
|
2016-12-05 18:51:07 +00:00
|
|
|
] )
|
2016-03-04 19:23:02 +00:00
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$mock->method( 'getBundlingKey' )->willReturn( $bundleHash );
|
|
|
|
$mock->method( 'getSortingKey' )->willReturn( $timestamp );
|
|
|
|
$mock->method( 'canBeBundled' )->willReturn( !$readStatus );
|
|
|
|
|
|
|
|
return $mock;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|