* @author Kornel LesiƄski * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License * @version SVN: $Id: ContentInterpolationTest.php 579 2009-04-25 23:14:46Z kornel $ * @link http://phptal.org/ */ require_once dirname(__FILE__)."/config.php"; class ContentInterpolationTest extends PHPTAL_TestCase { public function testInterpol() { $src = <<\${foo} EOT; $exp = <<foo value EOT; $tpl = $this->newPHPTAL(); $tpl->setSource($src); $tpl->foo = 'foo value'; $res = $tpl->execute(); $this->assertEquals($exp, $res); } public function testInterpol2() { $src = <<\${foo2} x \${structure foo} y \${foo}\${structure foo2} EOT; $exp = <<{foo2 <img />} x foo value y foo value{foo2 } EOT; $tpl = $this->newPHPTAL(); $tpl->setSource($src); $tpl->foo = 'foo value'; $tpl->foo2 = '{foo2 }'; $res = $tpl->execute(); $this->assertEquals($exp, $res); } public function testInterpol3() { $src = <<\${foo}\${foo} EOT; $exp = <<foo valuefoo value EOT; $tpl = $this->newPHPTAL(); $tpl->setSource($src); $tpl->foo = 'foo value'; $res = $tpl->execute(); $this->assertEquals($exp, $res); } public function testNoInterpol() { $src = <<$\${foo} EOT; $exp = <<\${foo} EOT; $tpl = $this->newPHPTAL(); $tpl->setSource($src); $tpl->foo = 'foo value'; $res = $tpl->execute(); $this->assertEquals($exp, $res); } public function testNoInterpolAdv() { $src = <<$$\${foo} EOT; $exp = <<$\${foo} EOT; $tpl = $this->newPHPTAL(); $tpl->setSource($src); $tpl->foo = 'foo value'; $res = $tpl->execute(); $this->assertEquals($exp, $res); } public function testPHPBlock() { $tpl = $this->newPHPTAL(); $tpl->setSource('

test"; ?>testtest

'); $this->assertEquals('

testtest&test

', $tpl->execute()); } public function testPHPBlockShort() { ini_set('short_open_tag',1); if (!ini_get('short_open_tag')) $this->markTestSkipped("PHP is buggy"); $tpl = $this->newPHPTAL(); $tpl->setSource('

test"); ?>testtest

'); $this->assertEquals('

testtest&test

', $tpl->execute()); ini_restore('short_open_tag'); } public function testPHPBlockNoShort() { ini_set('short_open_tag', 0); if (ini_get('short_open_tag')) $this->markTestSkipped("PHP is buggy"); $tpl = $this->newPHPTAL(); $tpl->setSource('

test"); ?>testtest

'); try { // unlike attributes, this isn't going to be escaped, because it gets parsed as a real processing instruction $this->assertEquals('

test"); ?>testtest

', $tpl->execute()); } catch(PHPTAL_ParserException $e) {/* xml ill-formedness error is ok too */} ini_restore('short_open_tag'); } /** * @expectedException PHPTAL_VariableNotFoundException */ function testErrorsThrow() { $tpl = $this->newPHPTAL(); $tpl->setSource('

${error}

'); $tpl->execute(); } /** * @expectedException PHPTAL_VariableNotFoundException */ function testErrorsThrow2() { $tpl = $this->newPHPTAL(); $tpl->setSource('

${error | error}

'); $tpl->execute(); } function testErrorsSilenced() { $tpl = $this->newPHPTAL(); $tpl->setSource('

${error | nothing}

'); $this->assertEquals('

',$tpl->execute()); } function testZeroIsNotEmpty() { $tpl = $this->newPHPTAL(); $tpl->zero = '0'; $tpl->setSource('

${zero | error}

'); $this->assertEquals('

0

',$tpl->execute()); } }