* @author Kornel LesiƄski * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License * @version SVN: $Id: TalAttributesTest.php 888 2010-06-08 09:48:33Z kornel $ * @link http://phptal.org/ */ class TalAttributesTest extends PHPTAL_TestCase { function testSimple() { $tpl = $this->newPHPTAL('input/tal-attributes.01.html'); $res = normalize_html($tpl->execute()); $exp = normalize_html_file('output/tal-attributes.01.html'); $this->assertEquals($exp, $res); } function testWithContent() { $tpl = $this->newPHPTAL('input/tal-attributes.02.html'); $tpl->spanClass = 'dummy'; $res = normalize_html($tpl->execute()); $exp = normalize_html_file('output/tal-attributes.02.html'); $this->assertEquals($exp, $res); } function testMultiples() { $tpl = $this->newPHPTAL('input/tal-attributes.03.html'); $tpl->spanClass = 'dummy'; $res = normalize_html($tpl->execute()); $exp = normalize_html_file('output/tal-attributes.03.html'); $this->assertEquals($exp, $res); } function testChain() { $tpl = $this->newPHPTAL('input/tal-attributes.04.html'); $tpl->spanClass = 'dummy'; $res = normalize_html($tpl->execute()); $exp = normalize_html_file('output/tal-attributes.04.html'); $this->assertEquals($exp, $res); } function testMultipleChains() { $tpl = $this->newPHPTAL('input/tal-attributes.05.html'); $tpl->spanClass = 'dummy'; $res = normalize_html($tpl->execute()); $exp = normalize_html_file('output/tal-attributes.05.html'); $this->assertEquals($exp, $res); } function testEncoding() { $tpl = $this->newPHPTAL('input/tal-attributes.06.html'); $tpl->href = "http://www.test.com/?foo=bar&buz=biz&title = 'bla bla '; $res = $tpl->execute(); $res = normalize_html($res); $exp = normalize_html_file('output/tal-attributes.06.html'); $this->assertEquals($exp, $res); } function testZeroValues() { $tpl = $this->newPHPTAL('input/tal-attributes.07.html'); $tpl->href1 = 0; $tpl->href2 = 0; $tpl->href3 = 0; $res = normalize_html($tpl->execute()); $exp = normalize_html_file('output/tal-attributes.07.html'); $this->assertEquals($exp, $res); } function testEmpty() { $src = << EOT; $exp = << EOT; $tpl = $this->newPHPTAL(); $tpl->setSource($src, __FILE__); $tpl->nullv = null; $tpl->falsev = false; $tpl->emptystrv = ''; $tpl->zerov = 0; $res = $tpl->execute(); $this->assertEquals($exp, $res); } function testSingleQuote() { $exp = normalize_html_file('output/tal-attributes.08.html'); $tpl = $this->newPHPTAL('input/tal-attributes.08.html'); $res = $tpl->execute(); $this->assertEquals($exp, $res); } function testStructure() { $exp = normalize_html_file('output/tal-attributes.09.html'); $tpl = $this->newPHPTAL('input/tal-attributes.09.html'); $tpl->value = "return confirm('helexecute(); $this->assertEquals($exp, $res); } function testChainedStructure() { $exp = normalize_html_file('output/tal-attributes.10.html'); $tpl = $this->newPHPTAL('input/tal-attributes.10.html'); $tpl->value1 = false; $tpl->value2 = "return confirm('helexecute(); $this->assertEquals($exp, $res); } function testNothingValue() { $tpl = $this->newPHPTAL(); $tpl->setSource('

'); $res = $tpl->execute(); $this->assertEquals($res, '

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

'); $res = $tpl->execute(); $this->assertEquals('

', $res); } function testNULLValueNoAlternative() { $tpl = $this->newPHPTAL(); $tpl->setSource('

'); $res = $tpl->execute(); $this->assertEquals('

', $res); } function testNULLValueReversed() { $tpl = $this->newPHPTAL(); $tpl->setSource('

'); $res = $tpl->execute(); $this->assertEquals('

', $res); } function testEmptyValue() { $tpl = $this->newPHPTAL(); $tpl->setSource('

'); $res = $tpl->execute(); $this->assertEquals('

', $res); } function testSemicolon() { $tpl = $this->newPHPTAL(); $tpl->setSource('

'); $res = $tpl->execute(); $this->assertEquals($res, '

'a;b;;c;;;d

'); } //TODO: test xhtml boolean attributes (currently tested in 'old' tests) } function phptal_tales_null($code, $nothrow) { return 'NULL'; }