diff --git a/Templating/Helper/FacebookHelper.php b/Templating/Helper/FacebookHelper.php index 4045ece..126591f 100644 --- a/Templating/Helper/FacebookHelper.php +++ b/Templating/Helper/FacebookHelper.php @@ -77,6 +77,20 @@ public function loginButton($parameters = array(), $name = null) )); } + public function loginUrl($parameters = array()) + { + if (!isset($parameters['scope'])) { + $parameters['scope'] = implode(',', $this->scope); + } + + // // todo: default to the configured check_path + // if (!isset($parameters['redirect_uri'])) { + // $parameters['redirect_uri'] = + // } + + return $this->facebook->getLoginUrl($parameters); + } + /** * @codeCoverageIgnore */ diff --git a/Tests/Twig/Extension/FacebookExtensionTest.php b/Tests/Twig/Extension/FacebookExtensionTest.php index 9fe393e..97ea9ae 100644 --- a/Tests/Twig/Extension/FacebookExtensionTest.php +++ b/Tests/Twig/Extension/FacebookExtensionTest.php @@ -12,7 +12,7 @@ namespace FOS\FacebookBundle\Tests\Twig\Extension; use FOS\FacebookBundle\Twig\Extension\FacebookExtension; -use FOS\FacebookBundle\Templating\Helper\FacebookHelper; +use Symfony\Component\DependencyInjection\Container; class FacebookExtensionTest extends \PHPUnit_Framework_TestCase { @@ -79,4 +79,25 @@ public function testRenderLoginButton() $extension = new FacebookExtension($containerMock); $this->assertSame('returnedValueLogin', $extension->renderLoginButton()); } + + /** + * @covers FOS\FacebookBundle\Twig\Extension\FacebookExtension::getLoginUrl + */ + public function testGetLoginUrl() + { + $helper = $this->getMockBuilder('FOS\FacebookBundle\Templating\Helper\FacebookHelper') + ->disableOriginalConstructor() + ->getMock(); + + $container = new Container(); + $container->set('fos_facebook.helper', $helper); + + $helper->expects($this->once()) + ->method('loginUrl') + ->with(array('foo' => 'bar')) + ->will($this->returnValue('http://foo.com')); + + $extension = new FacebookExtension($container); + $this->assertEquals('http://foo.com', $extension->getLoginUrl(array('foo' => 'bar'))); + } } diff --git a/Twig/Extension/FacebookExtension.php b/Twig/Extension/FacebookExtension.php index 6612a08..54e5cac 100644 --- a/Twig/Extension/FacebookExtension.php +++ b/Twig/Extension/FacebookExtension.php @@ -36,8 +36,9 @@ public function __construct(ContainerInterface $container) public function getFunctions() { return array( - 'facebook_initialize' => new \Twig_Function_Method($this, 'renderInitialize', array('is_safe' => array('html'))), + 'facebook_initialize' => new \Twig_Function_Method($this, 'renderInitialize', array('is_safe' => array('html'))), 'facebook_login_button' => new \Twig_Function_Method($this, 'renderLoginButton', array('is_safe' => array('html'))), + 'facebook_login_url' => new \Twig_Function_Method($this, 'getLoginUrl'), ); } @@ -66,4 +67,12 @@ public function renderLoginButton($parameters = array(), $name = null) { return $this->container->get('fos_facebook.helper')->loginButton($parameters, $name ?: 'FOSFacebookBundle::loginButton.html.twig'); } + + /** + * @see FacebookHelper::loginUrl() + */ + public function getLoginUrl($parameters = array()) + { + return $this->container->get('fos_facebook.helper')->loginUrl($parameters); + } }