From d463e25a75d23b08e498f5949d553a279b5e204c Mon Sep 17 00:00:00 2001 From: Nikita Konstantinov Date: Sat, 24 Aug 2013 04:46:37 +0400 Subject: [PATCH 1/2] [SecurityBundle] Move format-dependent tests from SecurityExtensionTest --- .../DependencyInjection/SecurityExtension.php | 3 +- .../CompleteConfigurationTest.php | 203 +++++++++++++++++ .../Fixtures/php/invalid_check_path.php | 16 -- .../Fixtures/xml/invalid_check_path.xml | 16 -- .../Fixtures/yml/invalid_check_path.yml | 9 - ...tionTest.php => MainConfigurationTest.php} | 2 +- ...t.php => PhpCompleteConfigurationTest.php} | 2 +- .../SecurityExtensionTest.php | 215 ++++-------------- ...t.php => XmlCompleteConfigurationTest.php} | 2 +- ....php => YamlCompleteConfigurationTest.php} | 2 +- 10 files changed, 256 insertions(+), 214 deletions(-) create mode 100644 src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php delete mode 100644 src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/invalid_check_path.php delete mode 100644 src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/invalid_check_path.xml delete mode 100644 src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/invalid_check_path.yml rename src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/{ConfigurationTest.php => MainConfigurationTest.php} (96%) rename src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/{PhpSecurityExtensionTest.php => PhpCompleteConfigurationTest.php} (90%) rename src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/{XmlSecurityExtensionTest.php => XmlCompleteConfigurationTest.php} (90%) rename src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/{YamlSecurityExtensionTest.php => YamlCompleteConfigurationTest.php} (90%) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index 97b9dbe59e..e56ac96bad 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -13,6 +13,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection; use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Alias; @@ -413,7 +414,7 @@ class SecurityExtension extends Extension } if (false === $hasListeners) { - throw new \LogicException(sprintf('No authentication listener registered for firewall "%s".', $id)); + throw new InvalidConfigurationException(sprintf('No authentication listener registered for firewall "%s".', $id)); } return array($listeners, $defaultEntryPoint); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php new file mode 100644 index 0000000000..1323c34d6d --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php @@ -0,0 +1,203 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection; + +use Symfony\Component\DependencyInjection\Reference; + +use Symfony\Component\DependencyInjection\Parameter; +use Symfony\Bundle\SecurityBundle\SecurityBundle; +use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension; +use Symfony\Component\DependencyInjection\ContainerBuilder; + +abstract class CompleteConfigurationTest extends \PHPUnit_Framework_TestCase +{ + abstract protected function loadFromFile(ContainerBuilder $container, $file); + + public function testRolesHierarchy() + { + $container = $this->getContainer('container1'); + $this->assertEquals(array( + 'ROLE_ADMIN' => array('ROLE_USER'), + 'ROLE_SUPER_ADMIN' => array('ROLE_USER', 'ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH'), + 'ROLE_REMOTE' => array('ROLE_USER', 'ROLE_ADMIN'), + ), $container->getParameter('security.role_hierarchy.roles')); + } + + public function testUserProviders() + { + $container = $this->getContainer('container1'); + + $providers = array_values(array_filter($container->getServiceIds(), function ($key) { return 0 === strpos($key, 'security.user.provider.concrete'); })); + + $expectedProviders = array( + 'security.user.provider.concrete.default', + 'security.user.provider.concrete.default_foo', + 'security.user.provider.concrete.digest', + 'security.user.provider.concrete.digest_foo', + 'security.user.provider.concrete.basic', + 'security.user.provider.concrete.basic_foo', + 'security.user.provider.concrete.basic_bar', + 'security.user.provider.concrete.service', + 'security.user.provider.concrete.chain', + ); + + $this->assertEquals(array(), array_diff($expectedProviders, $providers)); + $this->assertEquals(array(), array_diff($providers, $expectedProviders)); + + // chain provider + $this->assertEquals(array(array( + new Reference('security.user.provider.concrete.service'), + new Reference('security.user.provider.concrete.basic'), + )), $container->getDefinition('security.user.provider.concrete.chain')->getArguments()); + } + + public function testFirewalls() + { + $container = $this->getContainer('container1'); + + $arguments = $container->getDefinition('security.firewall.map')->getArguments(); + $listeners = array(); + foreach (array_keys($arguments[1]) as $contextId) { + $contextDef = $container->getDefinition($contextId); + $arguments = $contextDef->getArguments(); + $listeners[] = array_map(function ($ref) { return (string) $ref; }, $arguments['index_0']); + } + + $this->assertEquals(array( + array(), + array( + 'security.channel_listener', + 'security.logout_listener.secure', + 'security.authentication.listener.x509.secure', + 'security.authentication.listener.form.secure', + 'security.authentication.listener.basic.secure', + 'security.authentication.listener.digest.secure', + 'security.authentication.listener.anonymous.secure', + 'security.access_listener', + 'security.authentication.switchuser_listener.secure', + ), + ), $listeners); + } + + public function testAccess() + { + $container = $this->getContainer('container1'); + + $rules = array(); + foreach ($container->getDefinition('security.access_map')->getMethodCalls() as $call) { + if ($call[0] == 'add') { + $rules[] = array((string) $call[1][0], $call[1][1], $call[1][2]); + } + } + + $matcherIds = array(); + foreach ($rules as $rule) { + list($matcherId, $roles, $channel) = $rule; + $requestMatcher = $container->getDefinition($matcherId); + + $this->assertFalse(isset($matcherIds[$matcherId])); + $matcherIds[$matcherId] = true; + + $i = count($matcherIds); + if (1 === $i) { + $this->assertEquals(array('ROLE_USER'), $roles); + $this->assertEquals('https', $channel); + $this->assertEquals( + array('/blog/524', null, array('GET', 'POST')), + $requestMatcher->getArguments() + ); + } elseif (2 === $i) { + $this->assertEquals(array('IS_AUTHENTICATED_ANONYMOUSLY'), $roles); + $this->assertNull($channel); + $this->assertEquals( + array('/blog/.*'), + $requestMatcher->getArguments() + ); + } + } + } + + public function testMerge() + { + $container = $this->getContainer('merge'); + + $this->assertEquals(array( + 'FOO' => array('MOO'), + 'ADMIN' => array('USER'), + ), $container->getParameter('security.role_hierarchy.roles')); + } + + public function testEncoders() + { + $container = $this->getContainer('container1'); + + $this->assertEquals(array(array( + 'JMS\FooBundle\Entity\User1' => array( + 'class' => new Parameter('security.encoder.plain.class'), + 'arguments' => array(false), + ), + 'JMS\FooBundle\Entity\User2' => array( + 'class' => new Parameter('security.encoder.digest.class'), + 'arguments' => array('sha1', false, 5), + ), + 'JMS\FooBundle\Entity\User3' => array( + 'class' => new Parameter('security.encoder.digest.class'), + 'arguments' => array('md5', true, 5000), + ), + 'JMS\FooBundle\Entity\User4' => new Reference('security.encoder.foo'), + 'JMS\FooBundle\Entity\User5' => array( + 'class' => new Parameter('security.encoder.pbkdf2.class'), + 'arguments' => array('sha1', false, 5, 30), + ), + 'JMS\FooBundle\Entity\User6' => array( + 'class' => new Parameter('security.encoder.bcrypt.class'), + 'arguments' => array( + new Reference('security.secure_random'), + 15, + ) + ), + )), $container->getDefinition('security.encoder_factory.generic')->getArguments()); + } + + public function testAcl() + { + $container = $this->getContainer('container1'); + + $this->assertTrue($container->hasDefinition('security.acl.dbal.provider')); + $this->assertEquals('security.acl.dbal.provider', (string) $container->getAlias('security.acl.provider')); + } + + public function testCustomAclProvider() + { + $container = $this->getContainer('custom_acl_provider'); + + $this->assertFalse($container->hasDefinition('security.acl.dbal.provider')); + $this->assertEquals('foo', (string) $container->getAlias('security.acl.provider')); + } + + protected function getContainer($file) + { + $container = new ContainerBuilder(); + $security = new SecurityExtension(); + $container->registerExtension($security); + + $bundle = new SecurityBundle(); + $bundle->build($container); // Attach all default factories + $this->loadFromFile($container, $file); + + $container->getCompilerPassConfig()->setOptimizationPasses(array()); + $container->getCompilerPassConfig()->setRemovingPasses(array()); + $container->compile(); + + return $container; + } +} diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/invalid_check_path.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/invalid_check_path.php deleted file mode 100644 index 62e1acbc6c..0000000000 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/invalid_check_path.php +++ /dev/null @@ -1,16 +0,0 @@ -loadFromExtension('security', array( - 'providers' => array( - 'default' => array('id' => 'foo'), - ), - - 'firewalls' => array( - 'some_firewall' => array( - 'pattern' => '/secured_area/.*', - 'form_login' => array( - 'check_path' => '/some_area/login_check', - ) - ) - ) -)); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/invalid_check_path.xml b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/invalid_check_path.xml deleted file mode 100644 index f507d7037a..0000000000 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/invalid_check_path.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/invalid_check_path.yml b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/invalid_check_path.yml deleted file mode 100644 index dcdef71202..0000000000 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/invalid_check_path.yml +++ /dev/null @@ -1,9 +0,0 @@ -security: - providers: - default: { id: foo } - - firewalls: - some_firewall: - pattern: /secured_area/.* - form_login: - check_path: /some_area/login_check \ No newline at end of file diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/MainConfigurationTest.php similarity index 96% rename from src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/ConfigurationTest.php rename to src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/MainConfigurationTest.php index 0925e8b759..047821cfdb 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/MainConfigurationTest.php @@ -14,7 +14,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection; use Symfony\Bundle\SecurityBundle\DependencyInjection\MainConfiguration; use Symfony\Component\Config\Definition\Processor; -class ConfigurationTest extends \PHPUnit_Framework_TestCase +class MainConfigurationTest extends \PHPUnit_Framework_TestCase { /** * The minimal, required config needed to not have any required validation diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpSecurityExtensionTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpCompleteConfigurationTest.php similarity index 90% rename from src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpSecurityExtensionTest.php rename to src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpCompleteConfigurationTest.php index fc54797fc3..131c38d5e5 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpSecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/PhpCompleteConfigurationTest.php @@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\Config\FileLocator; -class PhpSecurityExtensionTest extends SecurityExtensionTest +class PhpCompleteConfigurationTest extends CompleteConfigurationTest { protected function loadFromFile(ContainerBuilder $container, $file) { diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php index 2f5a884b89..0605a1619e 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php @@ -11,202 +11,81 @@ namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection; -use Symfony\Component\DependencyInjection\Reference; - -use Symfony\Component\DependencyInjection\Parameter; -use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension; +use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Component\DependencyInjection\ContainerBuilder; -abstract class SecurityExtensionTest extends \PHPUnit_Framework_TestCase +class SecurityExtensionTest extends \PHPUnit_Framework_TestCase { - abstract protected function loadFromFile(ContainerBuilder $container, $file); - - public function testRolesHierarchy() + /** + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + * @expectedExceptionMessage The check_path "/some_area/login_check" for login method "form_login" is not matched by the firewall pattern "/secured_area/.*". + */ + public function testInvalidCheckPath() { - $container = $this->getContainer('container1'); - $this->assertEquals(array( - 'ROLE_ADMIN' => array('ROLE_USER'), - 'ROLE_SUPER_ADMIN' => array('ROLE_USER', 'ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH'), - 'ROLE_REMOTE' => array('ROLE_USER', 'ROLE_ADMIN'), - ), $container->getParameter('security.role_hierarchy.roles')); - } + $container = $this->getRawContainer(); - public function testUserProviders() - { - $container = $this->getContainer('container1'); - - $providers = array_values(array_filter($container->getServiceIds(), function ($key) { return 0 === strpos($key, 'security.user.provider.concrete'); })); - - $expectedProviders = array( - 'security.user.provider.concrete.default', - 'security.user.provider.concrete.default_foo', - 'security.user.provider.concrete.digest', - 'security.user.provider.concrete.digest_foo', - 'security.user.provider.concrete.basic', - 'security.user.provider.concrete.basic_foo', - 'security.user.provider.concrete.basic_bar', - 'security.user.provider.concrete.service', - 'security.user.provider.concrete.chain', - ); - - $this->assertEquals(array(), array_diff($expectedProviders, $providers)); - $this->assertEquals(array(), array_diff($providers, $expectedProviders)); - - // chain provider - $this->assertEquals(array(array( - new Reference('security.user.provider.concrete.service'), - new Reference('security.user.provider.concrete.basic'), - )), $container->getDefinition('security.user.provider.concrete.chain')->getArguments()); - } - - public function testFirewalls() - { - $container = $this->getContainer('container1'); - - $arguments = $container->getDefinition('security.firewall.map')->getArguments(); - $listeners = array(); - foreach (array_keys($arguments[1]) as $contextId) { - $contextDef = $container->getDefinition($contextId); - $arguments = $contextDef->getArguments(); - $listeners[] = array_map(function ($ref) { return (string) $ref; }, $arguments['index_0']); - } - - $this->assertEquals(array( - array(), - array( - 'security.channel_listener', - 'security.logout_listener.secure', - 'security.authentication.listener.x509.secure', - 'security.authentication.listener.form.secure', - 'security.authentication.listener.basic.secure', - 'security.authentication.listener.digest.secure', - 'security.authentication.listener.anonymous.secure', - 'security.access_listener', - 'security.authentication.switchuser_listener.secure', + $container->loadFromExtension('security', array( + 'providers' => array( + 'default' => array('id' => 'foo'), ), - ), $listeners); - } - public function testAccess() - { - $container = $this->getContainer('container1'); - - $rules = array(); - foreach ($container->getDefinition('security.access_map')->getMethodCalls() as $call) { - if ($call[0] == 'add') { - $rules[] = array((string) $call[1][0], $call[1][1], $call[1][2]); - } - } - - $matcherIds = array(); - foreach ($rules as $rule) { - list($matcherId, $roles, $channel) = $rule; - $requestMatcher = $container->getDefinition($matcherId); - - $this->assertFalse(isset($matcherIds[$matcherId])); - $matcherIds[$matcherId] = true; - - $i = count($matcherIds); - if (1 === $i) { - $this->assertEquals(array('ROLE_USER'), $roles); - $this->assertEquals('https', $channel); - $this->assertEquals( - array('/blog/524', null, array('GET', 'POST')), - $requestMatcher->getArguments() - ); - } elseif (2 === $i) { - $this->assertEquals(array('IS_AUTHENTICATED_ANONYMOUSLY'), $roles); - $this->assertNull($channel); - $this->assertEquals( - array('/blog/.*'), - $requestMatcher->getArguments() - ); - } - } - } - - public function testMerge() - { - $container = $this->getContainer('merge'); - - $this->assertEquals(array( - 'FOO' => array('MOO'), - 'ADMIN' => array('USER'), - ), $container->getParameter('security.role_hierarchy.roles')); - } - - public function testEncoders() - { - $container = $this->getContainer('container1'); - - $this->assertEquals(array(array( - 'JMS\FooBundle\Entity\User1' => array( - 'class' => new Parameter('security.encoder.plain.class'), - 'arguments' => array(false), - ), - 'JMS\FooBundle\Entity\User2' => array( - 'class' => new Parameter('security.encoder.digest.class'), - 'arguments' => array('sha1', false, 5), - ), - 'JMS\FooBundle\Entity\User3' => array( - 'class' => new Parameter('security.encoder.digest.class'), - 'arguments' => array('md5', true, 5000), - ), - 'JMS\FooBundle\Entity\User4' => new Reference('security.encoder.foo'), - 'JMS\FooBundle\Entity\User5' => array( - 'class' => new Parameter('security.encoder.pbkdf2.class'), - 'arguments' => array('sha1', false, 5, 30), - ), - 'JMS\FooBundle\Entity\User6' => array( - 'class' => new Parameter('security.encoder.bcrypt.class'), - 'arguments' => array( - new Reference('security.secure_random'), - 15, + 'firewalls' => array( + 'some_firewall' => array( + 'pattern' => '/secured_area/.*', + 'form_login' => array( + 'check_path' => '/some_area/login_check', + ) ) - ), - )), $container->getDefinition('security.encoder_factory.generic')->getArguments()); - } + ) + )); - public function testAcl() - { - $container = $this->getContainer('container1'); - - $this->assertTrue($container->hasDefinition('security.acl.dbal.provider')); - $this->assertEquals('security.acl.dbal.provider', (string) $container->getAlias('security.acl.provider')); - } - - public function testCustomAclProvider() - { - $container = $this->getContainer('custom_acl_provider'); - - $this->assertFalse($container->hasDefinition('security.acl.dbal.provider')); - $this->assertEquals('foo', (string) $container->getAlias('security.acl.provider')); + $container->compile(); } /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage not matched by the firewall pattern + * @expectedExceptionMessage No authentication listener registered for firewall "some_firewall" */ - public function testInvalidCheckPath() + public function testFirewallWithoutAuthenticationListener() { - $container = $this->getContainer('invalid_check_path'); + $container = $this->getRawContainer(); + + $container->loadFromExtension('security', array( + 'providers' => array( + 'default' => array('id' => 'foo'), + ), + + 'firewalls' => array( + 'some_firewall' => array( + 'pattern' => '/.*', + ) + ) + )); + + $container->compile(); } - protected function getContainer($file) + protected function getRawContainer() { $container = new ContainerBuilder(); $security = new SecurityExtension(); $container->registerExtension($security); $bundle = new SecurityBundle(); - $bundle->build($container); // Attach all default factories - $this->loadFromFile($container, $file); + $bundle->build($container); $container->getCompilerPassConfig()->setOptimizationPasses(array()); $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->compile(); return $container; } + + protected function getContainer() + { + $containter = $this->getRawContainer(); + $containter->compile(); + + return $containter; + } } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlSecurityExtensionTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlCompleteConfigurationTest.php similarity index 90% rename from src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlSecurityExtensionTest.php rename to src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlCompleteConfigurationTest.php index 6ce0489f2e..cf6833a22a 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlSecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/XmlCompleteConfigurationTest.php @@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\Config\FileLocator; -class XmlSecurityExtensionTest extends SecurityExtensionTest +class XmlCompleteConfigurationTest extends CompleteConfigurationTest { protected function loadFromFile(ContainerBuilder $container, $file) { diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlSecurityExtensionTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlCompleteConfigurationTest.php similarity index 90% rename from src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlSecurityExtensionTest.php rename to src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlCompleteConfigurationTest.php index f5fabe0257..568b8623ea 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlSecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/YamlCompleteConfigurationTest.php @@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\Config\FileLocator; -class YamlSecurityExtensionTest extends SecurityExtensionTest +class YamlCompleteConfigurationTest extends CompleteConfigurationTest { protected function loadFromFile(ContainerBuilder $container, $file) { From 4922a80ee5995b5fca8b02cf67edbfb881474406 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 28 Aug 2013 10:25:32 +0200 Subject: [PATCH 2/2] [FrameworkBundle] added support for double-quoted strings in the extractor (closes #8797) --- .../Tests/Fixtures/Resources/views/translation.html.php | 3 ++- .../FrameworkBundle/Tests/Translation/PhpExtractorTest.php | 7 ++++--- .../Bundle/FrameworkBundle/Translation/PhpExtractor.php | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/translation.html.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/translation.html.php index 48ea9fdb08..23631b9943 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/translation.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Resources/views/translation.html.php @@ -1,2 +1,3 @@ This template is used for translation message extraction tests -trans('new key') ?> +trans('single-quoted key') ?> +trans("double-quoted key") ?> diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/PhpExtractorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/PhpExtractorTest.php index 4305f0e69c..d639f01806 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/PhpExtractorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/PhpExtractorTest.php @@ -28,8 +28,9 @@ class PhpExtractorTest extends TestCase $extractor->extract(__DIR__.'/../Fixtures/Resources/views/', $catalogue); // Assert - $this->assertCount(1, $catalogue->all('messages'), '->extract() should find 1 translation'); - $this->assertTrue($catalogue->has('new key'), '->extract() should find at leat "new key" message'); - $this->assertEquals('prefixnew key', $catalogue->get('new key'), '->extract() should apply "prefix" as prefix'); + $this->assertCount(2, $catalogue->all('messages'), '->extract() should find 1 translation'); + $this->assertTrue($catalogue->has('single-quoted key'), '->extract() should find the "single-quoted key" message'); + $this->assertTrue($catalogue->has('double-quoted key'), '->extract() should find the "double-quoted key" message'); + $this->assertEquals('prefixsingle-quoted key', $catalogue->get('single-quoted key'), '->extract() should apply "prefix" as prefix'); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php b/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php index 1eb36052b3..1b8bfe44a7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php @@ -111,7 +111,7 @@ class PhpExtractor implements ExtractorInterface } } - $message = trim($message, '\''); + $message = trim($message, '\'"'); if ($message) { $catalog->set($message, $this->prefix.$message);