* @author Kornel LesiƄski * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License * @version SVN: $Id: MetalSlotTest.php 1001 2010-10-23 13:32:47Z kornel $ * @link http://phptal.org/ */ require_once 'I18NDummyTranslator.php'; class MetalSlotTest extends PHPTAL_TestCase { function testSimple() { $tpl = $this->newPHPTAL('input/metal-slot.01.html'); $res = normalize_html($tpl->execute()); $exp = normalize_html_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(normalize_html('top=top
inusemacro=inusemacro
inmacro=inmacro
infillslot=infillslot
/inmacro=inmacro
/inusemacro=inusemacro
/top=top'), normalize_html($tpl->execute()), $tpl->getCodePath()); } function testPreservesTopmostContext() { $tpl = $this->newPHPTAL(); $tpl->var = "topmost"; $tpl->setSource('
empty slot
var = ${var}
'); $this->assertEquals(normalize_html('
var = topmost
'), normalize_html($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(normalize_html('
test1 macro value:
test2 macro value:foo bar baz
'), normalize_html($tpl->execute()), $tpl->getCodePath()); } function testRecursiveFill() { $tpl = $this->newPHPTAL('input/metal-slot.02.html'); $res = normalize_html($tpl->execute()); $exp = normalize_html_file('output/metal-slot.02.html'); $this->assertEquals($exp, $res, $tpl->getCodePath()); } function testRecursiveUnFill() { $this->markTestSkipped("Known bug, won't get fixed for 1.2.2"); $tpl = $this->newPHPTAL()->setSource('
OK
ERROR
'); $res = normalize_html($tpl->execute()); $this->assertEquals('
OK
', $res, $tpl->getCodePath()); } function testBlock() { $tpl = $this->newPHPTAL('input/metal-slot.03.html'); $res = normalize_html($tpl->execute()); $exp = normalize_html_file('output/metal-slot.03.html'); $this->assertEquals($exp, $res); } function testFillAndCondition() { $tpl = $this->newPHPTAL('input/metal-slot.04.html'); $tpl->fillit = true; $res = normalize_html($tpl->execute()); $exp = normalize_html_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(normalize_html('

translatedyouaswell

'), normalize_html($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); } function testSlotBug() { $tpl = $this->newPHPTAL()->setSource(<<
OK subpage filled page/valuebis
page/value:FAIL unfilled page/value page/valuebis:FAIL unfilled page/valuebis FAIL unused invalid subpage/valuebis
OK toplevel-filled page/value
HTML ); $this->assertEquals( normalize_html('
page/value:
OK toplevel-filled page/value
page/valuebis:
OK subpage filled page/valuebis
'), normalize_html($tpl->execute()), $tpl->getCodePath()); } function testNestedSlots() { $tpl = $this->newPHPTAL()->setSource('
First Level Second Level
'); $this->assertEquals(normalize_html('
First Level
Second Level
'), normalize_html($tpl->execute())); } function testResetDefault() { $tpl = $this->newPHPTAL()->setSource('

The macro : the slot

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

The macro : the slot

The macro : something else

The macro : the slot

'),normalize_html($res)); } }