PageRenderTime 26ms CodeModel.GetById 18ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/Security/Firewall/FacebookListenerTest.php

http://github.com/FriendsOfSymfony/FOSFacebookBundle
PHP | 91 lines | 56 code | 12 blank | 23 comment | 0 complexity | 6f9e6757365a071a040bd405022b7dce MD5 | raw file
 1<?php
 2
 3/*
 4 * This file is part of the FOSFacebookBundle package.
 5 *
 6 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
 7 *
 8 * For the full copyright and license information, please view the LICENSE
 9 * file that was distributed with this source code.
10 */
11
12namespace FOS\FacebookBundle\Tests\Security\Firewall\FacebookListener;
13
14use FOS\FacebookBundle\Security\Firewall\FacebookListener;
15
16class FacebookListenerTest extends \PHPUnit_Framework_TestCase
17{
18    /**
19     * @covers FOS\FacebookBundle\Security\Firewall\FacebookListener::attemptAuthentication
20     */
21    public function testThatCanAttemptAuthenticationWithFacebook()
22    {
23        $listener = new FacebookListener(
24            $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'),
25            $this->getAuthenticationManager(),
26            $this->getMock('Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface'),
27            $this->getHttpUtils(),
28            'providerKey',
29            $this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface'),
30            $this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface')
31        );
32        $listener->handle($this->getResponseEvent());
33    }
34
35    /**
36     * @return Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface
37     */
38    private function getAuthenticationManager()
39    {
40        $authenticationManagerMock = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
41        $authenticationManagerMock->expects($this->once())
42            ->method('authenticate')
43            ->with($this->isInstanceOf('FOS\FacebookBundle\Security\Authentication\Token\FacebookUserToken'));
44
45        return $authenticationManagerMock;
46    }
47
48    /**
49     * @return Symfony\Component\Security\Http\HttpUtils
50     */
51    private function getHttpUtils()
52    {
53        $httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
54        $httpUtils->expects($this->once())
55            ->method('checkRequestPath')
56            ->will($this->returnValue(true));
57
58        return $httpUtils;
59    }
60
61    /**
62     * @return Symfony\Component\HttpKernel\Event\GetResponseEvent
63     */
64    private function getResponseEvent()
65    {
66        $responseEventMock = $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array('getRequest'), array(), '', false);
67        $responseEventMock->expects($this->any())
68            ->method('getRequest')
69            ->will($this->returnValue($this->getRequest()));
70
71        return $responseEventMock;
72    }
73
74    /**
75     * @return Symfony\Component\HttpFoundation\Request
76     */
77    private function getRequest()
78    {
79        $requestMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
80            ->disableOriginalClone()
81            ->getMock();
82        $requestMock->expects($this->any())
83            ->method('hasSession')
84            ->will($this->returnValue('true'));
85        $requestMock->expects($this->any())
86            ->method('hasPreviousSession')
87            ->will($this->returnValue('true'));
88
89        return $requestMock;
90    }
91}