public function myMkdir($dirname) { return $this->mkdir($dirname); } } class myStorage extends sfTemplateStorage { } } set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../../lib/vendor/smarty2'); $t = new lime_test(); $t->diag('->__construct()'); $renderer = new myRenderer(); $t->is(get_class($renderer->getSmarty()), 'Smarty', '->__construct() creates an instance of "Smarty" automatically'); $renderer = new myRenderer(new mySmarty()); $t->is(get_class($renderer->getSmarty()), 'mySmarty', '->__construct() uses the specified instance of "mySmarty"'); $t->diag('->evaluate()'); $fixtureDir = realpath(dirname(__FILE__) . '/../fixtures'); $smarty = new mySmarty(); $renderer = new myRenderer($smarty); $smarty->compile_dir = '/tmp'; $smarty->cache_dir = '/tmp'; $t->is($renderer->evaluate(new sfTemplateStorageString('Kousuke')), 'Kousuke', '->evaluate() returns string from the sfTemplateStorageString'); $t->is($renderer->evaluate(new sfTemplateStorageFile($fixtureDir . '/template/smarty.tpl')), trim(file_get_contents($fixtureDir . '/template/smarty.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'); $t->is($renderer->evaluate(new myStorage('invalid')), false, '->evaluate() returns false if the specified storage is not valid'); $t->diag('->mkdir()'); $dirPath = '/tmp/' . md5(__FILE__ . time()); $renderer->myMkdir($dirPath); $t->is(is_writable($dirPath), true, '->mkdir() creates writable directory'); $t->is($renderer->myMkdir($dirPath), true, '->mkdir() returns true if the specified directory is exists');
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');