File tree 2 files changed +25
-1
lines changed
src/Illuminate/Foundation/Testing/Concerns
tests/Foundation/Testing/Concerns
2 files changed +25
-1
lines changed 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 @@ -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