diff options
author | daniel <dkinzler@wikimedia.org> | 2025-01-07 17:30:38 +0100 |
---|---|---|
committer | Aaron Schulz <aschulz@wikimedia.org> | 2025-01-21 16:55:03 +0000 |
commit | 75dec01ee48e94e2013827fee4d2d02534af8b2a (patch) | |
tree | 479eab7870fb1639d49340f7d1cc9f75a0b8fde3 /tests | |
parent | 54989cd56e5de0c1d1d8bcf2efadd2032bf6f995 (diff) | |
download | mediawikicore-75dec01ee48e94e2013827fee4d2d02534af8b2a.tar.gz mediawikicore-75dec01ee48e94e2013827fee4d2d02534af8b2a.zip |
DomainEvent: Support type hierarchies
Why:
- It's useful to be able to listen to sets of compatible event types.
What:
- Make DomainEvents aware of a list of types they are compatible with.
- Make EventDispatchEngine dispatch to all compatible listeners,
registered for any of the supported types.
- Move all page events to their own namespace
Bug: T384330
Change-Id: I96bde2cfaf198e409a6ef3a24101ee7d02d57959
Diffstat (limited to 'tests')
6 files changed, 28 insertions, 5 deletions
diff --git a/tests/api-testing/REST/content.v1/Creation.js b/tests/api-testing/REST/content.v1/Creation.js index e609056198fc..bfc1196eb2a8 100644 --- a/tests/api-testing/REST/content.v1/Creation.js +++ b/tests/api-testing/REST/content.v1/Creation.js @@ -25,7 +25,7 @@ describe( 'POST /page', () => { const specPath = '/specs/v0/module' + specModule; const { status, text } = await client.get( specPath ); - assert.deepEqual( status, 200 ); + assert.deepEqual( status, 200, text ); openApiSpec = JSON.parse( text ); chai.use( chaiResponseValidator( openApiSpec ) ); diff --git a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php index 917490d88272..af2b91001fa3 100644 --- a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php +++ b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php @@ -20,6 +20,7 @@ use MediaWiki\Deferred\MWCallableUpdate; use MediaWiki\Edit\ParsoidRenderID; use MediaWiki\MainConfigNames; use MediaWiki\Message\Message; +use MediaWiki\Page\Event\PageUpdatedEvent; use MediaWiki\Page\PageIdentity; use MediaWiki\Page\PageIdentityValue; use MediaWiki\Page\ParserOutputAccess; @@ -32,7 +33,6 @@ use MediaWiki\Revision\SlotRecord; use MediaWiki\Storage\DerivedPageDataUpdater; use MediaWiki\Storage\EditResult; use MediaWiki\Storage\EditResultCache; -use MediaWiki\Storage\PageUpdatedEvent; use MediaWiki\Storage\RevisionSlotsUpdate; use MediaWiki\Title\Title; use MediaWiki\User\User; diff --git a/tests/phpunit/includes/import/ImportableOldRevisionImporterTest.php b/tests/phpunit/includes/import/ImportableOldRevisionImporterTest.php index ab127c7604f1..7e7c530a2ef7 100644 --- a/tests/phpunit/includes/import/ImportableOldRevisionImporterTest.php +++ b/tests/phpunit/includes/import/ImportableOldRevisionImporterTest.php @@ -1,8 +1,8 @@ <?php use MediaWiki\Content\ContentHandler; +use MediaWiki\Page\Event\PageUpdatedEvent; use MediaWiki\Revision\SlotRecord; -use MediaWiki\Storage\PageUpdatedEvent; use MediaWiki\Tests\Language\LanguageEventIngressSpyTrait; use MediaWiki\Tests\recentchanges\ChangeTrackingEventIngressSpyTrait; use MediaWiki\Tests\Search\SearchEventIngressSpyTrait; diff --git a/tests/phpunit/includes/page/MovePageTest.php b/tests/phpunit/includes/page/MovePageTest.php index 7d0616492cb8..21e451a61620 100644 --- a/tests/phpunit/includes/page/MovePageTest.php +++ b/tests/phpunit/includes/page/MovePageTest.php @@ -5,10 +5,10 @@ use MediaWiki\Content\WikitextContent; use MediaWiki\Interwiki\InterwikiLookup; use MediaWiki\MainConfigNames; use MediaWiki\MediaWikiServices; +use MediaWiki\Page\Event\PageUpdatedEvent; use MediaWiki\Page\MovePage; use MediaWiki\Revision\RevisionRecord; use MediaWiki\Revision\SlotRecord; -use MediaWiki\Storage\PageUpdatedEvent; use MediaWiki\Tests\Language\LanguageEventIngressSpyTrait; use MediaWiki\Tests\recentchanges\ChangeTrackingEventIngressSpyTrait; use MediaWiki\Tests\Rest\Handler\MediaTestTrait; diff --git a/tests/phpunit/includes/page/UndeletePageTest.php b/tests/phpunit/includes/page/UndeletePageTest.php index c631df196d0b..69dedf59a24f 100644 --- a/tests/phpunit/includes/page/UndeletePageTest.php +++ b/tests/phpunit/includes/page/UndeletePageTest.php @@ -2,10 +2,10 @@ use MediaWiki\CommentStore\CommentStoreComment; use MediaWiki\Content\ContentHandler; +use MediaWiki\Page\Event\PageUpdatedEvent; use MediaWiki\Page\PageIdentityValue; use MediaWiki\Page\UndeletePage; use MediaWiki\Revision\SlotRecord; -use MediaWiki\Storage\PageUpdatedEvent; use MediaWiki\Tests\Language\LanguageEventIngressSpyTrait; use MediaWiki\Tests\recentchanges\ChangeTrackingEventIngressSpyTrait; use MediaWiki\Tests\Search\SearchEventIngressSpyTrait; diff --git a/tests/phpunit/unit/includes/DomainEvent/EventDispatchEngineTest.php b/tests/phpunit/unit/includes/DomainEvent/EventDispatchEngineTest.php index a312f98cd748..e9f28a421d98 100644 --- a/tests/phpunit/unit/includes/DomainEvent/EventDispatchEngineTest.php +++ b/tests/phpunit/unit/includes/DomainEvent/EventDispatchEngineTest.php @@ -21,6 +21,10 @@ class EventDispatchEngineTest extends MediaWikiUnitTestCase { private function newEvent( string $type ): DomainEvent { return new class ( $type ) extends DomainEvent { + public function __construct( string $type ) { + parent::__construct(); + $this->declareEventType( $type ); + } }; } @@ -93,6 +97,25 @@ class EventDispatchEngineTest extends MediaWikiUnitTestCase { $this->assertSame( 2, $callCount, 'Listener should have been called' ); } + public function testWildcardListener() { + $engine = $this->newDispatchEngine(); + $conProv = $this->newConnectionProvider(); + + $callCount = 0; + $engine->registerListener( + DomainEvent::ANY, // register for any event + static function () use ( &$callCount ) { + $callCount++; + }, + [ DomainEventSource::INVOCATION_MODE => DomainEventSource::INVOKE_BEFORE_COMMIT ] + ); + + $engine->dispatch( $this->newEvent( 'Tested1' ), $conProv ); + $engine->dispatch( $this->newEvent( 'Tested2' ), $conProv ); + + $this->assertSame( 2, $callCount, 'Listener should have been called' ); + } + public function testRollback() { $engine = $this->newDispatchEngine(); |