Skip to content

Commit

Permalink
Merge pull request #302 from robert-h-curry/7113-nested-controls-brea…
Browse files Browse the repository at this point in the history
…king-last

BUGFIX: Issue #7113: Recalculate itemIteratorCount when popping viewer state.
  • Loading branch information
sminnee committed Apr 12, 2012
2 parents d34d57a + 695ae71 commit 1189322
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/view/SSViewerTest.php
Expand Up @@ -786,6 +786,48 @@ function testUpInLoop(){
)
);
}

/**
* Test that nested loops restore the loop variables correctly when pushing and popping states
*/
function testNestedLoops(){

// Data to run the loop tests on - one sequence of three items, one with child elements
// (of a different size to the main sequence)
$data = new ArrayData(array(
'Foo' => new ArrayList(array(
new ArrayData(array(
'Name' => '1',
'Children' => new ArrayList(array(
new ArrayData(array(
'Name' => 'a'
)),
new ArrayData(array(
'Name' => 'b'
)),
)),
)),
new ArrayData(array(
'Name' => '2',
'Children' => new ArrayList(),
)),
new ArrayData(array(
'Name' => '3',
'Children' => new ArrayList(),
)),
)),
));

// Make sure that including a loop inside a loop will not destroy the internal count of
// items, checked by using "Last"
$this->assertEqualIgnoringWhitespace(
'1ab23last',
$this->render(
'<% loop $Foo %>$Name<% loop Children %>$Name<% end_loop %><% if Last %>last<% end_if %><% end_loop %>',
$data
)
);
}

/**
* @covers SSViewer::get_themes()
Expand Down
1 change: 1 addition & 0 deletions view/SSViewer.php
Expand Up @@ -50,6 +50,7 @@ function getItem(){
function resetLocalScope(){
list($this->item, $this->itemIterator, $this->popIndex, $this->upIndex, $this->currentIndex) = $this->itemStack[$this->localIndex];
array_splice($this->itemStack, $this->localIndex+1);
$this->itemIteratorTotal = $this->itemIterator ? $this->itemIterator->count() : 0;
}

function obj($name){
Expand Down

0 comments on commit 1189322

Please sign in to comment.