DebugTest.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 TWIG_LIB_DIR.'/../test/Twig/Tests/Node/TestCase.php';
  11. class Twig_Tests_Node_DebugTest extends Twig_Tests_Node_TestCase
  12. {
  13. /**
  14. * @covers Twig_Node_Debug::__construct
  15. */
  16. public function testConstructor()
  17. {
  18. $expr = new Twig_Node_Expression_Name('foo', 0);
  19. $node = new Twig_Extensions_Node_Debug($expr, 0);
  20. $this->assertEquals($expr, $node->getNode('expr'));
  21. $node = new Twig_Extensions_Node_Debug(null, 0);
  22. $this->assertEquals(null, $node->getNode('expr'));
  23. }
  24. /**
  25. * @covers Twig_Node_Debug::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. $tests = array();
  35. $tests[] = array(new Twig_Extensions_Node_Debug(null, 0), <<<EOF
  36. if (\$this->env->isDebug()) {
  37. \$vars = array();
  38. foreach (\$context as \$key => \$value) {
  39. if (!\$value instanceof Twig_Template) {
  40. \$vars[\$key] = \$value;
  41. }
  42. }
  43. var_dump(\$vars);
  44. }
  45. EOF
  46. );
  47. $expr = new Twig_Node_Expression_Name('foo', 0);
  48. $node = new Twig_Extensions_Node_Debug($expr, 0);
  49. $tests[] = array($node, sprintf(<<<EOF
  50. if (\$this->env->isDebug()) {
  51. var_dump(%s);
  52. }
  53. EOF
  54. , $this->getVariableGetter('foo')));
  55. return $tests;
  56. }
  57. }