Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

facebook_login_url() #99

Open
wants to merge 1 commit into
base: 2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Templating/Helper/FacebookHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
23 changes: 22 additions & 1 deletion Tests/Twig/Extension/FacebookExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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')));
}
}
11 changes: 10 additions & 1 deletion Twig/Extension/FacebookExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
}

Expand Down Expand Up @@ -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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not goal of PR, but what about injecting helper via constructor and decline injecting container?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Koc Circular reference issue AFAICS (btw, the real place to solve it would be the helper, not the Twig extension as the helper would probably break because of a circular reference if you activate the PhpEngine without activating another engine)

}
}