PageRenderTime 20ms CodeModel.GetById 10ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/Tests/DependencyInjection/Security/Factory/FacebookFactoryTest.php

http://github.com/FriendsOfSymfony/FOSFacebookBundle
PHP | 106 lines | 61 code | 15 blank | 30 comment | 0 complexity | f7bcf4a594517a5d2b4180e3bacbd2aa 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\DependencyInjection\Security\Factory;
 13
 14use FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory;
 15
 16class FacebookFactoryTest extends \PHPUnit_Framework_TestCase
 17{
 18    /**
 19     * @var FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory
 20     */
 21    private $factory = null;
 22
 23    public function setUp()
 24    {
 25        $this->factory = new FacebookFactory();
 26    }
 27
 28    public function testThatCanGetPosition()
 29    {
 30        $this->assertEquals('pre_auth', $this->factory->getPosition());
 31    }
 32
 33    public function testThatCanGetKey()
 34    {
 35        $this->assertEquals('fos_facebook', $this->factory->getKey());
 36    }
 37
 38    /**
 39     * @covers FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory::createAuthProvider
 40     */
 41    public function testThatCreateUserAuthProviderWhenDefinedInConfig()
 42    {
 43        $idsArray = $this->facebookFactoryCreate(array('provider' => true, 'remember_me' => false, 'create_user_if_not_exists' => false));
 44        $this->assertEquals('fos_facebook.auth.l3l0', $idsArray[0]);
 45    }
 46
 47    /**
 48     * @covers FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory::createAuthProvider
 49     */
 50    public function testThatCreateUserAuthProviderEvenWhenNotDefinedInConfig()
 51    {
 52        $idsArray = $this->facebookFactoryCreate(array('remember_me' => false));
 53        $this->assertEquals('fos_facebook.auth.l3l0', $idsArray[0]);
 54    }
 55
 56    /**
 57     * @covers FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory::createAuthProvider
 58     */
 59    public function testThatCreateDifferentUserAuthProviderForDifferentFirewalls()
 60    {
 61        $idsArray = $this->facebookFactoryCreate(array('remember_me' => false));
 62        $this->assertEquals('fos_facebook.auth.l3l0', $idsArray[0]);
 63
 64        $idsArray = $this->facebookFactoryCreate(array('remember_me' => false), 'main');
 65        $this->assertEquals('fos_facebook.auth.main', $idsArray[0]);
 66    }
 67
 68    /**
 69     * @covers FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory::createEntryPoint
 70     */
 71    public function testThatCreateEntryPoint()
 72    {
 73        $idsArray = $this->facebookFactoryCreate(array('remember_me' => false));
 74        $this->assertEquals('fos_facebook.security.authentication.entry_point.l3l0', $idsArray[2]);
 75    }
 76
 77    /**
 78     * @covers FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory::getListenerId
 79     */
 80    public function testThatListenerForListenerId()
 81    {
 82        $idsArray = $this->facebookFactoryCreate(array('remember_me' => false));
 83        $this->assertEquals('fos_facebook.security.authentication.listener.l3l0', $idsArray[1]);
 84    }
 85
 86    /**
 87     * @param  array $config
 88     * @return array
 89     */
 90    private function facebookFactoryCreate($config = array(), $id = 'l3l0')
 91    {
 92        $definition = $this->getMock('Symfony\Component\DependencyInjection\Definition', array('addArgument', 'replaceArgument'));
 93        $definition->expects($this->any())
 94            ->method('replaceArgument')
 95            ->will($this->returnValue($definition));
 96        $definition->expects($this->any())
 97            ->method('addArgument')
 98            ->will($this->returnValue($definition));
 99        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('setDefinition'));
100        $container->expects($this->any())
101            ->method('setDefinition')
102            ->will($this->returnValue($definition));
103
104        return $this->factory->create($container, $id, $config, 'l3l0.user.provider', null);
105    }
106}