Skip to content

Commit 2b76d49

Browse files
makasimdkarlovi
authored andcommitted
The authorize form should be used only if authorize option true. (#554)
* The authorize form should be used only if authorize option true. * add tests.
1 parent f167268 commit 2b76d49

File tree

2 files changed

+64
-9
lines changed

2 files changed

+64
-9
lines changed

DependencyInjection/FOSOAuthServerExtension.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ public function load(array $configs, ContainerBuilder $container)
9090

9191
if (!empty($config['authorize'])) {
9292
$this->loadAuthorize($config['authorize'], $container, $loader);
93-
}
9493

95-
// Authorize form factory definition
96-
// TODO: Go back to xml configuration when bumping the requirement to Symfony >=2.6
97-
$authorizeFormDefinition = $container->getDefinition('fos_oauth_server.authorize.form');
98-
if (method_exists($authorizeFormDefinition, 'setFactory')) {
99-
$authorizeFormDefinition->setFactory(array(new Reference('form.factory'), 'createNamed'));
100-
} else {
101-
$authorizeFormDefinition->setFactoryService('form.factory');
102-
$authorizeFormDefinition->setFactoryMethod('createNamed');
94+
// Authorize form factory definition
95+
// TODO: Go back to xml configuration when bumping the requirement to Symfony >=2.6
96+
$authorizeFormDefinition = $container->getDefinition('fos_oauth_server.authorize.form');
97+
if (method_exists($authorizeFormDefinition, 'setFactory')) {
98+
$authorizeFormDefinition->setFactory(array(new Reference('form.factory'), 'createNamed'));
99+
} else {
100+
$authorizeFormDefinition->setFactoryService('form.factory');
101+
$authorizeFormDefinition->setFactoryMethod('createNamed');
102+
}
103103
}
104104
}
105105

Tests/DependencyInjection/FOSOAuthServerExtensionTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,66 @@
1111

1212
namespace DependencyInjection;
1313

14+
use FOS\OAuthServerBundle\DependencyInjection\FOSOAuthServerExtension;
1415
use Symfony\Component\Config\FileLocator;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Extension\Extension;
1518
use Symfony\Component\Routing\Loader\XmlFileLoader;
1619

1720
class FOSOAuthServerExtensionTest extends \PHPUnit_Framework_TestCase
1821
{
22+
public function testShouldImplementConfigurationInterface()
23+
{
24+
$rc = new \ReflectionClass(FOSOAuthServerExtension::class);
25+
26+
$this->assertTrue($rc->isSubclassOf(Extension::class));
27+
}
28+
29+
public function testCouldBeConstructedWithoutAnyArguments()
30+
{
31+
new FOSOAuthServerExtension();
32+
}
33+
34+
public function testShouldLoadAuthorizeRelatedServicesIfAuthorizationIsEnabled()
35+
{
36+
$container = new ContainerBuilder();
37+
38+
$extension = new FOSOAuthServerExtension();
39+
$extension->load([[
40+
'db_driver' => 'orm',
41+
'client_class' => 'aClientClass',
42+
'access_token_class' => 'anAccessTokenClass',
43+
'refresh_token_class' => 'aRefreshTokenClass',
44+
'auth_code_class' => 'anAuthCodeClass',
45+
'authorize' => true,
46+
]], $container);
47+
48+
$this->assertTrue($container->hasDefinition('fos_oauth_server.authorize.form'));
49+
$this->assertTrue($container->hasDefinition('fos_oauth_server.authorize.form.type'));
50+
$this->assertTrue($container->hasDefinition('fos_oauth_server.authorize.form.handler.default'));
51+
$this->assertTrue($container->hasDefinition('fos_oauth_server.controller.authorize'));
52+
}
53+
54+
public function testShouldNotLoadAuthorizeRelatedServicesIfAuthorizationIsDisabled()
55+
{
56+
$container = new ContainerBuilder();
57+
58+
$extension = new FOSOAuthServerExtension();
59+
$extension->load([[
60+
'db_driver' => 'orm',
61+
'client_class' => 'aClientClass',
62+
'access_token_class' => 'anAccessTokenClass',
63+
'refresh_token_class' => 'aRefreshTokenClass',
64+
'auth_code_class' => 'anAuthCodeClass',
65+
'authorize' => false,
66+
]], $container);
67+
68+
$this->assertFalse($container->hasDefinition('fos_oauth_server.authorize.form'));
69+
$this->assertFalse($container->hasDefinition('fos_oauth_server.authorize.form.type'));
70+
$this->assertFalse($container->hasDefinition('fos_oauth_server.authorize.form.handler.default'));
71+
$this->assertFalse($container->hasDefinition('fos_oauth_server.controller.authorize'));
72+
}
73+
1974
public function testLoadAuthorizeRouting()
2075
{
2176
$locator = new FileLocator();

0 commit comments

Comments
 (0)