/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. * This file is part of the FOSFacebookBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace FOS\FacebookBundle\Tests\DependencyInjection\Security\Factory;
  11. use FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory;
  12. class FacebookFactoryTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @var FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory
  16. */
  17. private $factory = null;
  18. public function setUp()
  19. {
  20. $this->factory = new FacebookFactory();
  21. }
  22. public function testThatCanGetPosition()
  23. {
  24. $this->assertEquals('pre_auth', $this->factory->getPosition());
  25. }
  26. public function testThatCanGetKey()
  27. {
  28. $this->assertEquals('fos_facebook', $this->factory->getKey());
  29. }
  30. /**
  31. * @covers FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory::createAuthProvider
  32. */
  33. public function testThatCreateUserAuthProviderWhenDefinedInConfig()
  34. {
  35. $idsArray = $this->facebookFactoryCreate(array('provider' => true, 'remember_me' => false, 'create_user_if_not_exists' => false));
  36. $this->assertEquals('fos_facebook.auth.l3l0', $idsArray[0]);
  37. }
  38. /**
  39. * @covers FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory::createAuthProvider
  40. */
  41. public function testThatCreateUserAuthProviderEvenWhenNotDefinedInConfig()
  42. {
  43. $idsArray = $this->facebookFactoryCreate(array('remember_me' => false));
  44. $this->assertEquals('fos_facebook.auth.l3l0', $idsArray[0]);
  45. }
  46. /**
  47. * @covers FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory::createAuthProvider
  48. */
  49. public function testThatCreateDifferentUserAuthProviderForDifferentFirewalls()
  50. {
  51. $idsArray = $this->facebookFactoryCreate(array('remember_me' => false));
  52. $this->assertEquals('fos_facebook.auth.l3l0', $idsArray[0]);
  53. $idsArray = $this->facebookFactoryCreate(array('remember_me' => false), 'main');
  54. $this->assertEquals('fos_facebook.auth.main', $idsArray[0]);
  55. }
  56. /**
  57. * @covers FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory::createEntryPoint
  58. */
  59. public function testThatCreateEntryPoint()
  60. {
  61. $idsArray = $this->facebookFactoryCreate(array('remember_me' => false));
  62. $this->assertEquals('fos_facebook.security.authentication.entry_point.l3l0', $idsArray[2]);
  63. }
  64. /**
  65. * @covers FOS\FacebookBundle\DependencyInjection\Security\Factory\FacebookFactory::getListenerId
  66. */
  67. public function testThatListenerForListenerId()
  68. {
  69. $idsArray = $this->facebookFactoryCreate(array('remember_me' => false));
  70. $this->assertEquals('fos_facebook.security.authentication.listener.l3l0', $idsArray[1]);
  71. }
  72. /**
  73. * @param array $config
  74. * @return array
  75. */
  76. private function facebookFactoryCreate($config = array(), $id = 'l3l0')
  77. {
  78. $definition = $this->getMock('Symfony\Component\DependencyInjection\Definition', array('addArgument', 'replaceArgument'));
  79. $definition->expects($this->any())
  80. ->method('replaceArgument')
  81. ->will($this->returnValue($definition));
  82. $definition->expects($this->any())
  83. ->method('addArgument')
  84. ->will($this->returnValue($definition));
  85. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('setDefinition'));
  86. $container->expects($this->any())
  87. ->method('setDefinition')
  88. ->will($this->returnValue($definition));
  89. return $this->factory->create($container, $id, $config, 'l3l0.user.provider', null);
  90. }
  91. }