FormExtensionDivLayoutTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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\Tests\Bridge\Twig\Extension;
  11. require_once __DIR__.'/Fixtures/StubTranslator.php';
  12. require_once __DIR__.'/Fixtures/StubFilesystemLoader.php';
  13. use Symfony\Component\Form\FormView;
  14. use Symfony\Bridge\Twig\Extension\FormExtension;
  15. use Symfony\Bridge\Twig\Extension\TranslationExtension;
  16. use Symfony\Tests\Component\Form\AbstractDivLayoutTest;
  17. use Symfony\Tests\Bridge\Twig\Extension\Fixtures\StubTranslator;
  18. use Symfony\Tests\Bridge\Twig\Extension\Fixtures\StubFilesystemLoader;
  19. class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
  20. {
  21. protected function setUp()
  22. {
  23. if (!class_exists('Twig_Environment')) {
  24. $this->markTestSkipped('Twig is not available.');
  25. }
  26. parent::setUp();
  27. $loader = new StubFilesystemLoader(array(
  28. __DIR__.'/../../../../../../src/Symfony/Bundle/TwigBundle/Resources/views/Form',
  29. __DIR__,
  30. ));
  31. $this->extension = new FormExtension(array(
  32. 'div_layout.html.twig',
  33. 'custom_widgets.html.twig',
  34. ));
  35. $environment = new \Twig_Environment($loader);
  36. $environment->addExtension($this->extension);
  37. $environment->addExtension(new TranslationExtension(new StubTranslator()));
  38. $this->extension->initRuntime($environment);
  39. }
  40. protected function renderEnctype(FormView $view)
  41. {
  42. return (string)$this->extension->renderEnctype($view);
  43. }
  44. protected function renderLabel(FormView $view, $label = null, array $vars = array())
  45. {
  46. return (string)$this->extension->renderLabel($view, $label, $vars);
  47. }
  48. protected function renderErrors(FormView $view)
  49. {
  50. return (string)$this->extension->renderErrors($view);
  51. }
  52. protected function renderWidget(FormView $view, array $vars = array())
  53. {
  54. return (string)$this->extension->renderWidget($view, $vars);
  55. }
  56. protected function renderRow(FormView $view, array $vars = array())
  57. {
  58. return (string)$this->extension->renderRow($view, $vars);
  59. }
  60. protected function renderRest(FormView $view, array $vars = array())
  61. {
  62. return (string)$this->extension->renderRest($view, $vars);
  63. }
  64. }