From 79785db1f0021bdd52dd5900c87bb5128dd9f93d Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Tue, 21 Aug 2012 22:07:13 +0200 Subject: [PATCH 1/5] Allow specifying delivery whitelists for the redirect plugin --- DependencyInjection/Configuration.php | 15 ++ DependencyInjection/SwiftmailerExtension.php | 1 + Resources/config/schema/swiftmailer-1.0.xsd | 7 + Resources/config/swiftmailer.xml | 1 + .../Fixtures/config/php/antiflood.php | 4 + .../Fixtures/config/php/empty.php | 2 + .../Fixtures/config/php/null.php | 4 + .../Fixtures/config/php/redirect.php | 5 + .../Fixtures/config/php/redirect_single.php | 5 + .../Fixtures/config/php/smtp.php | 13 ++ .../Fixtures/config/php/spool.php | 4 + .../Fixtures/config/php/spool_memory.php | 4 + .../Fixtures/config/xml/antiflood.xml | 11 ++ .../Fixtures/config/xml/empty.xml | 9 ++ .../Fixtures/config/xml/null.xml | 9 ++ .../Fixtures/config/xml/redirect.xml | 14 ++ .../Fixtures/config/xml/redirect_single.xml | 13 ++ .../Fixtures/config/xml/smtp.xml | 20 +++ .../Fixtures/config/xml/spool.xml | 11 ++ .../Fixtures/config/xml/spool_memory.xml | 11 ++ .../Fixtures/config/yml/antiflood.yml | 2 + .../Fixtures/config/yml/empty.yml | 1 + .../Fixtures/config/yml/null.yml | 2 + .../Fixtures/config/yml/redirect.yml | 5 + .../Fixtures/config/yml/redirect_single.yml | 4 + .../Fixtures/config/yml/smtp.yml | 11 ++ .../Fixtures/config/yml/spool.yml | 2 + .../Fixtures/config/yml/spool_memory.yml | 3 + .../SwiftmailerExtensionTest.php | 150 +++++++++++++++--- composer.json | 3 +- 30 files changed, 325 insertions(+), 21 deletions(-) create mode 100644 Tests/DependencyInjection/Fixtures/config/php/antiflood.php create mode 100644 Tests/DependencyInjection/Fixtures/config/php/empty.php create mode 100644 Tests/DependencyInjection/Fixtures/config/php/null.php create mode 100644 Tests/DependencyInjection/Fixtures/config/php/redirect.php create mode 100644 Tests/DependencyInjection/Fixtures/config/php/redirect_single.php create mode 100644 Tests/DependencyInjection/Fixtures/config/php/smtp.php create mode 100644 Tests/DependencyInjection/Fixtures/config/php/spool.php create mode 100644 Tests/DependencyInjection/Fixtures/config/php/spool_memory.php create mode 100644 Tests/DependencyInjection/Fixtures/config/xml/antiflood.xml create mode 100644 Tests/DependencyInjection/Fixtures/config/xml/empty.xml create mode 100644 Tests/DependencyInjection/Fixtures/config/xml/null.xml create mode 100644 Tests/DependencyInjection/Fixtures/config/xml/redirect.xml create mode 100644 Tests/DependencyInjection/Fixtures/config/xml/redirect_single.xml create mode 100644 Tests/DependencyInjection/Fixtures/config/xml/smtp.xml create mode 100644 Tests/DependencyInjection/Fixtures/config/xml/spool.xml create mode 100644 Tests/DependencyInjection/Fixtures/config/xml/spool_memory.xml create mode 100644 Tests/DependencyInjection/Fixtures/config/yml/antiflood.yml create mode 100644 Tests/DependencyInjection/Fixtures/config/yml/empty.yml create mode 100644 Tests/DependencyInjection/Fixtures/config/yml/null.yml create mode 100644 Tests/DependencyInjection/Fixtures/config/yml/redirect.yml create mode 100644 Tests/DependencyInjection/Fixtures/config/yml/redirect_single.yml create mode 100644 Tests/DependencyInjection/Fixtures/config/yml/smtp.yml create mode 100644 Tests/DependencyInjection/Fixtures/config/yml/spool.yml create mode 100644 Tests/DependencyInjection/Fixtures/config/yml/spool_memory.yml diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 8dbe78cc..a1c9d26f 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -62,6 +62,8 @@ public function getConfigTreeBuilder() ->thenInvalid('The %s encryption is not supported') ->end() ->end() + ->end() + ->children() ->scalarNode('auth_mode') ->defaultNull() ->validate() @@ -69,6 +71,8 @@ public function getConfigTreeBuilder() ->thenInvalid('The %s authentication mode is not supported') ->end() ->end() + ->end() + ->children() ->arrayNode('spool') ->children() ->scalarNode('type')->defaultValue('file')->end() @@ -83,6 +87,17 @@ public function getConfigTreeBuilder() ->end() ->end() ->scalarNode('delivery_address')->end() + ->end() + ->fixXmlConfig('pattern', 'delivery_whitelist') + ->children() + ->arrayNode('delivery_whitelist') + ->beforeNormalization() + ->ifTrue(function($v) {return isset($v['pattern']) && is_array($v['pattern']);}) + ->then(function($v) {return $v['pattern'];}) + ->end() + ->prototype('scalar') + ->end() + ->end() ->booleanNode('disable_delivery')->end() ->booleanNode('logging')->defaultValue($this->debug)->end() ->end() diff --git a/DependencyInjection/SwiftmailerExtension.php b/DependencyInjection/SwiftmailerExtension.php index ef581911..bd477fca 100644 --- a/DependencyInjection/SwiftmailerExtension.php +++ b/DependencyInjection/SwiftmailerExtension.php @@ -126,6 +126,7 @@ public function load(array $configs, ContainerBuilder $container) } else { $container->setParameter('swiftmailer.single_address', null); } + $container->setParameter('swiftmailer.delivery_whitelist', $config['delivery_whitelist']); } /** diff --git a/Resources/config/schema/swiftmailer-1.0.xsd b/Resources/config/schema/swiftmailer-1.0.xsd index 9bc89ef4..f406b52e 100644 --- a/Resources/config/schema/swiftmailer-1.0.xsd +++ b/Resources/config/schema/swiftmailer-1.0.xsd @@ -9,6 +9,7 @@ + @@ -62,4 +63,10 @@ + + + + + + diff --git a/Resources/config/swiftmailer.xml b/Resources/config/swiftmailer.xml index 57753bf6..09c705c6 100644 --- a/Resources/config/swiftmailer.xml +++ b/Resources/config/swiftmailer.xml @@ -63,6 +63,7 @@ %swiftmailer.single_address% + %swiftmailer.delivery_whitelist% diff --git a/Tests/DependencyInjection/Fixtures/config/php/antiflood.php b/Tests/DependencyInjection/Fixtures/config/php/antiflood.php new file mode 100644 index 00000000..f87b678f --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/php/antiflood.php @@ -0,0 +1,4 @@ +loadFromExtension('swiftmailer', array( + 'antiflood' => true +)); \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/php/empty.php b/Tests/DependencyInjection/Fixtures/config/php/empty.php new file mode 100644 index 00000000..92165e87 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/php/empty.php @@ -0,0 +1,2 @@ +loadFromExtension('swiftmailer', array()); \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/php/null.php b/Tests/DependencyInjection/Fixtures/config/php/null.php new file mode 100644 index 00000000..503cbb1c --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/php/null.php @@ -0,0 +1,4 @@ +loadFromExtension('swiftmailer', array( + 'transport' => null +)); \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/php/redirect.php b/Tests/DependencyInjection/Fixtures/config/php/redirect.php new file mode 100644 index 00000000..7e0f5724 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/php/redirect.php @@ -0,0 +1,5 @@ +loadFromExtension('swiftmailer', array( + 'delivery_address' => 'single@host.com', + 'delivery_whitelist' => array('/foo@.*/', '/.*@bar.com$/'), +)); \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/php/redirect_single.php b/Tests/DependencyInjection/Fixtures/config/php/redirect_single.php new file mode 100644 index 00000000..bfe2f3ef --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/php/redirect_single.php @@ -0,0 +1,5 @@ +loadFromExtension('swiftmailer', array( + 'delivery_address' => 'single@host.com', + 'delivery_whitelist' => array('/foo@.*/'), +)); \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/php/smtp.php b/Tests/DependencyInjection/Fixtures/config/php/smtp.php new file mode 100644 index 00000000..0441d3c2 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/php/smtp.php @@ -0,0 +1,13 @@ +loadFromExtension('swiftmailer', array( + 'transport' => "smtp", + 'username' =>"user", + 'password' => "pass", + 'host' => "example.org", + 'port' => "12345", + 'encryption' => "tls", + 'auth-mode' => "login", + 'timeout' => "1000", + 'source_ip' => "127.0.0.1", + 'logging' => true, +)); \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/php/spool.php b/Tests/DependencyInjection/Fixtures/config/php/spool.php new file mode 100644 index 00000000..075efe89 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/php/spool.php @@ -0,0 +1,4 @@ +loadFromExtension('swiftmailer', array( + 'spool' => true +)); \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/php/spool_memory.php b/Tests/DependencyInjection/Fixtures/config/php/spool_memory.php new file mode 100644 index 00000000..3d181dda --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/php/spool_memory.php @@ -0,0 +1,4 @@ +loadFromExtension('swiftmailer', array( + 'spool' => array('type' => 'memory') +)); \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/xml/antiflood.xml b/Tests/DependencyInjection/Fixtures/config/xml/antiflood.xml new file mode 100644 index 00000000..f93e824a --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/antiflood.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/xml/empty.xml b/Tests/DependencyInjection/Fixtures/config/xml/empty.xml new file mode 100644 index 00000000..f917cbaa --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/empty.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/xml/null.xml b/Tests/DependencyInjection/Fixtures/config/xml/null.xml new file mode 100644 index 00000000..d0b000dd --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/null.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/xml/redirect.xml b/Tests/DependencyInjection/Fixtures/config/xml/redirect.xml new file mode 100644 index 00000000..340cfde6 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/redirect.xml @@ -0,0 +1,14 @@ + + + + + + /foo@.*/ + /.*@bar.com$/ + + + \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/xml/redirect_single.xml b/Tests/DependencyInjection/Fixtures/config/xml/redirect_single.xml new file mode 100644 index 00000000..6b53e5fb --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/redirect_single.xml @@ -0,0 +1,13 @@ + + + + + + /foo@.*/ + + + \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/xml/smtp.xml b/Tests/DependencyInjection/Fixtures/config/xml/smtp.xml new file mode 100644 index 00000000..6c28b302 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/smtp.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/xml/spool.xml b/Tests/DependencyInjection/Fixtures/config/xml/spool.xml new file mode 100644 index 00000000..a0363a60 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/spool.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/xml/spool_memory.xml b/Tests/DependencyInjection/Fixtures/config/xml/spool_memory.xml new file mode 100644 index 00000000..1167391d --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/spool_memory.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/yml/antiflood.yml b/Tests/DependencyInjection/Fixtures/config/yml/antiflood.yml new file mode 100644 index 00000000..26d8ac05 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/antiflood.yml @@ -0,0 +1,2 @@ +swiftmailer: + antiflood: true \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/yml/empty.yml b/Tests/DependencyInjection/Fixtures/config/yml/empty.yml new file mode 100644 index 00000000..21e89e52 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/empty.yml @@ -0,0 +1 @@ +swiftmailer: \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/yml/null.yml b/Tests/DependencyInjection/Fixtures/config/yml/null.yml new file mode 100644 index 00000000..a15653e6 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/null.yml @@ -0,0 +1,2 @@ +swiftmailer: + transport: ~ \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/yml/redirect.yml b/Tests/DependencyInjection/Fixtures/config/yml/redirect.yml new file mode 100644 index 00000000..b42bfccb --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/redirect.yml @@ -0,0 +1,5 @@ +swiftmailer: + delivery_address: single@host.com + delivery_whitelist: + - /foo@.*/ + - /.*@bar.com$/ diff --git a/Tests/DependencyInjection/Fixtures/config/yml/redirect_single.yml b/Tests/DependencyInjection/Fixtures/config/yml/redirect_single.yml new file mode 100644 index 00000000..1653424a --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/redirect_single.yml @@ -0,0 +1,4 @@ +swiftmailer: + delivery_address: single@host.com + delivery_whitelist: + - /foo@.*/ \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/yml/smtp.yml b/Tests/DependencyInjection/Fixtures/config/yml/smtp.yml new file mode 100644 index 00000000..b508e4a1 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/smtp.yml @@ -0,0 +1,11 @@ +swiftmailer: + transport: smtp + username: user + password: pass + host: example.org + port: 12345 + encryption: tls + auth-mode: login + timeout: 1000 + source_ip: 127.0.0.1 + logging: true diff --git a/Tests/DependencyInjection/Fixtures/config/yml/spool.yml b/Tests/DependencyInjection/Fixtures/config/yml/spool.yml new file mode 100644 index 00000000..3cee3550 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/spool.yml @@ -0,0 +1,2 @@ +swiftmailer: + spool: true \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/yml/spool_memory.yml b/Tests/DependencyInjection/Fixtures/config/yml/spool_memory.yml new file mode 100644 index 00000000..4ab4932c --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/spool_memory.yml @@ -0,0 +1,3 @@ +swiftmailer: + spool: + type: memory \ No newline at end of file diff --git a/Tests/DependencyInjection/SwiftmailerExtensionTest.php b/Tests/DependencyInjection/SwiftmailerExtensionTest.php index 9d72ddf3..7e965005 100644 --- a/Tests/DependencyInjection/SwiftmailerExtensionTest.php +++ b/Tests/DependencyInjection/SwiftmailerExtensionTest.php @@ -14,44 +14,154 @@ use Symfony\Bundle\SwiftmailerBundle\Tests\TestCase; use Symfony\Bundle\SwiftmailerBundle\DependencyInjection\SwiftmailerExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; +use Symfony\Component\Config\FileLocator; class SwiftmailerExtensionTest extends TestCase { - public function testConfigLoad() + public function getConfigTypes() { - $container = new ContainerBuilder(); - $container->setParameter('kernel.debug', false); - $loader = new SwiftmailerExtension(); - - $loader->load(array(array()), $container); - $this->assertEquals('Swift_Mailer', $container->getParameter('swiftmailer.class'), '->load() loads the swiftmailer.xml file if not already loaded'); + return array( + array('xml'), + array('php'), + array('yml') + ); + } - $loader->load(array(array('transport' => 'sendmail')), $container); - $this->assertEquals('swiftmailer.transport.sendmail', (string) $container->getAlias('swiftmailer.transport')); + /** + * @dataProvider getConfigTypes + */ + public function testDefaultConfig($type) + { + $container = $this->loadContainerFromFile('empty', $type); - $loader->load(array(array()), $container); $this->assertEquals('swiftmailer.transport.smtp', (string) $container->getAlias('swiftmailer.transport')); } - public function testNullTransport() + /** + * @dataProvider getConfigTypes + */ + public function testNullTransport($type) { - $container = new ContainerBuilder(); - $container->setParameter('kernel.debug', false); - $loader = new SwiftmailerExtension(); + $container = $this->loadContainerFromFile('null', $type); - $loader->load(array(array('transport' => null)), $container); $this->assertEquals('swiftmailer.transport.null', (string) $container->getAlias('swiftmailer.transport')); } - public function testSpool() + /** + * @dataProvider getConfigTypes + */ + public function testSpool($type) { - $container = new ContainerBuilder(); - $container->setParameter('kernel.debug', false); - $loader = new SwiftmailerExtension(); + $container = $this->loadContainerFromFile('spool', $type); - $loader->load(array(array('spool' => array())), $container); $this->assertEquals('swiftmailer.transport.spool', (string) $container->getAlias('swiftmailer.transport')); $this->assertEquals('swiftmailer.transport.smtp', (string) $container->getAlias('swiftmailer.transport.real')); + $this->assertTrue($container->has('swiftmailer.spool.file'), 'Default is file based spool'); } + /** + * @dataProvider getConfigTypes + */ + public function testMemorySpool($type) + { + $container = $this->loadContainerFromFile('spool_memory', $type); + + $this->assertEquals('swiftmailer.transport.spool', (string) $container->getAlias('swiftmailer.transport')); + $this->assertEquals('swiftmailer.transport.smtp', (string) $container->getAlias('swiftmailer.transport.real')); + $this->assertTrue($container->has('swiftmailer.spool.memory'), 'Memory based spool is configured'); + } + + /** + * @dataProvider getConfigTypes + */ + public function testSmtpConfig($type) + { + $container = $this->loadContainerFromFile('smtp', $type); + + $this->assertEquals('swiftmailer.transport.smtp', (string) $container->getAlias('swiftmailer.transport')); + + $this->assertEquals('example.org', $container->getParameter('swiftmailer.transport.smtp.host')); + $this->assertEquals('12345', $container->getParameter('swiftmailer.transport.smtp.port')); + $this->assertEquals('tls', $container->getParameter('swiftmailer.transport.smtp.encryption')); + $this->assertEquals('user', $container->getParameter('swiftmailer.transport.smtp.username')); + $this->assertEquals('pass', $container->getParameter('swiftmailer.transport.smtp.password')); + $this->assertEquals('login', $container->getParameter('swiftmailer.transport.smtp.auth_mode')); + $this->assertEquals('1000', $container->getParameter('swiftmailer.transport.smtp.timeout')); + $this->assertEquals('127.0.0.1', $container->getParameter('swiftmailer.transport.smtp.source_ip')); + } + + /** + * @dataProvider getConfigTypes + */ + public function testRedirectionConfig($type) + { + $container = $this->loadContainerFromFile('redirect', $type); + + $this->assertSame(array('swiftmailer.plugin' => array(array())), $container->getDefinition('swiftmailer.plugin.redirecting')->getTags()); + $this->assertSame('single@host.com', $container->getParameter('swiftmailer.single_address')); + $this->assertEquals(array('/foo@.*/', '/.*@bar.com$/'), $container->getParameter('swiftmailer.delivery_whitelist')); + } + + /** + * @dataProvider getConfigTypes + */ + public function testSingleRedirectionConfig($type) + { + $container = $this->loadContainerFromFile('redirect_single', $type); + + $this->assertSame(array('swiftmailer.plugin' => array(array())), $container->getDefinition('swiftmailer.plugin.redirecting')->getTags()); + $this->assertSame('single@host.com', $container->getParameter('swiftmailer.single_address')); + $this->assertEquals(array('/foo@.*/'), $container->getParameter('swiftmailer.delivery_whitelist')); + } + + /** + * @dataProvider getConfigTypes + */ + public function testAntifloodConfig($type) + { + $container = $this->loadContainerFromFile('antiflood', $type); + + $this->assertSame(array('swiftmailer.plugin' => array(array())), $container->getDefinition('swiftmailer.plugin.antiflood')->getTags()); + } + + /** + * @param string $file + * @param string $type + * @return ContainerBuilder + */ + private function loadContainerFromFile($file, $type) + { + $container = new ContainerBuilder(); + + $container->setParameter('kernel.debug', false); + $container->setParameter('kernel.cache_dir', '/tmp'); + + $container->registerExtension(new SwiftmailerExtension()); + $locator = new FileLocator(__DIR__ . '/Fixtures/config/' . $type); + + switch ($type) { + case 'xml': + $loader = new XmlFileLoader($container, $locator); + break; + + case 'yml': + $loader = new YamlFileLoader($container, $locator); + break; + + case 'php': + $loader = new PhpFileLoader($container, $locator); + break; + } + + $loader->load($file . '.' . $type); + + $container->getCompilerPassConfig()->setOptimizationPasses(array()); + $container->getCompilerPassConfig()->setRemovingPasses(array()); + $container->compile(); + + return $container; + } } diff --git a/composer.json b/composer.json index efb9999c..73f57045 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "require-dev": { "symfony/dependency-injection": "2.1.*", "symfony/http-kernel": "2.1.*", - "symfony/config": "2.1.*" + "symfony/config": "2.1.*", + "symfony/yaml": "2.1.*" }, "autoload": { "psr-0": { "Symfony\\Bundle\\SwiftmailerBundle": "" } From fd2897726fdd035fb4eb2d7498121164ebe6b7ca Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Tue, 28 Aug 2012 23:39:34 +0200 Subject: [PATCH 2/5] Removing porcelain --- DependencyInjection/Configuration.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a1c9d26f..80d8dac2 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -62,8 +62,6 @@ public function getConfigTreeBuilder() ->thenInvalid('The %s encryption is not supported') ->end() ->end() - ->end() - ->children() ->scalarNode('auth_mode') ->defaultNull() ->validate() @@ -71,8 +69,6 @@ public function getConfigTreeBuilder() ->thenInvalid('The %s authentication mode is not supported') ->end() ->end() - ->end() - ->children() ->arrayNode('spool') ->children() ->scalarNode('type')->defaultValue('file')->end() From 4addbfe9da60276c1b58c88b3a0e3dd54d7ba878 Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Tue, 28 Aug 2012 23:49:48 +0200 Subject: [PATCH 3/5] Adding full config file --- .../Fixtures/config/php/full.php | 16 +++++++++++ .../Fixtures/config/xml/full.xml | 27 +++++++++++++++++++ .../Fixtures/config/yml/full.yml | 17 ++++++++++++ .../SwiftmailerExtensionTest.php | 24 +++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 Tests/DependencyInjection/Fixtures/config/php/full.php create mode 100644 Tests/DependencyInjection/Fixtures/config/xml/full.xml create mode 100644 Tests/DependencyInjection/Fixtures/config/yml/full.yml diff --git a/Tests/DependencyInjection/Fixtures/config/php/full.php b/Tests/DependencyInjection/Fixtures/config/php/full.php new file mode 100644 index 00000000..cd02ef4b --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/php/full.php @@ -0,0 +1,16 @@ +loadFromExtension('swiftmailer', array( + 'transport' => "smtp", + 'username' =>"user", + 'password' => "pass", + 'host' => "example.org", + 'port' => "12345", + 'encryption' => "tls", + 'auth-mode' => "login", + 'timeout' => "1000", + 'source_ip' => "127.0.0.1", + 'logging' => true, + 'spool' => array('type' => 'memory'), + 'delivery_address' => 'single@host.com', + 'delivery_whitelist' => array('/foo@.*/', '/.*@bar.com$/'), +)); \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/xml/full.xml b/Tests/DependencyInjection/Fixtures/config/xml/full.xml new file mode 100644 index 00000000..1a73c95d --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/xml/full.xml @@ -0,0 +1,27 @@ + + + + + + + + /foo@.*/ + /.*@bar.com$/ + + + \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/yml/full.yml b/Tests/DependencyInjection/Fixtures/config/yml/full.yml new file mode 100644 index 00000000..7b5eea85 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/config/yml/full.yml @@ -0,0 +1,17 @@ +swiftmailer: + transport: smtp + username: user + password: pass + host: example.org + port: 12345 + encryption: tls + auth-mode: login + timeout: 1000 + source_ip: 127.0.0.1 + logging: true + spool: + type: memory + delivery_address: single@host.com + delivery_whitelist: + - /foo@.*/ + - /.*@bar.com$/ diff --git a/Tests/DependencyInjection/SwiftmailerExtensionTest.php b/Tests/DependencyInjection/SwiftmailerExtensionTest.php index 7e965005..3686ce43 100644 --- a/Tests/DependencyInjection/SwiftmailerExtensionTest.php +++ b/Tests/DependencyInjection/SwiftmailerExtensionTest.php @@ -50,6 +50,30 @@ public function testNullTransport($type) $this->assertEquals('swiftmailer.transport.null', (string) $container->getAlias('swiftmailer.transport')); } + /** + * @dataProvider getConfigTypes + */ + public function testFull($type) + { + $container = $this->loadContainerFromFile('full', $type); + + + $this->assertEquals('swiftmailer.transport.spool', (string) $container->getAlias('swiftmailer.transport')); + $this->assertEquals('swiftmailer.transport.smtp', (string) $container->getAlias('swiftmailer.transport.real')); + $this->assertTrue($container->has('swiftmailer.spool.memory')); + $this->assertEquals('example.org', $container->getParameter('swiftmailer.transport.smtp.host')); + $this->assertEquals('12345', $container->getParameter('swiftmailer.transport.smtp.port')); + $this->assertEquals('tls', $container->getParameter('swiftmailer.transport.smtp.encryption')); + $this->assertEquals('user', $container->getParameter('swiftmailer.transport.smtp.username')); + $this->assertEquals('pass', $container->getParameter('swiftmailer.transport.smtp.password')); + $this->assertEquals('login', $container->getParameter('swiftmailer.transport.smtp.auth_mode')); + $this->assertEquals('1000', $container->getParameter('swiftmailer.transport.smtp.timeout')); + $this->assertEquals('127.0.0.1', $container->getParameter('swiftmailer.transport.smtp.source_ip')); + $this->assertSame(array('swiftmailer.plugin' => array(array())), $container->getDefinition('swiftmailer.plugin.redirecting')->getTags()); + $this->assertSame('single@host.com', $container->getParameter('swiftmailer.single_address')); + $this->assertEquals(array('/foo@.*/', '/.*@bar.com$/'), $container->getParameter('swiftmailer.delivery_whitelist')); + } + /** * @dataProvider getConfigTypes */ From 7067ca92c91364069e9c033f75bae7c6c0ea9aaa Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 29 Aug 2012 13:00:19 +0200 Subject: [PATCH 4/5] Adding minimum stability to the composer.json --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 73f57045..a45cc657 100644 --- a/composer.json +++ b/composer.json @@ -34,5 +34,6 @@ "branch-alias": { "dev-master": "2.1-dev" } - } + }, + "minimum-stability": "dev" } From 3930be77d0f32017483270b0f917923dfcaabafc Mon Sep 17 00:00:00 2001 From: Lars Strojny Date: Wed, 29 Aug 2012 13:51:52 +0200 Subject: [PATCH 5/5] Worsen XML structure --- DependencyInjection/Configuration.php | 6 +----- Resources/config/schema/swiftmailer-1.0.xsd | 14 ++++---------- .../Fixtures/config/xml/full.xml | 6 ++---- .../Fixtures/config/xml/redirect.xml | 6 ++---- .../Fixtures/config/xml/redirect_single.xml | 4 +--- 5 files changed, 10 insertions(+), 26 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 80d8dac2..d45112c7 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -84,13 +84,9 @@ public function getConfigTreeBuilder() ->end() ->scalarNode('delivery_address')->end() ->end() - ->fixXmlConfig('pattern', 'delivery_whitelist') + ->fixXmlConfig('delivery_whitelist_pattern', 'delivery_whitelist') ->children() ->arrayNode('delivery_whitelist') - ->beforeNormalization() - ->ifTrue(function($v) {return isset($v['pattern']) && is_array($v['pattern']);}) - ->then(function($v) {return $v['pattern'];}) - ->end() ->prototype('scalar') ->end() ->end() diff --git a/Resources/config/schema/swiftmailer-1.0.xsd b/Resources/config/schema/swiftmailer-1.0.xsd index f406b52e..5f73a127 100644 --- a/Resources/config/schema/swiftmailer-1.0.xsd +++ b/Resources/config/schema/swiftmailer-1.0.xsd @@ -8,11 +8,11 @@ - - - + - + + + @@ -63,10 +63,4 @@ - - - - - - diff --git a/Tests/DependencyInjection/Fixtures/config/xml/full.xml b/Tests/DependencyInjection/Fixtures/config/xml/full.xml index 1a73c95d..46031ae1 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/full.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/full.xml @@ -19,9 +19,7 @@ delivery-address="single@host.com"> - - /foo@.*/ - /.*@bar.com$/ - + /foo@.*/ + /.*@bar.com$/ \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/xml/redirect.xml b/Tests/DependencyInjection/Fixtures/config/xml/redirect.xml index 340cfde6..f5f31765 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/redirect.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/redirect.xml @@ -6,9 +6,7 @@ http://symfony.com/schema/dic/swiftmailer http://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd"> - - /foo@.*/ - /.*@bar.com$/ - + /foo@.*/ + /.*@bar.com$/ \ No newline at end of file diff --git a/Tests/DependencyInjection/Fixtures/config/xml/redirect_single.xml b/Tests/DependencyInjection/Fixtures/config/xml/redirect_single.xml index 6b53e5fb..77b04fbc 100644 --- a/Tests/DependencyInjection/Fixtures/config/xml/redirect_single.xml +++ b/Tests/DependencyInjection/Fixtures/config/xml/redirect_single.xml @@ -6,8 +6,6 @@ http://symfony.com/schema/dic/swiftmailer http://symfony.com/schema/dic/swiftmailer/swiftmailer-1.0.xsd"> - - /foo@.*/ - + /foo@.*/ \ No newline at end of file