55use Cake \Controller \ComponentRegistry ;
66use Cake \Datasource \FactoryLocator ;
77use Cake \Datasource \Paging \PaginatedResultSet ;
8+ use Cake \Event \EventList ;
9+ use Cake \Event \EventManager ;
810use Cake \Http \Response ;
911use Cake \Http \ServerRequest ;
1012use Cake \Routing \RouteBuilder ;
2022class SerializerTest extends TestCase
2123{
2224 /**
23- * @var string[]
25+ * @inheritdoc
2426 */
2527 public array $ fixtures = [
2628 'plugin.MixerApi/CollectionView.Actors ' ,
@@ -34,6 +36,8 @@ public function setUp(): void
3436
3537 public function test_as_json (): void
3638 {
39+ EventManager::instance ()->trackEvents (true )->setEventList (new EventList ());
40+
3741 $ actor = FactoryLocator::get ('Table ' )->get ('Actors ' );
3842
3943 $ result = new PaginatedResultSet ($ actor ->find ()->limit (1 )->all (), [
@@ -85,6 +89,8 @@ public function test_as_json(): void
8589
8690 $ obj = json_decode ($ json );
8791 $ this ->assertIsObject ($ obj );
92+ $ this ->assertEventFired ('MixerApi.CollectionView.beforeSerialize ' );
93+ $ this ->assertEventFired ('MixerApi.CollectionView.afterSerialize ' );
8894 $ this ->assertEquals (20 , $ obj ->collection ->count );
8995 $ this ->assertEquals (60 , $ obj ->collection ->total );
9096 $ this ->assertEquals ('/ ' , $ obj ->collection ->url );
@@ -93,6 +99,7 @@ public function test_as_json(): void
9399
94100 public function test_as_xml (): void
95101 {
102+ EventManager::instance ()->trackEvents (true )->setEventList (new EventList ());
96103 $ actor = FactoryLocator::get ('Table ' )->get ('Actors ' );
97104
98105 $ result = new PaginatedResultSet ($ actor ->find ()->limit (1 )->all (), [
@@ -142,6 +149,8 @@ public function test_as_xml(): void
142149 $ this ->assertIsString ($ xml );
143150
144151 $ simpleXml = simplexml_load_string ($ xml );
152+ $ this ->assertEventFired ('MixerApi.CollectionView.beforeSerialize ' );
153+ $ this ->assertEventFired ('MixerApi.CollectionView.afterSerialize ' );
145154 $ this ->assertInstanceOf (SimpleXMLElement::class, $ simpleXml );
146155 $ this ->assertEquals ('/ ' , $ simpleXml ->collection ->url );
147156 $ this ->assertInstanceOf (SimpleXMLElement::class, $ simpleXml ->data );
0 commit comments