${var} $${var} $$${var} $$$${var}
'); $this->assertEquals(normalize_html('val< ${var} $val< $${var}
'), normalize_html($tpl->execute())); } function testUnescapeString() { $tpl = $this->newPHPTAL(); $tpl->var = 'val<'; $tpl->setSource(''); $this->assertEquals(normalize_html('
val< ${var} $val< $${var}
'), normalize_html($tpl->execute())); } function testUnescapeStructure() { $tpl = $this->newPHPTAL(); $tpl->var = 'val${structure var} $${structure var} $$${structure var} $$$${structure var}
'); $this->assertEquals(normalize_html('
val
${var+1} $${var+1} $$${var+1} $$$${var+1}
'); $this->assertEquals(normalize_html('2 ${var+1} $2 $${var+1}
'), normalize_html($tpl->execute())); } public function testPHPBlock() { $tpl = $this->newPHPTAL(); $tpl->setSource('test"; ?>testtest
'); $this->assertEquals('test
test"); ?>testtest
'); $this->assertEquals('test
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()); } function testPreservesNewline() { $tpl = $this->newPHPTAL()->setSource(' ${variable1 | string:Line 1}${php:\'foo bar\'}
')->execute(); $this->assertEquals('foo bar
', $res); $res = $this->newPHPTAL()->setSource('${php:\'foo\' . substr(\'barz\' , 0,3)}
')->execute(); $this->assertEquals('foobar
', $res); } function testMultilineInterpolation() { $res = $this->newPHPTAL()->setSource('${string:foo bar}
')->execute(); $this->assertEquals('foo bar
', $res); $res = $this->newPHPTAL()->setSource('${structure string:foo bar}
')->execute(); $this->assertEquals('foo bar
', $res); } function testTagsBreakTALES() { $res = $this->newPHPTAL()->setSource('${foo
bar}
${foo
bar}
${structure string:foo<br />bar}
')->execute(); $this->assertEquals('foo
bar