-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get/set leave redirect to url from/to session
- Loading branch information
1 parent
d8ab69f
commit ff0340c
Showing
5 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Lab404\Tests; | ||
|
||
use Lab404\Impersonate\Services\ImpersonateManager; | ||
|
||
class ImpersonateControllerTest extends TestCase | ||
{ | ||
/** @var ImpersonateManager $manager */ | ||
protected $manager; | ||
|
||
/** @var string $guard */ | ||
protected $guard; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->manager = $this->app->make(ImpersonateManager::class); | ||
$this->guard = 'web'; | ||
} | ||
|
||
/** @test */ | ||
public function it_gets_leave_redirect_to_from_session_if_exists() | ||
{ | ||
// Arrange | ||
$leaveRedirectTo = 'http://example.com'; | ||
$this->app['session']->put($this->manager->getSessionLeaveRedirectTo(), $leaveRedirectTo); | ||
$this->app['session']->put($this->manager->getSessionKey(), 'test_session_key'); | ||
|
||
// Act | ||
$response = $this->get(route('impersonate.leave')); | ||
|
||
// Assert | ||
$response->assertRedirect($leaveRedirectTo); | ||
} | ||
|
||
/** @test */ | ||
public function it_gets_leave_redirect_to_from_query_parameter_and_stores_it_in_session() | ||
{ | ||
// Arrange | ||
$this->withoutExceptionHandling(); | ||
$this->app['auth']->loginUsingId('[email protected]'); | ||
$leaveRedirectTo = 'http://example.com'; | ||
|
||
// Act | ||
$response = $this->get(route('impersonate', ['id' => '[email protected]', 'guardName' => 'web', 'leaveRedirectTo' => $leaveRedirectTo])); | ||
|
||
// Assert | ||
$this->assertEquals($leaveRedirectTo, $this->app['session']->get($this->manager->getSessionLeaveRedirectTo())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,4 +214,19 @@ public function it_renames_the_remember_web_cookie_when_taking_and_reverts_the_c | |
$this->assertEquals($cookie->getName(), $response->headers->getCookies()[0]->getName()); | ||
$this->assertEquals($cookie->getValue(), $response->headers->getCookies()[0]->getValue()); | ||
} | ||
|
||
/** @test */ | ||
public function it_puts_leave_redirect_to_in_session_when_take_is_called() | ||
{ | ||
// Arrange | ||
$this->app['auth']->loginUsingId('[email protected]'); | ||
$leaveRedirectTo = 'http://localhost/custom-redirect-url'; | ||
|
||
// Act | ||
$this->manager->take($this->app['auth']->user(), $this->manager->findUserById('[email protected]'), null, $leaveRedirectTo); | ||
|
||
// Assert | ||
$this->assertEquals($leaveRedirectTo, $this->app['session']->get($this->manager->getSessionLeaveRedirectTo())); | ||
} | ||
|
||
} |