Page MenuHomeWickedGov Phorge

FilterMiddlewareTest.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

FilterMiddlewareTest.php

<?php
namespace MediaWiki\Tests\Notification;
use MediaWiki\Notification\Middleware\FilterMiddleware;
use MediaWiki\Notification\Notification;
use MediaWiki\Notification\NotificationEnvelope;
use MediaWiki\Notification\NotificationsBatch;
use MediaWiki\Notification\RecipientSet;
use MediaWiki\User\UserIdentity;
use MediaWikiUnitTestCase;
/**
* @covers MediaWiki\Notification\Middleware\FilterMiddleware
*/
class FilterMiddlewareTest extends MediaWikiUnitTestCase {
public function testRemovesNotificationTest() {
$sut = $this->getMockForAbstractClass( FilterMiddleware::class );
$sut->expects( $this->any() )
->method( 'filter' )
->willReturnCallback( static function ( NotificationEnvelope $envelope ) {
// remove the one with `remove` or no recipients
return $envelope->getNotification()->getType() !== 'remove' &&
$envelope->getRecipientSet()->count() !== 0;
} );
$notificationA = new Notification( 'first' );
$notificationB = new Notification( 'remove' );
$notificationC = new Notification( 'middle' );
$notificationD = new Notification( 'last' );
$someRecipients = new RecipientSet( [ $this->createMock( UserIdentity::class ) ] );
$emptyRecipients = new RecipientSet( [] );
$batch = new NotificationsBatch(
new NotificationEnvelope( $notificationA, $someRecipients ),
new NotificationEnvelope( $notificationB, $someRecipients ),
new NotificationEnvelope( $notificationC, $someRecipients ),
new NotificationEnvelope( $notificationD, $emptyRecipients )
);
$calledNext = false;
$sut->handle( $batch, static function () use ( &$calledNext ) {
$calledNext = true;
} );
$envelopes = iterator_to_array( $batch );
$this->assertTrue( $calledNext );
$this->assertCount( 2, $envelopes );
$this->assertSame( 'first', $envelopes[0]->getNotification()->getType() );
$this->assertSame( 'middle', $envelopes[1]->getNotification()->getType() );
}
}

File Metadata

Mime Type
text/x-php
Expires
Aug 18 2026, 12:06 (4 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
d7/c5/759d49916a3143ddcf1969e868f6
Default Alt Text
FilterMiddlewareTest.php (1 KB)

Event Timeline