FormExtensionTableLayoutTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\AbstractTableLayoutTest;
  17. use Symfony\Tests\Bridge\Twig\Extension\Fixtures\StubTranslator;
  18. use Symfony\Tests\Bridge\Twig\Extension\Fixtures\StubFilesystemLoader;
  19. class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
  20. {
  21. protected $extension;
  22. protected function setUp()
  23. {
  24. if (!class_exists('Twig_Environment')) {
  25. $this->markTestSkipped('Twig is not available.');
  26. }
  27. parent::setUp();
  28. $loader = new StubFilesystemLoader(array(
  29. __DIR__.'/../../../../../../src/Symfony/Bridge/Twig/Resources/views/Form',
  30. __DIR__,
  31. ));
  32. $this->extension = new FormExtension(array(
  33. 'form_table_layout.html.twig',
  34. 'custom_widgets.html.twig',
  35. ));
  36. $environment = new \Twig_Environment($loader);
  37. $environment->addExtension($this->extension);
  38. $environment->addExtension(new TranslationExtension(new StubTranslator()));
  39. $this->extension->initRuntime($environment);
  40. }
  41. protected function tearDown()
  42. {
  43. parent::tearDown();
  44. $this->extension = null;
  45. }
  46. protected function renderEnctype(FormView $view)
  47. {
  48. return (string) $this->extension->renderEnctype($view);
  49. }
  50. protected function renderLabel(FormView $view, $label = null, array $vars = array())
  51. {
  52. return (string) $this->extension->renderLabel($view, $label, $vars);
  53. }
  54. protected function renderErrors(FormView $view)
  55. {
  56. return (string) $this->extension->renderErrors($view);
  57. }
  58. protected function renderWidget(FormView $view, array $vars = array())
  59. {
  60. return (string) $this->extension->renderWidget($view, $vars);
  61. }
  62. protected function renderRow(FormView $view, array $vars = array())
  63. {
  64. return (string) $this->extension->renderRow($view, $vars);
  65. }
  66. protected function renderRest(FormView $view, array $vars = array())
  67. {
  68. return (string) $this->extension->renderRest($view, $vars);
  69. }
  70. protected function setTheme(FormView $view, array $themes)
  71. {
  72. $this->extension->setTheme($view, $themes);
  73. }
  74. }