Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Add routeRoute method to test request #49366

Merged
merged 2 commits into from Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php
Expand Up @@ -297,7 +297,7 @@ public function disableCookieEncryption()
}

/**
* Set the referer header and previous URL session value in order to simulate a previous request.
* Set the referer header and previous URL session value from a given URL in order to simulate a previous request.
*
* @param string $url
* @return $this
Expand All @@ -309,6 +309,18 @@ public function from(string $url)
return $this->withHeader('referer', $url);
}

/**
* Set the referer header and previous URL session value from a given route in order to simulate a previous request.
*
* @param string $name
* @param mixed $parameters
* @return $this
*/
public function fromRoute(string $name, $parameters = [])
{
return $this->from($this->app['url']->route($name, $parameters));
}

/**
* Set the Precognition header to "true".
*
Expand Down
12 changes: 12 additions & 0 deletions tests/Foundation/Testing/Concerns/MakesHttpRequestsTest.php
Expand Up @@ -18,6 +18,18 @@ public function testFromSetsHeaderAndSession()
$this->assertSame('previous/url', $this->app['session']->previousUrl());
}

public function testFromRouteSetsHeaderAndSession()
{
$router = $this->app->make(Registrar::class);

$router->get('previous/url', fn () => 'ok')->name('previous-url');

$this->fromRoute('previous-url');

$this->assertSame('http://localhost/previous/url', $this->defaultHeaders['referer']);
$this->assertSame('http://localhost/previous/url', $this->app['session']->previousUrl());
}

public function testWithTokenSetsAuthorizationHeader()
{
$this->withToken('foobar');
Expand Down