You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TextTest.php 1.7KB

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. class Twig_Tests_Extension_TextTest extends PHPUnit_Framework_TestCase
  11. {
  12. /** @var TwigEnvironment */
  13. private $env;
  14. public static function setUpBeforeClass()
  15. {
  16. if (!class_exists('Twig_Extensions_Extension_Text')) {
  17. self::markTestSkipped('Unable to find class Twig_Extensions_Extension_Text.');
  18. }
  19. }
  20. public function setUp()
  21. {
  22. $this->env = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
  23. $this->env
  24. ->expects($this->any())
  25. ->method('getCharset')
  26. ->will($this->returnValue('utf-8'))
  27. ;
  28. }
  29. /**
  30. * @dataProvider getTruncateTestData
  31. */
  32. public function testTruncate($input, $length, $preserve, $separator, $expectedOutput)
  33. {
  34. $output = twig_truncate_filter($this->env, $input, $length, $preserve, $separator);
  35. $this->assertEquals($expectedOutput, $output);
  36. }
  37. public function getTruncateTestData()
  38. {
  39. return array(
  40. array('This is a very long sentence.', 2, false, '...', 'Th...'),
  41. array('This is a very long sentence.', 6, false, '...', 'This i...'),
  42. array('This is a very long sentence.', 2, true, '...', 'This...'),
  43. array('This is a very long sentence.', 2, true, '[...]', 'This[...]'),
  44. array('This is a very long sentence.', 23, false, '...', 'This is a very long sen...'),
  45. array('This is a very long sentence.', 23, true, '...', 'This is a very long sentence.'),
  46. );
  47. }
  48. }