FormThemeTokenParserTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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\Bridge\Twig\Tests\TokenParser;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
  13. use Symfony\Bridge\Twig\Node\FormThemeNode;
  14. use Twig\Environment;
  15. use Twig\Node\Expression\ArrayExpression;
  16. use Twig\Node\Expression\ConstantExpression;
  17. use Twig\Node\Expression\NameExpression;
  18. use Twig\Parser;
  19. use Twig\Source;
  20. class FormThemeTokenParserTest extends TestCase
  21. {
  22. /**
  23. * @dataProvider getTestsForFormTheme
  24. */
  25. public function testCompile($source, $expected)
  26. {
  27. $env = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
  28. $env->addTokenParser(new FormThemeTokenParser());
  29. $stream = $env->tokenize(new Source($source, ''));
  30. $parser = new Parser($env);
  31. $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
  32. }
  33. public function getTestsForFormTheme()
  34. {
  35. return array(
  36. array(
  37. '{% form_theme form "tpl1" %}',
  38. new FormThemeNode(
  39. new NameExpression('form', 1),
  40. new ArrayExpression(array(
  41. new ConstantExpression(0, 1),
  42. new ConstantExpression('tpl1', 1),
  43. ), 1),
  44. 1,
  45. 'form_theme'
  46. ),
  47. ),
  48. array(
  49. '{% form_theme form "tpl1" "tpl2" %}',
  50. new FormThemeNode(
  51. new NameExpression('form', 1),
  52. new ArrayExpression(array(
  53. new ConstantExpression(0, 1),
  54. new ConstantExpression('tpl1', 1),
  55. new ConstantExpression(1, 1),
  56. new ConstantExpression('tpl2', 1),
  57. ), 1),
  58. 1,
  59. 'form_theme'
  60. ),
  61. ),
  62. array(
  63. '{% form_theme form with "tpl1" %}',
  64. new FormThemeNode(
  65. new NameExpression('form', 1),
  66. new ConstantExpression('tpl1', 1),
  67. 1,
  68. 'form_theme'
  69. ),
  70. ),
  71. array(
  72. '{% form_theme form with ["tpl1"] %}',
  73. new FormThemeNode(
  74. new NameExpression('form', 1),
  75. new ArrayExpression(array(
  76. new ConstantExpression(0, 1),
  77. new ConstantExpression('tpl1', 1),
  78. ), 1),
  79. 1,
  80. 'form_theme'
  81. ),
  82. ),
  83. array(
  84. '{% form_theme form with ["tpl1", "tpl2"] %}',
  85. new FormThemeNode(
  86. new NameExpression('form', 1),
  87. new ArrayExpression(array(
  88. new ConstantExpression(0, 1),
  89. new ConstantExpression('tpl1', 1),
  90. new ConstantExpression(1, 1),
  91. new ConstantExpression('tpl2', 1),
  92. ), 1),
  93. 1,
  94. 'form_theme'
  95. ),
  96. ),
  97. );
  98. }
  99. }