MacroTest.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. require_once dirname(__FILE__).'/TestCase.php';
  11. class Twig_Tests_Node_MacroTest extends Twig_Tests_Node_TestCase
  12. {
  13. /**
  14. * @covers Twig_Node_Macro::__construct
  15. */
  16. public function testConstructor()
  17. {
  18. $body = new Twig_Node_Text('foo', 0);
  19. $arguments = new Twig_Node(array(new Twig_Node_Expression_Name('foo', 0)), array(), 0);
  20. $node = new Twig_Node_Macro('foo', $body, $arguments, 0);
  21. $this->assertEquals($body, $node->getNode('body'));
  22. $this->assertEquals($arguments, $node->getNode('arguments'));
  23. $this->assertEquals('foo', $node->getAttribute('name'));
  24. }
  25. /**
  26. * @covers Twig_Node_Macro::compile
  27. * @dataProvider getTests
  28. */
  29. public function testCompile($node, $source, $environment = null)
  30. {
  31. parent::testCompile($node, $source, $environment);
  32. }
  33. public function getTests()
  34. {
  35. $body = new Twig_Node_Text('foo', 0);
  36. $arguments = new Twig_Node(array(new Twig_Node_Expression_Name('foo', 0)), array(), 0);
  37. $node = new Twig_Node_Macro('foo', $body, $arguments, 0);
  38. return array(
  39. array($node, <<<EOF
  40. public function getfoo(\$foo = null)
  41. {
  42. \$context = array_merge(\$this->env->getGlobals(), array(
  43. "foo" => \$foo,
  44. ));
  45. ob_start();
  46. try {
  47. echo "foo";
  48. } catch(Exception \$e) {
  49. ob_end_clean();
  50. throw \$e;
  51. }
  52. return ob_get_clean();
  53. }
  54. EOF
  55. ),
  56. );
  57. }
  58. }