File tree Expand file tree Collapse file tree 5 files changed +50
-2
lines changed
src/Illuminate/Foundation
tests/Foundation/Testing/Concerns Expand file tree Collapse file tree 5 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -53,4 +53,14 @@ public static function skipWhen(Closure $callback)
53
53
{
54
54
static ::$ skipCallbacks [] = $ callback ;
55
55
}
56
+
57
+ /**
58
+ * Flush the middleware's global state.
59
+ *
60
+ * @return void
61
+ */
62
+ public static function flushState ()
63
+ {
64
+ static ::$ skipCallbacks = [];
65
+ }
56
66
}
Original file line number Diff line number Diff line change @@ -91,4 +91,14 @@ public static function skipWhen(Closure $callback)
91
91
{
92
92
static ::$ skipCallbacks [] = $ callback ;
93
93
}
94
+
95
+ /**
96
+ * Flush the middleware's global state.
97
+ *
98
+ * @return void
99
+ */
100
+ public static function flushState ()
101
+ {
102
+ static ::$ skipCallbacks = [];
103
+ }
94
104
}
Original file line number Diff line number Diff line change @@ -297,7 +297,7 @@ public function disableCookieEncryption()
297
297
}
298
298
299
299
/**
300
- * Set the referer header and previous URL session value in order to simulate a previous request.
300
+ * Set the referer header and previous URL session value from a given URL in order to simulate a previous request.
301
301
*
302
302
* @param string $url
303
303
* @return $this
@@ -309,6 +309,18 @@ public function from(string $url)
309
309
return $ this ->withHeader ('referer ' , $ url );
310
310
}
311
311
312
+ /**
313
+ * Set the referer header and previous URL session value from a given route in order to simulate a previous request.
314
+ *
315
+ * @param string $name
316
+ * @param mixed $parameters
317
+ * @return $this
318
+ */
319
+ public function fromRoute (string $ name , $ parameters = [])
320
+ {
321
+ return $ this ->from ($ this ->app ['url ' ]->route ($ name , $ parameters ));
322
+ }
323
+
312
324
/**
313
325
* Set the Precognition header to "true".
314
326
*
Original file line number Diff line number Diff line change 6
6
use Illuminate \Console \Application as Artisan ;
7
7
use Illuminate \Database \Eloquent \Model ;
8
8
use Illuminate \Foundation \Bootstrap \HandleExceptions ;
9
+ use Illuminate \Foundation \Http \Middleware \ConvertEmptyStringsToNull ;
10
+ use Illuminate \Foundation \Http \Middleware \TrimStrings ;
9
11
use Illuminate \Queue \Queue ;
10
12
use Illuminate \Support \Carbon ;
11
13
use Illuminate \Support \Facades \Facade ;
@@ -234,9 +236,11 @@ protected function tearDown(): void
234
236
Component::flushCache ();
235
237
Component::forgetComponentsResolver ();
236
238
Component::forgetFactory ();
237
- Queue:: createPayloadUsing ( null );
239
+ ConvertEmptyStringsToNull:: flushState ( );
238
240
HandleExceptions::forgetApp ();
241
+ Queue::createPayloadUsing (null );
239
242
Sleep::fake (false );
243
+ TrimStrings::flushState ();
240
244
241
245
if ($ this ->callbackException ) {
242
246
throw $ this ->callbackException ;
Original file line number Diff line number Diff line change @@ -18,6 +18,18 @@ public function testFromSetsHeaderAndSession()
18
18
$ this ->assertSame ('previous/url ' , $ this ->app ['session ' ]->previousUrl ());
19
19
}
20
20
21
+ public function testFromRouteSetsHeaderAndSession ()
22
+ {
23
+ $ router = $ this ->app ->make (Registrar::class);
24
+
25
+ $ router ->get ('previous/url ' , fn () => 'ok ' )->name ('previous-url ' );
26
+
27
+ $ this ->fromRoute ('previous-url ' );
28
+
29
+ $ this ->assertSame ('http://localhost/previous/url ' , $ this ->defaultHeaders ['referer ' ]);
30
+ $ this ->assertSame ('http://localhost/previous/url ' , $ this ->app ['session ' ]->previousUrl ());
31
+ }
32
+
21
33
public function testWithTokenSetsAuthorizationHeader ()
22
34
{
23
35
$ this ->withToken ('foobar ' );
You can’t perform that action at this time.
0 commit comments