diff options
author | Piotr Miazga <pmiazga@wikimedia.org> | 2025-03-06 14:48:12 +0100 |
---|---|---|
committer | Piotr Miazga <pmiazga@wikimedia.org> | 2025-03-21 10:50:14 +0100 |
commit | f1e88be974500910c79ad0dd9a2cf4a454d24b4d (patch) | |
tree | 681a41dd81136fb3609b071d2ccce8ad5a436af7 /tests/phpunit/unit/includes/Notification/NotificationServiceTest.php | |
parent | 35bbe148a98cb4f119524cbbf52dd0e96ec0f4dc (diff) | |
download | mediawikicore-f1e88be974500910c79ad0dd9a2cf4a454d24b4d.tar.gz mediawikicore-f1e88be974500910c79ad0dd9a2cf4a454d24b4d.zip |
notifications: Introduce Notification Middleware and NotificationEnvelope
To allow ourselves esier processing/modifying Notifications lets
introduce an idea of NotificationsEnvelope which represents a
Notification being sent and list of recipients.
The middleware approach will allow us to modify the Notification
behaviour by letting extensions to inject/modify the Notifications.
Each Middleware will retrieve a list of Envelopes MediaWiki wants to
send. Middlewares should iterate over envelopes and decide if those
want to add/remove/replace Notifications and/or Recipients.
Bug: T387996
Change-Id: Ib3ee35c75b2f4dcfdc516b9259a852dc73c4a778
Diffstat (limited to 'tests/phpunit/unit/includes/Notification/NotificationServiceTest.php')
-rw-r--r-- | tests/phpunit/unit/includes/Notification/NotificationServiceTest.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/phpunit/unit/includes/Notification/NotificationServiceTest.php b/tests/phpunit/unit/includes/Notification/NotificationServiceTest.php index 242a3ac6f515..e62a1be23e41 100644 --- a/tests/phpunit/unit/includes/Notification/NotificationServiceTest.php +++ b/tests/phpunit/unit/includes/Notification/NotificationServiceTest.php @@ -2,6 +2,7 @@ namespace MediaWiki\Tests\Notification; +use MediaWiki\Notification\MiddlewareChain; use MediaWiki\Notification\Notification; use MediaWiki\Notification\NotificationHandler; use MediaWiki\Notification\NotificationService; @@ -16,6 +17,36 @@ use RuntimeException; */ class NotificationServiceTest extends MediaWikiUnitTestCase { + protected function getEmptyMiddleware() { + $middleware = $this->createMock( MiddlewareChain::class ); + $middleware->expects( $this->any() ) + ->method( 'process' ) + ->willReturnArgument( 0 ); + return $middleware; + } + + public function testTriggersMiddleware() { + $notification = new Notification( 'test.middleware' ); + $recipients = new RecipientSet( [] ); + $middleware = $this->createMock( MiddlewareChain::class ); + $middleware->expects( $this->once() ) + ->method( 'process' ) + ->willReturnCallback( function ( $batch ) { + $envelopes = iterator_to_array( $batch ); + $this->assertCount( 1, $envelopes ); + $this->assertSame( 'test.middleware', $envelopes[0]->getNotification()->getType() ); + return $batch; + } ); + + $svc = new NotificationService( + new NullLogger(), + $this->createSimpleObjectFactory(), + $middleware, + [] + ); + $svc->notify( $notification, $recipients ); + } + public function testBasic() { $recipients = new RecipientSet( [] ); @@ -34,6 +65,7 @@ class NotificationServiceTest extends MediaWikiUnitTestCase { $svc = new NotificationService( new NullLogger(), $this->createSimpleObjectFactory(), + $this->getEmptyMiddleware(), [ [ 'types' => [ 'A' ], 'factory' => static fn () => $handlerA ], [ 'types' => [ '*' ], 'factory' => static fn () => $handlerB ], @@ -56,6 +88,7 @@ class NotificationServiceTest extends MediaWikiUnitTestCase { $svc = new NotificationService( new NullLogger(), $this->createSimpleObjectFactory(), + $this->getEmptyMiddleware(), [ [ 'types' => [ 'A/*' ], 'factory' => static fn () => $handler ], ] @@ -74,6 +107,7 @@ class NotificationServiceTest extends MediaWikiUnitTestCase { $svc = new NotificationService( new NullLogger(), $this->createSimpleObjectFactory(), + $this->getEmptyMiddleware(), [ [ 'types' => [ '*' ], 'factory' => static fn () => $handler ], [ 'types' => [ '*' ], 'factory' => static fn () => $handler ], @@ -93,6 +127,7 @@ class NotificationServiceTest extends MediaWikiUnitTestCase { $svc = new NotificationService( $mockLogger, $this->createSimpleObjectFactory(), + $this->getEmptyMiddleware(), [ [ 'types' => [ 'B' ], 'factory' => static fn () => $handler ], ] |