* @author Kornel LesiƄski * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License * @version SVN: $Id: MetalSlotTest.php 710 2009-09-07 11:46:50Z kornel $ * @link http://phptal.org/ */ require_once dirname(__FILE__)."/config.php"; class MetalSlotTest extends PHPTAL_TestCase { function testSimple() { $tpl = $this->newPHPTAL('input/metal-slot.01.html'); $res = trim_string($tpl->execute()); $exp = trim_file('output/metal-slot.01.html'); $this->assertEquals($exp, $res); } function testPreservesContext() { $tpl = $this->newPHPTAL('input/metal-slot.05.html'); $tpl->var = "top"; $this->assertEquals(trim_string('top=top
inusemacro=inusemacro
inmacro=inmacro
infillslot=infillslot
/inmacro=inmacro
/inusemacro=inusemacro
/top=top'), trim_string($tpl->execute()), $tpl->getCodePath()); } function testPreservesTopmostContext() { $tpl = $this->newPHPTAL(); $tpl->var = "topmost"; $tpl->setSource('
empty slot
var = ${var}
'); $this->assertEquals(trim_string('
var = topmost
'),trim_string($tpl->execute()), $tpl->getCodePath()); } function testRecursiveFillSimple() { $tpl = $this->newPHPTAL(); $tpl->setSource('
test1 macro value:a value should go here
test2 macro value:a value should go here
foo bar baz
'); $this->assertEquals(trim_string('
test1 macro value:
test2 macro value:foo bar baz
'), trim_string($tpl->execute()), $tpl->getCodePath()); } function testRecusiveFill() { $tpl = $this->newPHPTAL('input/metal-slot.02.html'); $res = trim_string($tpl->execute()); $exp = trim_file('output/metal-slot.02.html'); $this->assertEquals($exp, $res, $tpl->getCodePath()); } function testBlock() { $tpl = $this->newPHPTAL('input/metal-slot.03.html'); $res = trim_string($tpl->execute()); $exp = trim_file('output/metal-slot.03.html'); $this->assertEquals($exp, $res); } function testFillAndCondition() { $tpl = $this->newPHPTAL('input/metal-slot.04.html'); $tpl->fillit = true; $res = trim_string($tpl->execute()); $exp = trim_file('output/metal-slot.04.html'); $this->assertEquals($exp, $res); } function testFillWithi18n() { $tpl = $this->newPHPTAL(); $tpl->setSource('

translatemetoo

test

'); $tr = new DummyTranslator(); $tr->setTranslation("translateme","translatedyou"); $tr->setTranslation("translatemetoo","translatedyouaswell"); $tpl->setTranslator($tr); $this->assertEquals(trim_string('

translatedyouaswell

'),trim_string($tpl->execute()), $tpl->getCodePath()); } /** * this is violation of TAL specification, but needs to work for backwards compatibility */ function testFillPreservedAcrossCalls() { $tpl = $this->newPHPTAL(); $tpl->setSource('foocontent'); $tpl->execute(); $tpl->setSource('FAIL'); $this->assertEquals('foocontent', $tpl->execute()); } /** * this is violation of TAL specification, but needs to work for backwards compatibility */ function testFillPreservedAcrossCalls2() { $tpl = $this->newPHPTAL(); $tpl->setSource('

foocontent

'); $tpl->execute(); $tpl->setSource('

FAIL

'); $this->assertEquals('

foocontent

', $tpl->execute()); } function testUsesCallbackForLargeSlots() { $tpl = $this->newPHPTAL(); $tpl->setSource(' stuff stuff stuff '); $res = $tpl->execute(); $this->assertGreaterThan(PHPTAL_Php_Attribute_METAL_FillSlot::CALLBACK_THRESHOLD,strlen($res)); $tpl_php_source = file_get_contents($tpl->getCodePath()); $this->assertNotContains("fillSlot(",$tpl_php_source); $this->assertContains("fillSlotCallback(",$tpl_php_source); } function testUsesBufferForSmallSlots() { $tpl = $this->newPHPTAL(); $tpl->setSource(' stuff lots of stuff stuff lots of stuff stuff lots of stuff stuff lots of stuff stuff lots of stuff stuff lots of stuff '); $tpl->execute(); $tpl_php_source = file_get_contents($tpl->getCodePath()); $this->assertNotContains("fillSlotCallback(",$tpl_php_source); $this->assertContains("fillSlot(",$tpl_php_source); } }