TestTest.php 1.9KB

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 dirname(__FILE__).'/../TestCase.php';
  11. class Twig_Tests_Node_Expression_TestTest extends Twig_Tests_Node_TestCase
  12. {
  13. /**
  14. * @covers Twig_Node_Expression_Test::__construct
  15. */
  16. public function testConstructor()
  17. {
  18. $expr = new Twig_Node_Expression_Constant('foo', 0);
  19. $name = new Twig_Node_Expression_Constant('null', 0);
  20. $args = new Twig_Node();
  21. $node = new Twig_Node_Expression_Test($expr, $name, $args, 0);
  22. $this->assertEquals($expr, $node->getNode('node'));
  23. $this->assertEquals($args, $node->getNode('arguments'));
  24. $this->assertEquals($name, $node->getAttribute('name'));
  25. }
  26. /**
  27. * @covers Twig_Node_Expression_Test::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. $expr = new Twig_Node_Expression_Constant('foo', 0);
  38. $node = new Twig_Node_Expression_Test_Null($expr, 'null', new Twig_Node(array()), 0);
  39. $tests[] = array($node, '(null === "foo")');
  40. return $tests;
  41. }
  42. /**
  43. * @covers Twig_Node_Expression_Filter::compile
  44. * @expectedException Twig_Error_Syntax
  45. * @expectedExceptionMessage The test "nul" does not exist. Did you mean "null" at line 0
  46. */
  47. public function testUnknownTest()
  48. {
  49. $node = $this->createTest(new Twig_Node_Expression_Constant('foo', 0), 'nul');
  50. $node->compile($this->getCompiler());
  51. }
  52. protected function createTest($node, $name, array $arguments = array())
  53. {
  54. return new Twig_Node_Expression_Test($node, $name, new Twig_Node($arguments), 0);
  55. }
  56. }