@@ -56,6 +56,7 @@ public function testDoesNothingWhenMediaTypeIsSupported(): void
5656 $ request = new Request ();
5757 $ request ->attributes ->set ('supported_media_types ' , ['json ' , 'xml ' ]);
5858 $ request ->headers = new HeaderBag ([
59+ 'Content-Type ' => 'application/vnd.ibexa.api.ContentCreate+json ' ,
5960 'Accept ' => 'application/vnd.ibexa.api.ContentCreate+json ' ,
6061 ]);
6162
@@ -72,6 +73,7 @@ public function testThrowsExceptionWhenHeaderTypeIsNotSupported(): void
7273 $ request = new Request ();
7374 $ request ->attributes ->set ('supported_media_types ' , ['json ' ]);
7475 $ request ->headers = new HeaderBag ([
76+ 'Content-Type ' => 'application/vnd.ibexa.api.ContentCreate+xml ' ,
7577 'Accept ' => 'application/vnd.ibexa.api.ContentCreate+xml ' ,
7678 ]);
7779
@@ -87,6 +89,7 @@ public function testThrowsExceptionWhenUnknownMediaTypeIsUsed(): void
8789 $ request = new Request ();
8890 $ request ->attributes ->set ('supported_media_types ' , ['yaml ' ]);
8991 $ request ->headers = new HeaderBag ([
92+ 'Content-Type ' => 'application/vnd.ibexa.api.ContentCreate+unknown ' ,
9093 'Accept ' => 'application/vnd.ibexa.api.ContentCreate+unknown ' ,
9194 ]);
9295
@@ -97,11 +100,28 @@ public function testThrowsExceptionWhenUnknownMediaTypeIsUsed(): void
97100 $ subscriber ->allowOnlySupportedMediaTypes ($ event );
98101 }
99102
103+ public function testThrowsExceptionWhenDifferentMediaTypesInHeadersAreUsed (): void
104+ {
105+ $ request = new Request ();
106+ $ request ->attributes ->set ('supported_media_types ' , ['json ' ]);
107+ $ request ->headers = new HeaderBag ([
108+ 'Content-Type ' => 'application/vnd.ibexa.api.ContentCreate+json ' ,
109+ 'Accept ' => 'application/vnd.ibexa.api.ContentCreate+xml ' ,
110+ ]);
111+
112+ $ subscriber = new SupportedMediaTypesSubscriber ();
113+ $ event = new RequestEvent ($ this ->kernel , $ request , HttpKernelInterface::MAIN_REQUEST );
114+
115+ $ this ->expectException (UnsupportedMediaTypeHttpException::class);
116+ $ subscriber ->allowOnlySupportedMediaTypes ($ event );
117+ }
118+
100119 public function testApplicationJsonHeaderIsSupported (): void
101120 {
102121 $ request = new Request ();
103122 $ request ->attributes ->set ('supported_media_types ' , ['json ' ]);
104123 $ request ->headers = new HeaderBag ([
124+ 'Content-Type ' => 'application/json ' ,
105125 'Accept ' => 'application/json ' ,
106126 ]);
107127
0 commit comments