Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ public function assertRedirectContains($uri)
return $this;
}

/**
* Assert whether the response is redirecting back to the previous location.
*
* @return $this
*/
public function assertRedirectBack()
{
PHPUnit::withResponse($this)->assertTrue(
$this->isRedirect(),
$this->statusMessageWithDetails('201, 301, 302, 303, 307, 308', $this->getStatusCode()),
);

$this->assertLocation(app('url')->previous());

return $this;
}

/**
* Assert whether the response is redirecting to a given route.
*
Expand Down
21 changes: 21 additions & 0 deletions tests/Testing/TestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2631,6 +2631,27 @@ public function testAssertRedirect()
$response->assertRedirect();
}

public function testAssertRedirectBack()
{
app()->instance('session.store', $store = new Store('test-session', new ArraySessionHandler(1)));

$store->setPreviousUrl('https://url.com');

app('url')->setSessionResolver(fn () => app('session.store'));

$response = TestResponse::fromBaseResponse(
(new Response('', 302))->withHeaders(['Location' => 'https://url.com'])
);

$response->assertRedirectBack();

$this->expectException(ExpectationFailedException::class);

$store->setPreviousUrl('https://url.net');

$response->assertRedirectBack();
}

public function testGetDecryptedCookie()
{
$response = TestResponse::fromBaseResponse(
Expand Down