This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
443 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Christian Gripp <mail@core23.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Core23\FacebookBundle\Tests\Action; | ||
|
||
use Core23\FacebookBundle\Action\AuthErrorAction; | ||
use Core23\FacebookBundle\Core23FacebookEvents; | ||
use Core23\FacebookBundle\Event\AuthFailedEvent; | ||
use Core23\FacebookBundle\Session\SessionManagerInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Argument; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Twig\Environment; | ||
|
||
class AuthErrorActionTest extends TestCase | ||
{ | ||
private $twig; | ||
|
||
private $router; | ||
|
||
private $sessionManager; | ||
|
||
private $eventDispatcher; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->twig = $this->prophesize(Environment::class); | ||
$this->router = $this->prophesize(RouterInterface::class); | ||
$this->sessionManager = $this->prophesize(SessionManagerInterface::class); | ||
$this->eventDispatcher = $this->prophesize(EventDispatcherInterface::class); | ||
} | ||
|
||
public function testExecute(): void | ||
{ | ||
$this->sessionManager->isAuthenticated() | ||
->willReturn(false) | ||
; | ||
|
||
$this->sessionManager->clear() | ||
->shouldBeCalled() | ||
; | ||
|
||
$this->eventDispatcher->dispatch(Core23FacebookEvents::AUTH_ERROR, Argument::type(AuthFailedEvent::class)) | ||
->willReturn(null) | ||
->shouldBeCalled() | ||
; | ||
|
||
$action = new AuthErrorAction( | ||
$this->twig->reveal(), | ||
$this->router->reveal(), | ||
$this->sessionManager->reveal(), | ||
$this->eventDispatcher->reveal() | ||
); | ||
|
||
$response = $action(); | ||
|
||
$this->assertNotInstanceOf(RedirectResponse::class, $response); | ||
$this->assertSame(200, $response->getStatusCode()); | ||
} | ||
|
||
public function testExecuteWithNoAuth(): void | ||
{ | ||
$this->sessionManager->isAuthenticated() | ||
->willReturn(true) | ||
; | ||
|
||
$this->router->generate('core23_facebook_success', [], UrlGeneratorInterface::ABSOLUTE_PATH) | ||
->willReturn('/success') | ||
->shouldBeCalled() | ||
; | ||
|
||
$action = new AuthErrorAction( | ||
$this->twig->reveal(), | ||
$this->router->reveal(), | ||
$this->sessionManager->reveal(), | ||
$this->eventDispatcher->reveal() | ||
); | ||
|
||
$this->assertInstanceOf(RedirectResponse::class, $action()); | ||
} | ||
} |
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,122 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Christian Gripp <mail@core23.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Core23\FacebookBundle\Tests\Action; | ||
|
||
use Core23\FacebookBundle\Action\AuthSuccessAction; | ||
use Core23\FacebookBundle\Core23FacebookEvents; | ||
use Core23\FacebookBundle\Event\AuthSuccessEvent; | ||
use Core23\FacebookBundle\Session\SessionInterface; | ||
use Core23\FacebookBundle\Session\SessionManagerInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Argument; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Twig\Environment; | ||
|
||
class AuthSuccessActionTest extends TestCase | ||
{ | ||
private $twig; | ||
|
||
private $router; | ||
|
||
private $sessionManager; | ||
|
||
private $eventDispatcher; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->twig = $this->prophesize(Environment::class); | ||
$this->router = $this->prophesize(RouterInterface::class); | ||
$this->sessionManager = $this->prophesize(SessionManagerInterface::class); | ||
$this->eventDispatcher = $this->prophesize(EventDispatcherInterface::class); | ||
} | ||
|
||
public function testExecute(): void | ||
{ | ||
$session = $this->prophesize(SessionInterface::class); | ||
|
||
$this->sessionManager->isAuthenticated() | ||
->willReturn(true) | ||
; | ||
$this->sessionManager->getSession() | ||
->willReturn($session) | ||
; | ||
$this->sessionManager->getUsername() | ||
->willReturn('FooUser') | ||
; | ||
|
||
$this->eventDispatcher->dispatch(Core23FacebookEvents::AUTH_SUCCESS, Argument::type(AuthSuccessEvent::class)) | ||
->shouldBeCalled() | ||
; | ||
|
||
$this->twig->render('@Core23Facebook/Auth/success.html.twig', [ | ||
'name' => 'FooUser', | ||
])->shouldBeCalled(); | ||
|
||
$action = new AuthSuccessAction( | ||
$this->twig->reveal(), | ||
$this->router->reveal(), | ||
$this->sessionManager->reveal(), | ||
$this->eventDispatcher->reveal() | ||
); | ||
|
||
$response = $action(); | ||
|
||
$this->assertNotInstanceOf(RedirectResponse::class, $response); | ||
$this->assertSame(200, $response->getStatusCode()); | ||
} | ||
|
||
public function testExecuteNoAuth(): void | ||
{ | ||
$this->sessionManager->isAuthenticated() | ||
->willReturn(false) | ||
; | ||
|
||
$this->router->generate('core23_facebook_error', [], UrlGeneratorInterface::ABSOLUTE_PATH) | ||
->willReturn('/success') | ||
->shouldBeCalled() | ||
; | ||
|
||
$action = new AuthSuccessAction( | ||
$this->twig->reveal(), | ||
$this->router->reveal(), | ||
$this->sessionManager->reveal(), | ||
$this->eventDispatcher->reveal() | ||
); | ||
|
||
$this->assertInstanceOf(RedirectResponse::class, $action()); | ||
} | ||
|
||
public function testExecuteNoSession(): void | ||
{ | ||
$this->sessionManager->isAuthenticated() | ||
->willReturn(true) | ||
; | ||
$this->sessionManager->getSession() | ||
->willReturn(null) | ||
; | ||
|
||
$this->router->generate('core23_facebook_error', [], UrlGeneratorInterface::ABSOLUTE_PATH) | ||
->willReturn('/success') | ||
->shouldBeCalled() | ||
; | ||
|
||
$action = new AuthSuccessAction( | ||
$this->twig->reveal(), | ||
$this->router->reveal(), | ||
$this->sessionManager->reveal(), | ||
$this->eventDispatcher->reveal() | ||
); | ||
|
||
$this->assertInstanceOf(RedirectResponse::class, $action()); | ||
} | ||
} |
Oops, something went wrong.