MacroTest.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. class Twig_Tests_Node_MacroTest extends Twig_Test_NodeTestCase
  11. {
  12. /**
  13. * @covers Twig_Node_Macro::__construct
  14. */
  15. public function testConstructor()
  16. {
  17. $body = new Twig_Node_Text('foo', 1);
  18. $arguments = new Twig_Node(array(new Twig_Node_Expression_Name('foo', 1)), array(), 1);
  19. $node = new Twig_Node_Macro('foo', $body, $arguments, 1);
  20. $this->assertEquals($body, $node->getNode('body'));
  21. $this->assertEquals($arguments, $node->getNode('arguments'));
  22. $this->assertEquals('foo', $node->getAttribute('name'));
  23. }
  24. /**
  25. * @covers Twig_Node_Macro::compile
  26. * @dataProvider getTests
  27. */
  28. public function testCompile($node, $source, $environment = null)
  29. {
  30. parent::testCompile($node, $source, $environment);
  31. }
  32. public function getTests()
  33. {
  34. $body = new Twig_Node_Text('foo', 1);
  35. $arguments = new Twig_Node(array(new Twig_Node_Expression_Name('foo', 1)), array(), 1);
  36. $node = new Twig_Node_Macro('foo', $body, $arguments, 1);
  37. return array(
  38. array($node, <<<EOF
  39. // line 1
  40. public function getfoo(\$foo = null)
  41. {
  42. \$context = \$this->env->mergeGlobals(array(
  43. "foo" => \$foo,
  44. ));
  45. \$blocks = array();
  46. ob_start();
  47. try {
  48. echo "foo";
  49. } catch(Exception \$e) {
  50. ob_end_clean();
  51. throw \$e;
  52. }
  53. return ob_get_clean();
  54. }
  55. EOF
  56. ),
  57. );
  58. }
  59. }