Browse Source

Fix boolean definition for options in configuration array

Thomas Rabaix 11 years ago
parent
commit
d203890f71

+ 2 - 2
DependencyInjection/Configuration.php

@@ -74,8 +74,8 @@ class Configuration implements ConfigurationInterface
                 ->arrayNode('options')
                     ->addDefaultsIfNotSet()
                     ->children()
-                        ->scalarNode('html5_validate')->defaultValue(true)->end()
-                        ->scalarNode('confirm_exit')->defaultValue(true)->end()
+                        ->booleanNode('html5_validate')->defaultValue(true)->end()
+                        ->booleanNode('confirm_exit')->defaultValue(true)->end()
                     ->end()
                 ->end()
                 ->arrayNode('dashboard')

+ 41 - 0
Tests/DependencyInjection/ConfigurationTest.php

@@ -0,0 +1,41 @@
+<?php
+
+/*
+ * This file is part of the Sonata package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Tests;
+
+use Sonata\AdminBundle\DependencyInjection\Configuration;
+use Symfony\Component\Config\Definition\Processor;
+
+class ConfigurationTest extends \PHPUnit_Framework_TestCase
+{
+    public function testOptions()
+    {
+        $processor = new Processor();
+
+        $config = $processor->processConfiguration(new Configuration(), array());
+
+        $this->assertTrue($config['options']['html5_validate']);
+        $this->assertTrue($config['options']['confirm_exit']);
+    }
+
+    public function testOptionsWithInvalidFormat()
+    {
+        $this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');
+
+        $processor = new Processor();
+
+        $config = $processor->processConfiguration(new Configuration(), array(array(
+            'options' => array(
+                'html5_validate' => '1'
+            )
+        )));
+    }
+}