File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
src/Illuminate/Foundation/Testing/Concerns
tests/Foundation/Testing/Concerns Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -297,7 +297,7 @@ public function disableCookieEncryption()
297297 }
298298
299299 /**
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.
301301 *
302302 * @param string $url
303303 * @return $this
@@ -309,6 +309,18 @@ public function from(string $url)
309309 return $ this ->withHeader ('referer ' , $ url );
310310 }
311311
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+
312324 /**
313325 * Set the Precognition header to "true".
314326 *
Original file line number Diff line number Diff line change @@ -18,6 +18,18 @@ public function testFromSetsHeaderAndSession()
1818 $ this ->assertSame ('previous/url ' , $ this ->app ['session ' ]->previousUrl ());
1919 }
2020
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+
2133 public function testWithTokenSetsAuthorizationHeader ()
2234 {
2335 $ this ->withToken ('foobar ' );
You can’t perform that action at this time.
0 commit comments