TestTest.php 1.9KB

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