<?php
/**
* PHPTAL templating engine
*
* PHP Version 5
*
* @category HTML
* @package PHPTAL
* @author Laurent Bedubourg <hide@address.com>
* @author Kornel LesiÅski <hide@address.com>
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
* @version SVN: $Id: CommentTest.php 888 2010-06-08 09:48:33Z kornel $
* @link http://phptal.org/
*/
class CommentTest extends PHPTAL_TestCase
{
function testSimple()
{
$source = '<html><!-- \${variable} --></html>';
$tpl = $this->newPHPTAL();
$tpl->setSource($source);
$res = $tpl->execute();
$this->assertEquals($source, $res);
}
function testNoEntities()
{
$source = '<html><!-- <foo> --></html>';
$tpl = $this->newPHPTAL();
$tpl->setSource($source, __FILE__);
$res = $tpl->execute();
$this->assertEquals($source, $res);
}
function testShortComments()
{
$source = '<html><!--><--></html>';
$tpl = $this->newPHPTAL();
$tpl->setSource($source);
$res = $tpl->execute();
$this->assertEquals($source, $res);
}
/**
* @expectedException PHPTAL_ParserException
*/
function testNestedComments()
{
$source = '<html><!--<!--<!--></html>';
$tpl = $this->newPHPTAL();
$tpl->setSource($source);
$res = $tpl->execute();
$this->fail("Ill-formed comment accepted");
}
/**
* @expectedException PHPTAL_ParserException
*/
function testDashedComment()
{
$source = '<html><!--- XML hates you ---></html>';
$tpl = $this->newPHPTAL();
$tpl->setSource($source);
$res = $tpl->execute();
$this->fail("Ill-formed comment accepted");
}
function testSkippedComments()
{
$source = '<html><!--!
removed --><!-- left --><!-- !removed --></html>';
$tpl = $this->newPHPTAL();
$tpl->setSource($source);
$res = $tpl->execute();
$this->assertEquals('<html><!-- left --></html>', $res);
}
function testCStyleComments()
{
$tpl = $this->newPHPTAL();
$src = '<script><!--
// comment
/* comment <tag> */
// comment
--></script>';
$tpl->setSource($src);
$this->assertEquals($src, $tpl->execute());
}
}