Skip to content

Commit

Permalink
Adhoc parts. Flag is still treated as a special attribute (and append…
Browse files Browse the repository at this point in the history
…ed to parent)
  • Loading branch information
zzgab committed Feb 27, 2017
1 parent 15c4982 commit 5059430
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/figdice/classes/ViewElementTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,16 @@ private function buildXMLAttributesString(Context $context) {
foreach($attributes as $attribute=>$value) {

if( ! $context->view->isFigAttribute($attribute)) {
// a flag attribute is to be processed differently because it isn't a key=value pair.
if ( !($value instanceof Flag) ) {
// a flag attribute is to be processed differently because
// it isn't a key=value pair.

if ($value instanceof Flag) {
// Flag attribute: there is no value. We print only the name of the flag.
$result .= " $attribute";
}


else {

// We're potentially in presence of:
// - a plain scalar
Expand Down Expand Up @@ -327,17 +335,9 @@ private function buildXMLAttributesString(Context $context) {

}
$value = $combined;
}



if ($value instanceof Flag) {
// Flag attribute: there is no value. We print only the name of the flag.
$result .= " $attribute";
}
else {
$result .= " $attribute=\"$value\"";
}
}
}

}
Expand Down
57 changes: 57 additions & 0 deletions test/CacheTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

use figdice\View;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamWrapper;

class CacheTest extends PHPUnit_Framework_TestCase
{
public function testAdhocAndFlagAreCachedAndRestored()
{
vfsStream::setup('root');

$template = <<<ENDTEMPLATE
<html>
<div class="one {/one/more} three" id="mydiv">
<fig:m fig:macro="mymacro">
<title fig:text="param1"></title>
</fig:m>
<span fig:call="mymacro" param1="'abc'"/>
</div>
<input name="email" fig:void="true">
<fig:attr name="required" flag="1" />
</input>
</html>
ENDTEMPLATE;

vfsStream::newFile('template.html')->withContent($template)->at(vfsStreamWrapper::getRoot());
$view = new View();
$view->setCachePath(vfsStream::url('root'));
$view->mount('one', ['more' => 'two']);
$view->loadFile(vfsStream::url('root/template.html'));
$output = $view->render();

$expected = <<<EXPECTED
<html>
<div class="one two three" id="mydiv">
<title>abc</title>
</div>
<input name="email" required>
</html>
EXPECTED;

$this->assertEquals($expected, $output);

// Now remove the original file
unlink(vfsStream::url('root/template.html'));
$view = new View();
$view->setCachePath(vfsStream::url('root'));
$view->mount('one', ['more' => 'two']);
$view->loadFile(vfsStream::url('root/template.html'));
$output = $view->render();

$this->assertEquals($expected, $output);
}
}

0 comments on commit 5059430

Please sign in to comment.