Skip to content

Commit

Permalink
unit test to validate the availability of View options in included te…
Browse files Browse the repository at this point in the history
…mplates
  • Loading branch information
zzgab committed Jan 1, 2016
1 parent 0194504 commit dea8efc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/SlotPlugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,23 @@ public function testPlugExecutesInLocalContext()
$rendered = $view->render();
$this->assertEquals(1, trim($rendered));
}

public function testPlugInIncludedFileUsesParentViewOption()
{
// New behaviour for plugs: rendered in local context.
$view = new View();
$view->loadFile(__DIR__.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'slot-in-parent.xml');
$output = trim($view->render());

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

// Legacy behaviour: rendered in final global context
// What we are trying to test is: the plug is defined in an included template, and yet its rendering process
// checks properly that the top view has the GLOBAL_PLUGS defined.
$view = new View([View::GLOBAL_PLUGS]);
$view->loadFile(__DIR__.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'slot-in-parent.xml');
$output = trim($view->render());

$this->assertEquals(12, $output);
}
}
3 changes: 3 additions & 0 deletions test/resources/plug-in-include.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<fig:mute xmlns:fig="http://figdice.org">
<tag fig:mute="true" fig:plug="slot1" fig:text="/someData"/>
</fig:mute>
11 changes: 11 additions & 0 deletions test/resources/slot-in-parent.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<fig:template xmlns:fig="http://figdice.org">

<dummy-tag fig:slot="slot1" />

<!-- give some local data to the included template -->
<fig:mount target="someData" value="11" />
<fig:include file="plug-in-include.xml" />

<!-- overwrite the same key, with new data, which is available in the terminal global context. -->
<fig:mount target="someData" value="12" />
</fig:template>

0 comments on commit dea8efc

Please sign in to comment.