ConditionalTest.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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_Expression_ConditionalTest extends Twig_Tests_Node_TestCase
  12. {
  13. /**
  14. * @covers Twig_Node_Expression_Conditional::__construct
  15. */
  16. public function testConstructor()
  17. {
  18. $expr1 = new Twig_Node_Expression_Constant(1, 0);
  19. $expr2 = new Twig_Node_Expression_Constant(2, 0);
  20. $expr3 = new Twig_Node_Expression_Constant(3, 0);
  21. $node = new Twig_Node_Expression_Conditional($expr1, $expr2, $expr3, 0);
  22. $this->assertEquals($expr1, $node->getNode('expr1'));
  23. $this->assertEquals($expr2, $node->getNode('expr2'));
  24. $this->assertEquals($expr3, $node->getNode('expr3'));
  25. }
  26. /**
  27. * @covers Twig_Node_Expression_Conditional::compile
  28. * @dataProvider getTests
  29. */
  30. public function testCompile($node, $source, $environment = null)
  31. {
  32. parent::testCompile($node, $source, $environment);
  33. }
  34. public function getTests()
  35. {
  36. $tests = array();
  37. $expr1 = new Twig_Node_Expression_Constant(1, 0);
  38. $expr2 = new Twig_Node_Expression_Constant(2, 0);
  39. $expr3 = new Twig_Node_Expression_Constant(3, 0);
  40. $node = new Twig_Node_Expression_Conditional($expr1, $expr2, $expr3, 0);
  41. $tests[] = array($node, '((1) ? (2) : (3))');
  42. return $tests;
  43. }
  44. }