MacroTest.php 1.7KB

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. 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. \$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. }