2012-12-14 10:26:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
|
|
|
|
use Symfony\Component\Config\Definition\Processor;
|
|
|
|
|
|
|
|
class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
2013-01-23 14:18:20 +00:00
|
|
|
public function testDefaultConfig()
|
2012-12-14 10:26:52 +00:00
|
|
|
{
|
|
|
|
$processor = new Processor();
|
2014-05-10 23:14:12 +01:00
|
|
|
$config = $processor->processConfiguration(new Configuration(true), array(array('secret' => 's3cr3t')));
|
2012-12-14 10:26:52 +00:00
|
|
|
|
2013-01-23 14:18:20 +00:00
|
|
|
$this->assertEquals(
|
2013-08-07 15:00:53 +01:00
|
|
|
array_merge(array('secret' => 's3cr3t', 'trusted_hosts' => array()), self::getBundleDefaultConfig()),
|
2013-01-23 14:18:20 +00:00
|
|
|
$config
|
2012-12-14 10:26:52 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-08-02 00:30:03 +01:00
|
|
|
public function testDoNoDuplicateDefaultFormResources()
|
|
|
|
{
|
|
|
|
$input = array('templating' => array(
|
|
|
|
'form' => array('resources' => array('FrameworkBundle:Form')),
|
|
|
|
'engines' => array('php'),
|
|
|
|
));
|
|
|
|
|
|
|
|
$processor = new Processor();
|
2015-08-26 19:16:18 +01:00
|
|
|
$config = $processor->processConfiguration(new Configuration(true), array($input));
|
2015-08-02 00:30:03 +01:00
|
|
|
|
|
|
|
$this->assertEquals(array('FrameworkBundle:Form'), $config['templating']['form']['resources']);
|
|
|
|
}
|
|
|
|
|
2012-12-14 10:26:52 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider getTestValidTrustedProxiesData
|
|
|
|
*/
|
2013-01-23 14:18:20 +00:00
|
|
|
public function testValidTrustedProxies($trustedProxies, $processedProxies)
|
2012-12-14 10:26:52 +00:00
|
|
|
{
|
|
|
|
$processor = new Processor();
|
2014-05-10 23:14:12 +01:00
|
|
|
$configuration = new Configuration(true);
|
2013-01-23 14:18:20 +00:00
|
|
|
$config = $processor->processConfiguration($configuration, array(array(
|
2014-10-22 19:27:13 +01:00
|
|
|
'secret' => 's3cr3t',
|
2014-09-21 19:53:12 +01:00
|
|
|
'trusted_proxies' => $trustedProxies,
|
2013-01-23 14:18:20 +00:00
|
|
|
)));
|
2012-12-14 10:26:52 +00:00
|
|
|
|
2013-01-23 14:18:20 +00:00
|
|
|
$this->assertEquals($processedProxies, $config['trusted_proxies']);
|
2012-12-14 10:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTestValidTrustedProxiesData()
|
|
|
|
{
|
|
|
|
return array(
|
2013-01-23 14:18:20 +00:00
|
|
|
array(array('127.0.0.1'), array('127.0.0.1')),
|
|
|
|
array(array('::1'), array('::1')),
|
|
|
|
array(array('127.0.0.1', '::1'), array('127.0.0.1', '::1')),
|
|
|
|
array(null, array()),
|
|
|
|
array(false, array()),
|
|
|
|
array(array(), array()),
|
2013-03-08 20:55:36 +00:00
|
|
|
array(array('10.0.0.0/8'), array('10.0.0.0/8')),
|
|
|
|
array(array('::ffff:0:0/96'), array('::ffff:0:0/96')),
|
2015-09-07 08:21:10 +01:00
|
|
|
array(array('0.0.0.0/0'), array('0.0.0.0/0')),
|
2012-12-14 10:26:52 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-05 17:52:40 +00:00
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
2012-12-14 10:26:52 +00:00
|
|
|
*/
|
|
|
|
public function testInvalidTypeTrustedProxies()
|
|
|
|
{
|
|
|
|
$processor = new Processor();
|
2014-05-10 23:14:12 +01:00
|
|
|
$configuration = new Configuration(true);
|
2013-01-23 14:18:20 +00:00
|
|
|
$processor->processConfiguration($configuration, array(
|
|
|
|
array(
|
|
|
|
'secret' => 's3cr3t',
|
2014-09-21 19:53:12 +01:00
|
|
|
'trusted_proxies' => 'Not an IP address',
|
|
|
|
),
|
2013-01-23 14:18:20 +00:00
|
|
|
));
|
2012-12-14 10:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-05 17:52:40 +00:00
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
2012-12-14 10:26:52 +00:00
|
|
|
*/
|
|
|
|
public function testInvalidValueTrustedProxies()
|
|
|
|
{
|
|
|
|
$processor = new Processor();
|
2014-05-10 23:14:12 +01:00
|
|
|
$configuration = new Configuration(true);
|
2016-01-25 21:22:29 +00:00
|
|
|
|
2013-01-23 14:18:20 +00:00
|
|
|
$processor->processConfiguration($configuration, array(
|
|
|
|
array(
|
|
|
|
'secret' => 's3cr3t',
|
2014-09-21 19:53:12 +01:00
|
|
|
'trusted_proxies' => array('Not an IP address'),
|
|
|
|
),
|
2013-01-23 14:18:20 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2015-02-26 10:02:40 +00:00
|
|
|
public function testAssetsCanBeEnabled()
|
|
|
|
{
|
|
|
|
$processor = new Processor();
|
|
|
|
$configuration = new Configuration(true);
|
|
|
|
$config = $processor->processConfiguration($configuration, array(array('assets' => null)));
|
|
|
|
|
|
|
|
$defaultConfig = array(
|
2016-02-04 17:27:46 +00:00
|
|
|
'enabled' => true,
|
2016-01-25 21:22:29 +00:00
|
|
|
'version_strategy' => null,
|
2015-02-26 10:02:40 +00:00
|
|
|
'version' => null,
|
|
|
|
'version_format' => '%%s?%%s',
|
|
|
|
'base_path' => '',
|
|
|
|
'base_urls' => array(),
|
|
|
|
'packages' => array(),
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals($defaultConfig, $config['assets']);
|
|
|
|
}
|
|
|
|
|
2016-01-25 21:22:29 +00:00
|
|
|
/**
|
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
|
|
|
* @expectedExceptionMessage You cannot use both "version_strategy" and "version" at the same time under "assets".
|
|
|
|
*/
|
|
|
|
public function testInvalidVersionStrategy()
|
|
|
|
{
|
|
|
|
$processor = new Processor();
|
|
|
|
$configuration = new Configuration(true);
|
|
|
|
$processor->processConfiguration($configuration, array(
|
|
|
|
array(
|
|
|
|
'assets' => array(
|
|
|
|
'base_urls' => '//example.com',
|
|
|
|
'version' => 1,
|
|
|
|
'version_strategy' => 'foo',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
|
|
|
* @expectedExceptionMessage You cannot use both "version_strategy" and "version" at the same time under "assets" packages.
|
|
|
|
*/
|
|
|
|
public function testInvalidPackageVersionStrategy()
|
|
|
|
{
|
|
|
|
$processor = new Processor();
|
|
|
|
$configuration = new Configuration(true);
|
|
|
|
|
|
|
|
$processor->processConfiguration($configuration, array(
|
|
|
|
array(
|
|
|
|
'assets' => array(
|
|
|
|
'base_urls' => '//example.com',
|
|
|
|
'version' => 1,
|
|
|
|
'packages' => array(
|
|
|
|
'foo' => array(
|
|
|
|
'base_urls' => '//example.com',
|
|
|
|
'version' => 1,
|
|
|
|
'version_strategy' => 'foo',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2013-01-23 14:18:20 +00:00
|
|
|
protected static function getBundleDefaultConfig()
|
|
|
|
{
|
|
|
|
return array(
|
2013-02-27 13:12:14 +00:00
|
|
|
'http_method_override' => true,
|
2014-10-22 19:27:13 +01:00
|
|
|
'trusted_proxies' => array(),
|
|
|
|
'ide' => null,
|
|
|
|
'default_locale' => 'en',
|
2015-11-10 23:41:32 +00:00
|
|
|
'csrf_protection' => array(
|
|
|
|
'enabled' => false,
|
|
|
|
),
|
2014-10-26 07:41:27 +00:00
|
|
|
'form' => array(
|
2013-10-09 09:42:58 +01:00
|
|
|
'enabled' => false,
|
|
|
|
'csrf_protection' => array(
|
2015-11-10 23:41:32 +00:00
|
|
|
'enabled' => null, // defaults to csrf_protection.enabled
|
2015-09-04 21:24:52 +01:00
|
|
|
'field_name' => '_token',
|
2013-10-09 09:42:58 +01:00
|
|
|
),
|
|
|
|
),
|
2014-10-22 19:27:13 +01:00
|
|
|
'esi' => array('enabled' => false),
|
2014-10-26 07:46:28 +00:00
|
|
|
'ssi' => array('enabled' => false),
|
2014-10-22 19:27:13 +01:00
|
|
|
'fragments' => array(
|
2013-01-23 14:18:20 +00:00
|
|
|
'enabled' => false,
|
2014-10-22 19:27:13 +01:00
|
|
|
'path' => '/_fragment',
|
2013-01-23 14:18:20 +00:00
|
|
|
),
|
2014-10-22 19:27:13 +01:00
|
|
|
'profiler' => array(
|
|
|
|
'enabled' => false,
|
|
|
|
'only_exceptions' => false,
|
2013-01-23 14:18:20 +00:00
|
|
|
'only_master_requests' => false,
|
2014-10-22 19:27:13 +01:00
|
|
|
'dsn' => 'file:%kernel.cache_dir%/profiler',
|
|
|
|
'collect' => true,
|
2016-02-04 17:27:46 +00:00
|
|
|
'matcher' => array(
|
|
|
|
'enabled' => false,
|
|
|
|
'ips' => array(),
|
|
|
|
),
|
2013-01-23 14:18:20 +00:00
|
|
|
),
|
2014-10-22 19:27:13 +01:00
|
|
|
'translator' => array(
|
|
|
|
'enabled' => false,
|
2015-01-12 11:17:42 +00:00
|
|
|
'fallbacks' => array('en'),
|
2014-11-04 14:29:39 +00:00
|
|
|
'logging' => true,
|
2015-05-05 20:36:55 +01:00
|
|
|
'paths' => array(),
|
2013-01-23 14:18:20 +00:00
|
|
|
),
|
2014-10-22 19:27:13 +01:00
|
|
|
'validation' => array(
|
|
|
|
'enabled' => false,
|
2013-01-23 14:18:20 +00:00
|
|
|
'enable_annotations' => false,
|
2014-10-30 20:17:55 +00:00
|
|
|
'static_method' => array('loadValidatorMetadata'),
|
2013-01-23 14:18:20 +00:00
|
|
|
'translation_domain' => 'validators',
|
2014-10-30 20:17:55 +00:00
|
|
|
'strict_email' => false,
|
2013-01-23 14:18:20 +00:00
|
|
|
),
|
2014-10-22 19:27:13 +01:00
|
|
|
'annotations' => array(
|
2016-06-28 13:49:00 +01:00
|
|
|
'cache' => 'php_array',
|
2013-01-23 14:18:20 +00:00
|
|
|
'file_cache_dir' => '%kernel.cache_dir%/annotations',
|
2016-03-12 17:49:05 +00:00
|
|
|
'debug' => true,
|
2013-01-23 14:18:20 +00:00
|
|
|
),
|
2014-10-22 19:27:13 +01:00
|
|
|
'serializer' => array(
|
2014-09-21 19:53:12 +01:00
|
|
|
'enabled' => false,
|
2014-12-25 03:17:33 +00:00
|
|
|
'enable_annotations' => false,
|
2014-08-21 18:05:54 +01:00
|
|
|
),
|
|
|
|
'property_access' => array(
|
|
|
|
'magic_call' => false,
|
|
|
|
'throw_exception_on_invalid_index' => false,
|
|
|
|
),
|
2015-09-28 12:22:50 +01:00
|
|
|
'property_info' => array(
|
|
|
|
'enabled' => false,
|
|
|
|
),
|
2016-02-04 17:27:46 +00:00
|
|
|
'router' => array(
|
|
|
|
'enabled' => false,
|
|
|
|
'http_port' => 80,
|
|
|
|
'https_port' => 443,
|
|
|
|
'strict_requirements' => true,
|
|
|
|
),
|
|
|
|
'session' => array(
|
|
|
|
'enabled' => false,
|
|
|
|
'storage_id' => 'session.storage.native',
|
|
|
|
'handler_id' => 'session.handler.native_file',
|
|
|
|
'cookie_httponly' => true,
|
|
|
|
'gc_probability' => 1,
|
|
|
|
'save_path' => '%kernel.cache_dir%/sessions',
|
|
|
|
'metadata_update_threshold' => '0',
|
|
|
|
),
|
|
|
|
'request' => array(
|
|
|
|
'enabled' => false,
|
|
|
|
'formats' => array(),
|
|
|
|
),
|
|
|
|
'templating' => array(
|
|
|
|
'enabled' => false,
|
|
|
|
'hinclude_default_template' => null,
|
|
|
|
'form' => array(
|
|
|
|
'resources' => array('FrameworkBundle:Form'),
|
|
|
|
),
|
|
|
|
'engines' => array(),
|
|
|
|
'loaders' => array(),
|
|
|
|
),
|
|
|
|
'assets' => array(
|
|
|
|
'enabled' => false,
|
|
|
|
'version_strategy' => null,
|
|
|
|
'version' => null,
|
|
|
|
'version_format' => '%%s?%%s',
|
|
|
|
'base_path' => '',
|
|
|
|
'base_urls' => array(),
|
|
|
|
'packages' => array(),
|
|
|
|
),
|
2016-04-06 18:53:33 +01:00
|
|
|
'cache' => array(
|
|
|
|
'pools' => array(),
|
2016-04-28 17:07:16 +01:00
|
|
|
'app' => 'cache.adapter.filesystem',
|
2016-05-05 16:37:21 +01:00
|
|
|
'system' => 'cache.adapter.system',
|
2016-04-28 17:07:16 +01:00
|
|
|
'directory' => '%kernel.cache_dir%/pools',
|
|
|
|
'default_redis_provider' => 'redis://localhost',
|
2016-04-06 18:53:33 +01:00
|
|
|
),
|
2016-03-25 15:43:30 +00:00
|
|
|
'workflows' => array(),
|
2013-01-23 14:18:20 +00:00
|
|
|
);
|
2012-12-14 10:26:52 +00:00
|
|
|
}
|
|
|
|
}
|