setCharset() public method

public setCharset ( $charset )
Esempio n. 1
0
 public function testReverseFilterOnNonUTF8String()
 {
     $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->setCharset('ISO-8859-1');
     $input = iconv('UTF-8', 'ISO-8859-1', 'Äé');
     $output = iconv('ISO-8859-1', 'UTF-8', twig_reverse_filter($twig, $input));
     $this->assertEquals($output, 'éÄ');
 }
Esempio n. 2
0
 public function testReverseFilterOnNonUTF8String()
 {
     if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) {
         $this->markTestSkipped('needs iconv or mbstring');
     }
     $twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->setCharset('ISO-8859-1');
     $input = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8');
     $output = twig_convert_encoding(twig_reverse_filter($twig, $input), 'UTF-8', 'ISO-8859-1');
     $this->assertEquals($output, 'éÄ');
 }
        return $context;
    }
    class myRenderer extends sfTemplateRendererTwig
    {
        public function getLoader()
        {
            return $this->loader;
        }
        public function getEnvironment()
        {
            return $this->environment;
        }
    }
}
$t = new lime_test();
$t->diag('->__construct()');
$renderer = new myRenderer();
$t->is(get_class($renderer->getLoader()), 'Twig_Loader_String', '->__construct() creates an instance of "Twig_Loader_String" automatically');
$t->is($renderer->getEnvironment()->getCharset(), 'UTF-8', '->__construct() creates an instance of "Twig_Environment" automatically');
$loader = new Twig_Loader_Filesystem('./');
$environment = new Twig_Environment($loader);
$environment->setCharset('Shift_JIS');
$renderer = new myRenderer($loader, $environment);
$t->is(get_class($renderer->getLoader()), 'Twig_Loader_Filesystem', '->__construct() uses the specified instance of "Twig_Loader_Filesystem"');
$t->is($renderer->getEnvironment()->getCharset(), 'Shift_JIS', '->__construct() uses the specified instance of "Twig_Environment"');
$t->diag('->evaluate()');
$fixtureDir = realpath(dirname(__FILE__) . '/../fixtures');
$renderer = new sfTemplateRendererTwig();
$t->is($renderer->evaluate(new sfTemplateStorageString('Kousuke')), 'Kousuke', '->evaluate() returns string from the sfTemplateStorageString');
$t->is($renderer->evaluate(new sfTemplateStorageFile($fixtureDir . '/template/twig.tpl')), file_get_contents($fixtureDir . '/template/twig.tpl'), '->evaluate() returns string from the sfTemplateStorageFile');
$t->is($renderer->evaluate(new sfTemplateStorageString('{{ name }}'), array('name' => 'Ebihara')), 'Ebihara', '->evaluate() returns string from the sfTemplateStorageString and the parameters');