mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-28 17:50:39 +00:00
aaf061c725
The following sniffs are failing and were disabled: * MediaWiki.Commenting.FunctionComment.ExtraParamComment * MediaWiki.Commenting.FunctionComment.MissingParamComment * MediaWiki.Commenting.FunctionComment.MissingParamName * MediaWiki.Commenting.FunctionComment.MissingParamTag * MediaWiki.Commenting.FunctionComment.MissingReturn * MediaWiki.Commenting.FunctionComment.ParamNameNoMatch * MediaWiki.Commenting.FunctionComment.WrongStyle * MediaWiki.FunctionComment.Missing.Protected * MediaWiki.FunctionComment.Missing.Public * MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName * MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment Change-Id: I8401abf121a7413fa191d7bc535e0ddd6cf8c3f7
45 lines
1.6 KiB
PHP
45 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 = [ $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( [
|
|
'getBundlingKey',
|
|
'getSortingKey',
|
|
'canBeBundled',
|
|
] )
|
|
->getMock();
|
|
|
|
$mock->method( 'getBundlingKey' )->willReturn( $bundleHash );
|
|
$mock->method( 'getSortingKey' )->willReturn( $timestamp );
|
|
$mock->method( 'canBeBundled' )->willReturn( !$readStatus );
|
|
|
|
return $mock;
|
|
}
|
|
|
|
}
|