From 12042e0880ae1ac7ee94f6f406d3a330df4a1d34 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 28 Jan 2012 17:09:25 +0100 Subject: [PATCH] added some unit tests for random() when charset is not UTF-8 --- test/Twig/Tests/Extension/CoreTest.php | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/test/Twig/Tests/Extension/CoreTest.php b/test/Twig/Tests/Extension/CoreTest.php index 49abdfb..45f90bb 100644 --- a/test/Twig/Tests/Extension/CoreTest.php +++ b/test/Twig/Tests/Extension/CoreTest.php @@ -80,4 +80,16 @@ class Twig_Tests_Extension_CoreTest extends PHPUnit_Framework_TestCase { twig_random(new Twig_Environment(), array()); } + + public function testRandomFunctionOnNonUTF8String() + { + $twig = new Twig_Environment(); + $twig->setCharset('ISO-8859-1'); + + $text = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8'); + for ($i = 0; $i < 30; $i++) { + $rand = twig_random($twig, $text); + $this->assertTrue(in_array(twig_convert_encoding($rand, 'UTF-8', 'ISO-8859-1'), array('Ä', 'é'), true)); + } + } } -- 1.7.2.5