WebExtensionTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
  11. use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
  12. use Symfony\Bundle\FrameworkBundle\DependencyInjection\WebExtension;
  13. use Symfony\Components\DependencyInjection\ContainerBuilder;
  14. use Symfony\Components\DependencyInjection\ParameterBag\ParameterBag;
  15. class WebExtensionTest extends TestCase
  16. {
  17. public function testConfigLoad()
  18. {
  19. $container = new ContainerBuilder();
  20. $loader = $this->getWebExtension();
  21. $loader->configLoad(array(), $container);
  22. $this->assertEquals('Symfony\\Bundle\\FrameworkBundle\\RequestListener', $container->getParameter('request_listener.class'), '->webLoad() loads the web.xml file if not already loaded');
  23. $container = $this->getContainer();
  24. $loader = $this->getWebExtension();
  25. $loader->configLoad(array('profiler' => true), $container);
  26. $this->assertEquals('Symfony\\Bundle\\FrameworkBundle\\Profiler', $container->getParameter('profiler.class'), '->configLoad() loads the collectors.xml file if not already loaded');
  27. $this->assertFalse($container->getParameterBag()->has('debug.toolbar.class'), '->configLoad() does not load the toolbar.xml file');
  28. $loader->configLoad(array('toolbar' => true), $container);
  29. $this->assertEquals('Symfony\\Components\\HttpKernel\\Profiler\\WebDebugToolbarListener', $container->getParameter('debug.toolbar.class'), '->configLoad() loads the collectors.xml file if the toolbar option is given');
  30. }
  31. public function testTemplatingLoad()
  32. {
  33. $container = $this->getContainer();
  34. $loader = $this->getWebExtension();
  35. $loader->templatingLoad(array(), $container);
  36. $this->assertEquals('Symfony\\Bundle\\FrameworkBundle\\Templating\\Engine', $container->getParameter('templating.engine.class'), '->templatingLoad() loads the templating.xml file if not already loaded');
  37. }
  38. public function testValidationLoad()
  39. {
  40. $container = $this->getContainer();
  41. $loader = $this->getWebExtension();
  42. $loader->configLoad(array('validation' => array('enabled' => true)), $container);
  43. $this->assertEquals('Symfony\Components\Validator\Validator', $container->getParameter('validator.class'), '->validationLoad() loads the validation.xml file if not already loaded');
  44. $this->assertFalse($container->hasDefinition('validator.mapping.loader.annotation_loader'), '->validationLoad() doesn\'t load the annotations service unless its needed');
  45. $loader->configLoad(array('validation' => array('enabled' => true, 'annotations' => true)), $container);
  46. $this->assertTrue($container->hasDefinition('validator.mapping.loader.annotation_loader'), '->validationLoad() loads the annotations service');
  47. }
  48. public function getWebExtension() {
  49. return new WebExtension(array(
  50. 'Symfony\\Framework' => __DIR__ . '/../../../Framework',
  51. ), array(
  52. 'FrameworkBundle',
  53. ));
  54. }
  55. protected function getContainer()
  56. {
  57. return new ContainerBuilder(new ParameterBag(array(
  58. 'kernel.bundle_dirs' => array(),
  59. 'kernel.bundles' => array(),
  60. 'kernel.debug' => false,
  61. )));
  62. }
  63. }