@@ -28,49 +28,32 @@ class WebDebugToolbarListenerTest extends TestCase
28
28
/**
29
29
* @dataProvider getInjectToolbarTests
30
30
*/
31
- public function testInjectToolbar (Response $ response , string $ expected )
31
+ public function testInjectToolbar (string $ content , string $ expected )
32
32
{
33
33
$ listener = new WebDebugToolbarListener ($ this ->getTwigMock ());
34
34
$ m = new \ReflectionMethod ($ listener , 'injectToolbar ' );
35
35
36
+ $ response = new Response ($ content );
37
+
36
38
$ m ->invoke ($ listener , $ response , Request::create ('/ ' ), ['csp_script_nonce ' => 'scripto ' , 'csp_style_nonce ' => 'stylo ' ]);
37
39
$ this ->assertEquals ($ expected , $ response ->getContent ());
38
40
}
39
41
40
42
public static function getInjectToolbarTests ()
41
43
{
42
44
return [
43
- [new Response ( '<html><head></head><body></body></html> ' ) , "<html><head></head><body> \nWDT \n</body></html> " ],
44
- [new Response ( '<html>
45
+ ['<html><head></head><body></body></html> ' , "<html><head></head><body> \nWDT \n</body></html> " ],
46
+ ['<html>
45
47
<head></head>
46
48
<body>
47
49
<textarea><html><head></head><body></body></html></textarea>
48
50
</body>
49
- </html> ') , "<html>
51
+ </html> ' , "<html>
50
52
<head></head>
51
53
<body>
52
54
<textarea><html><head></head><body></body></html></textarea>
53
55
\nWDT \n</body>
54
56
</html> " ],
55
- [
56
- MockedStreamedResponse::createFromContent ('<html><head></head><body></body></html> ' ),
57
- '<html><head></head><body>WDT</body></html> ' ,
58
- ],
59
- [
60
- MockedStreamedResponse::createFromContent (
61
- '<html>
62
- <head></head>
63
- <body>
64
- <textarea><html><head></head><body></body></html></textarea>
65
- </body>
66
- </html> ' ),
67
- '<html>
68
- <head></head>
69
- <body>
70
- <textarea><html><head></head><body></body></html></textarea>
71
- WDT</body>
72
- </html> ' ,
73
- ],
74
57
];
75
58
}
76
59
@@ -92,7 +75,7 @@ public function testHtmlRedirectionIsIntercepted(int $statusCode)
92
75
93
76
public function testNonHtmlRedirectionIsNotIntercepted ()
94
77
{
95
- $ response = new Response ('Some content ' , ' 301 ' );
78
+ $ response = new Response ('Some content ' , 301 );
96
79
$ response ->headers ->set ('X-Debug-Token ' , 'xxxxxxxx ' );
97
80
$ event = new ResponseEvent ($ this ->createMock (Kernel::class), new Request ([], [], ['_format ' => 'json ' ]), HttpKernelInterface::MAIN_REQUEST , $ response );
98
81
@@ -103,77 +86,49 @@ public function testNonHtmlRedirectionIsNotIntercepted()
103
86
$ this ->assertEquals ('Some content ' , $ response ->getContent ());
104
87
}
105
88
106
- /**
107
- * @dataProvider provideInjectedResponse
108
- */
109
- public function testToolbarIsInjected (Response $ response , string $ expected )
89
+ public function testToolbarIsInjected ()
110
90
{
91
+ $ response = new Response ('<html><head></head><body></body></html> ' );
111
92
$ response ->headers ->set ('X-Debug-Token ' , 'xxxxxxxx ' );
112
93
113
94
$ event = new ResponseEvent ($ this ->createMock (Kernel::class), new Request (), HttpKernelInterface::MAIN_REQUEST , $ response );
114
95
115
96
$ listener = new WebDebugToolbarListener ($ this ->getTwigMock ());
116
97
$ listener ->onKernelResponse ($ event );
117
98
118
- $ this ->assertEquals ($ expected , $ response ->getContent ());
119
- }
120
-
121
- public static function provideInjectedResponse (): array
122
- {
123
- return [
124
- [new Response ('<html><head></head><body></body></html> ' ), "<html><head></head><body> \nWDT \n</body></html> " ],
125
- [MockedStreamedResponse::createFromContent ('<html><head></head><body></body></html> ' ), '<html><head></head><body>WDT</body></html> ' ],
126
- ];
127
- }
128
-
129
- public static function provideNotInjectedResponse (): array
130
- {
131
- return [
132
- [new Response ('<html><head></head><body></body></html> ' ), '<html><head></head><body></body></html> ' ],
133
- [MockedStreamedResponse::createFromContent ('<html><head></head><body></body></html> ' ), '<html><head></head><body></body></html> ' ],
134
- ];
135
- }
136
-
137
- public static function provideEmptyResponse (): array
138
- {
139
- return [
140
- [new Response ()],
141
- [MockedStreamedResponse::createFromContent ()],
142
- ];
99
+ $ this ->assertEquals ("<html><head></head><body> \nWDT \n</body></html> " , $ response ->getContent ());
143
100
}
144
101
145
102
/**
146
103
* @depends testToolbarIsInjected
147
- *
148
- * @dataProvider provideNotInjectedResponse
149
104
*/
150
- public function testToolbarIsNotInjectedOnNonHtmlContentType (Response $ response , string $ expected )
105
+ public function testToolbarIsNotInjectedOnNonHtmlContentType ()
151
106
{
107
+ $ response = new Response ('<html><head></head><body></body></html> ' );
152
108
$ response ->headers ->set ('X-Debug-Token ' , 'xxxxxxxx ' );
153
109
$ response ->headers ->set ('Content-Type ' , 'text/xml ' );
154
110
$ event = new ResponseEvent ($ this ->createMock (Kernel::class), new Request (), HttpKernelInterface::MAIN_REQUEST , $ response );
155
111
156
112
$ listener = new WebDebugToolbarListener ($ this ->getTwigMock ());
157
113
$ listener ->onKernelResponse ($ event );
158
114
159
- $ this ->assertEquals ($ expected , $ response ->getContent ());
115
+ $ this ->assertEquals (' <html><head></head><body></body></html> ' , $ response ->getContent ());
160
116
}
161
117
162
118
/**
163
119
* @depends testToolbarIsInjected
164
- *
165
- * @dataProvider provideNotInjectedResponse
166
120
*/
167
- public function testToolbarIsNotInjectedOnContentDispositionAttachment (Response $ response , string $ expected )
121
+ public function testToolbarIsNotInjectedOnContentDispositionAttachment ()
168
122
{
123
+ $ response = new Response ('<html><head></head><body></body></html> ' );
169
124
$ response ->headers ->set ('X-Debug-Token ' , 'xxxxxxxx ' );
170
125
$ response ->headers ->set ('Content-Disposition ' , 'attachment; filename=test.html ' );
171
126
$ event = new ResponseEvent ($ this ->createMock (Kernel::class), new Request (), HttpKernelInterface::MAIN_REQUEST , $ response );
172
127
173
128
$ listener = new WebDebugToolbarListener ($ this ->getTwigMock ());
174
129
$ listener ->onKernelResponse ($ event );
175
130
176
- $ this ->assertEquals ($ expected , $ response ->getContent ());
131
+ $ this ->assertEquals (' <html><head></head><body></body></html> ' , $ response ->getContent ());
177
132
}
178
133
179
134
/**
@@ -203,34 +158,33 @@ public static function provideRedirects(): array
203
158
204
159
/**
205
160
* @depends testToolbarIsInjected
206
- *
207
- * @dataProvider provideNotInjectedResponse
208
161
*/
209
- public function testToolbarIsNotInjectedWhenThereIsNoNoXDebugTokenResponseHeader (Response $ response , string $ expected )
162
+ public function testToolbarIsNotInjectedWhenThereIsNoNoXDebugTokenResponseHeader ()
210
163
{
164
+ $ response = new Response ('<html><head></head><body></body></html> ' );
165
+
211
166
$ event = new ResponseEvent ($ this ->createMock (Kernel::class), new Request (), HttpKernelInterface::MAIN_REQUEST , $ response );
212
167
213
168
$ listener = new WebDebugToolbarListener ($ this ->getTwigMock ());
214
169
$ listener ->onKernelResponse ($ event );
215
170
216
- $ this ->assertEquals ($ expected , $ response ->getContent ());
171
+ $ this ->assertEquals (' <html><head></head><body></body></html> ' , $ response ->getContent ());
217
172
}
218
173
219
174
/**
220
175
* @depends testToolbarIsInjected
221
- *
222
- * @dataProvider provideNotInjectedResponse
223
176
*/
224
- public function testToolbarIsNotInjectedWhenOnSubRequest (Response $ response , string $ expected )
177
+ public function testToolbarIsNotInjectedWhenOnSubRequest ()
225
178
{
179
+ $ response = new Response ('<html><head></head><body></body></html> ' );
226
180
$ response ->headers ->set ('X-Debug-Token ' , 'xxxxxxxx ' );
227
181
228
182
$ event = new ResponseEvent ($ this ->createMock (Kernel::class), new Request (), HttpKernelInterface::SUB_REQUEST , $ response );
229
183
230
184
$ listener = new WebDebugToolbarListener ($ this ->getTwigMock ());
231
185
$ listener ->onKernelResponse ($ event );
232
186
233
- $ this ->assertEquals ($ expected , $ response ->getContent ());
187
+ $ this ->assertEquals (' <html><head></head><body></body></html> ' , $ response ->getContent ());
234
188
}
235
189
236
190
/**
@@ -251,11 +205,10 @@ public function testToolbarIsNotInjectedOnIncompleteHtmlResponses()
251
205
252
206
/**
253
207
* @depends testToolbarIsInjected
254
- *
255
- * @dataProvider provideNotInjectedResponse
256
208
*/
257
- public function testToolbarIsNotInjectedOnXmlHttpRequests (Response $ response , string $ expected )
209
+ public function testToolbarIsNotInjectedOnXmlHttpRequests ()
258
210
{
211
+ $ response = new Response ('<html><head></head><body></body></html> ' );
259
212
$ response ->headers ->set ('X-Debug-Token ' , 'xxxxxxxx ' );
260
213
261
214
$ request = new Request ();
@@ -266,31 +219,28 @@ public function testToolbarIsNotInjectedOnXmlHttpRequests(Response $response, st
266
219
$ listener = new WebDebugToolbarListener ($ this ->getTwigMock ());
267
220
$ listener ->onKernelResponse ($ event );
268
221
269
- $ this ->assertEquals ($ expected , $ response ->getContent ());
222
+ $ this ->assertEquals (' <html><head></head><body></body></html> ' , $ response ->getContent ());
270
223
}
271
224
272
225
/**
273
226
* @depends testToolbarIsInjected
274
- *
275
- * @dataProvider provideNotInjectedResponse
276
227
*/
277
- public function testToolbarIsNotInjectedOnNonHtmlRequests (Response $ response , string $ expected )
228
+ public function testToolbarIsNotInjectedOnNonHtmlRequests ()
278
229
{
230
+ $ response = new Response ('<html><head></head><body></body></html> ' );
279
231
$ response ->headers ->set ('X-Debug-Token ' , 'xxxxxxxx ' );
280
232
281
233
$ event = new ResponseEvent ($ this ->createMock (Kernel::class), new Request ([], [], ['_format ' => 'json ' ]), HttpKernelInterface::MAIN_REQUEST , $ response );
282
234
283
235
$ listener = new WebDebugToolbarListener ($ this ->getTwigMock ());
284
236
$ listener ->onKernelResponse ($ event );
285
237
286
- $ this ->assertEquals ($ expected , $ response ->getContent ());
238
+ $ this ->assertEquals (' <html><head></head><body></body></html> ' , $ response ->getContent ());
287
239
}
288
240
289
- /**
290
- * @dataProvider provideEmptyResponse
291
- */
292
- public function testXDebugUrlHeader (Response $ response )
241
+ public function testXDebugUrlHeader ()
293
242
{
243
+ $ response = new Response ();
294
244
$ response ->headers ->set ('X-Debug-Token ' , 'xxxxxxxx ' );
295
245
296
246
$ urlGenerator = $ this ->createMock (UrlGeneratorInterface::class);
@@ -309,11 +259,9 @@ public function testXDebugUrlHeader(Response $response)
309
259
$ this ->assertEquals ('http://mydomain.com/_profiler/xxxxxxxx ' , $ response ->headers ->get ('X-Debug-Token-Link ' ));
310
260
}
311
261
312
- /**
313
- * @dataProvider provideEmptyResponse
314
- */
315
- public function testThrowingUrlGenerator (Response $ response )
262
+ public function testThrowingUrlGenerator ()
316
263
{
264
+ $ response = new Response ();
317
265
$ response ->headers ->set ('X-Debug-Token ' , 'xxxxxxxx ' );
318
266
319
267
$ urlGenerator = $ this ->createMock (UrlGeneratorInterface::class);
@@ -332,11 +280,9 @@ public function testThrowingUrlGenerator(Response $response)
332
280
$ this ->assertEquals ('Exception: foo ' , $ response ->headers ->get ('X-Debug-Error ' ));
333
281
}
334
282
335
- /**
336
- * @dataProvider provideEmptyResponse
337
- */
338
- public function testThrowingErrorCleanup (Response $ response )
283
+ public function testThrowingErrorCleanup ()
339
284
{
285
+ $ response = new Response ();
340
286
$ response ->headers ->set ('X-Debug-Token ' , 'xxxxxxxx ' );
341
287
342
288
$ urlGenerator = $ this ->createMock (UrlGeneratorInterface::class);
@@ -355,11 +301,9 @@ public function testThrowingErrorCleanup(Response $response)
355
301
$ this ->assertEquals ('Exception: This multiline tabbed text should come out on a single plain line ' , $ response ->headers ->get ('X-Debug-Error ' ));
356
302
}
357
303
358
- /**
359
- * @dataProvider provideInjectedResponse
360
- */
361
- public function testCspIsDisabledIfDumperWasUsed (Response $ response , string $ expected )
304
+ public function testCspIsDisabledIfDumperWasUsed ()
362
305
{
306
+ $ response = new Response ('<html><head></head><body></body></html> ' );
363
307
$ response ->headers ->set ('X-Debug-Token ' , 'xxxxxxxx ' );
364
308
365
309
$ event = new ResponseEvent ($ this ->createMock (Kernel::class), new Request (), HttpKernelInterface::MAIN_REQUEST , $ response );
@@ -375,14 +319,12 @@ public function testCspIsDisabledIfDumperWasUsed(Response $response, string $exp
375
319
$ listener = new WebDebugToolbarListener ($ this ->getTwigMock (), false , WebDebugToolbarListener::ENABLED , null , '' , $ cspHandler , $ dumpDataCollector );
376
320
$ listener ->onKernelResponse ($ event );
377
321
378
- $ this ->assertEquals ($ expected , $ response ->getContent ());
322
+ $ this ->assertEquals (" <html><head></head><body> \n WDT \n </body></html> " , $ response ->getContent ());
379
323
}
380
324
381
- /**
382
- * @dataProvider provideInjectedResponse
383
- */
384
- public function testCspIsKeptEnabledIfDumperWasNotUsed (Response $ response , string $ expected )
325
+ public function testCspIsKeptEnabledIfDumperWasNotUsed ()
385
326
{
327
+ $ response = new Response ('<html><head></head><body></body></html> ' );
386
328
$ response ->headers ->set ('X-Debug-Token ' , 'xxxxxxxx ' );
387
329
388
330
$ event = new ResponseEvent ($ this ->createMock (Kernel::class), new Request (), HttpKernelInterface::MAIN_REQUEST , $ response );
@@ -398,7 +340,7 @@ public function testCspIsKeptEnabledIfDumperWasNotUsed(Response $response, strin
398
340
$ listener = new WebDebugToolbarListener ($ this ->getTwigMock (), false , WebDebugToolbarListener::ENABLED , null , '' , $ cspHandler , $ dumpDataCollector );
399
341
$ listener ->onKernelResponse ($ event );
400
342
401
- $ this ->assertEquals ($ expected , $ response ->getContent ());
343
+ $ this ->assertEquals (" <html><head></head><body> \n WDT \n </body></html> " , $ response ->getContent ());
402
344
}
403
345
404
346
public function testNullContentTypeWithNoDebugEnv ()
@@ -414,6 +356,7 @@ public function testNullContentTypeWithNoDebugEnv()
414
356
415
357
$ this ->expectNotToPerformAssertions ();
416
358
}
359
+
417
360
public function testAjaxReplaceHeaderOnDisabledToolbar ()
418
361
{
419
362
$ response = new Response ();
0 commit comments