/Tests/Templating/Helper/FacebookHelperTest.php

http://github.com/FriendsOfSymfony/FOSFacebookBundle · PHP · 107 lines · 78 code · 15 blank · 14 comment · 0 complexity · 21b9440e1e9d1b4130d7b5f422644666 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\Templating\Helper;
  11. use FOS\FacebookBundle\Templating\Helper\FacebookHelper;
  12. class FacebookHelperTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @covers FOS\FacebookBundle\Templating\Helper\FacebookHelper::initialize
  16. */
  17. public function testInitialize()
  18. {
  19. $expected = new \stdClass();
  20. $templating = $this->getMockBuilder('Symfony\Component\Templating\DelegatingEngine')
  21. ->disableOriginalConstructor()
  22. ->getMock();
  23. $templating
  24. ->expects($this->once())
  25. ->method('render')
  26. ->with('FOSFacebookBundle::initialize.html.php', array(
  27. 'appId' => 123,
  28. 'async' => true,
  29. 'cookie' => false,
  30. 'culture' => 'en_US',
  31. 'fbAsyncInit' => '',
  32. 'logging' => true,
  33. 'oauth' => true,
  34. 'status' => false,
  35. 'channelUrl' => '/channel.html',
  36. 'xfbml' => false,
  37. ))
  38. ->will($this->returnValue($expected));
  39. $facebookMock = $this->getMockBuilder('FOS\FacebookBundle\Facebook\FacebookSessionPersistence')
  40. ->disableOriginalConstructor()
  41. ->setMethods(array('getAppId'))
  42. ->getMock();
  43. $routing = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')
  44. ->disableOriginalConstructor()
  45. ->getMock();
  46. $routing
  47. ->expects($this->once())
  48. ->method('generate')
  49. ->will($this->returnValue('/channel.html'));
  50. $facebookMock->expects($this->once())
  51. ->method('getAppId')
  52. ->will($this->returnValue('123'));
  53. $helper = new FacebookHelper($templating, $facebookMock, $routing);
  54. $this->assertSame($expected, $helper->initialize(array('cookie' => false)));
  55. }
  56. /**
  57. * @covers FOS\FacebookBundle\Templating\Helper\FacebookHelper::loginButton
  58. */
  59. public function testLoginButton()
  60. {
  61. $expected = new \stdClass();
  62. $templating = $this->getMockBuilder('Symfony\Component\Templating\DelegatingEngine')
  63. ->disableOriginalConstructor()
  64. ->getMock();
  65. $templating
  66. ->expects($this->once())
  67. ->method('render')
  68. ->with('FOSFacebookBundle::loginButton.html.php', array(
  69. 'autologoutlink' => 'false',
  70. 'label' => 'testLabel',
  71. 'showFaces' => 'false',
  72. 'width' => '',
  73. 'maxRows' => '1',
  74. 'scope' => '1,2,3',
  75. 'registrationUrl' => '',
  76. 'size' => 'medium',
  77. 'onlogin' => ''
  78. ))
  79. ->will($this->returnValue($expected));
  80. $facebookMock = $this->getMockBuilder('FOS\FacebookBundle\Facebook\FacebookSessionPersistence')
  81. ->disableOriginalConstructor()
  82. ->setMethods(array('getAppId'))
  83. ->getMock();
  84. $routing = $this->getMockBuilder('Symfony\Component\Routing\Generator\UrlGeneratorInterface')
  85. ->disableOriginalConstructor()
  86. ->getMock();
  87. $facebookMock->expects($this->any())
  88. ->method('getAppId');
  89. $helper = new FacebookHelper($templating, $facebookMock, $routing, true, 'en_US', array(1,2,3) );
  90. $this->assertSame($expected, $helper->loginButton(array('label' => 'testLabel')));
  91. }
  92. }