Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/zendframework/zendframework#6825-zend-navigation…
Browse files Browse the repository at this point in the history
…-recursive-iterator-compatibility' into develop

Close zendframework/zendframework#6825
Close zendframework/zendframework#4517
Forward port zendframework/zendframework#6825
Forward port zendframework/zendframework#4517
  • Loading branch information
Ocramius committed Nov 22, 2014
168 parents ad732a4 + 738f604 + a2b81c6 + 5711b49 + db8e36b + 9a865bc + 27420a4 + 2e7e46b + f51e1ec + e6b286e + d5c10b6 + 0eabc04 + fed2583 + af2d845 + e8e4ce2 + f4be937 + 9323faa + 65deb5a + d5a4f17 + 94b36e8 + 62824a2 + 6378cbe + a10281c + cd0ff39 + 02e8122 + a667dd4 + 02ccc35 + 7d61487 + ab2f663 + a27ca10 + 75af0e5 + 24f498b + d2dd157 + 6c759d8 + 51b0320 + aabe1c0 + e76b67c + 5d85a78 + d285b08 + c5df6b0 + ff58ff4 + 5675884 + a55ead5 + 47eb5a8 + a36e34a + 3e520ad + 7b0d374 + 461c28b + 3890e69 + 316384e + 1431343 + debad5a + 1680741 + 4497a00 + bb6633a + 6b7ed03 + 35fcae3 + 0737e9d + c31bf4c + 918649e + ecbe771 + b4124fc + f4e1da0 + a8c70a8 + 50d3c5d + 79180fa + f6f9386 + 8ed6590 + d79a4a4 + 3958052 + eae6146 + 1cc7a46 + 1d9542f + a22d6e2 + 3496b67 + 9398e77 + 687d980 + 900dc7d + 21f6363 + 0eeb6ff + 8c442a3 + adf1f8e + c2ceb18 + 9b17a1c + d5dab4a + 346a62a + 9808633 + bdeec54 + 1a2506a + f5f3d02 + b623064 + 4338bf4 + bdababf + 4054000 + 4449c16 + d3d8b33 + 8427cf8 + 8d162ec + a988e9a + 3e9d597 + ee93c08 + 9d3ce53 + f04a59c + 0c3f2de + a654383 + 502d937 + 93350ca + 23a0ccc + 15dc071 + 6ca79e9 + 7645850 + 7b0843e + b9f38cc + 53d4205 + 0ba91ba + 7ad75c4 + 35376fd + e6713be + b15c871 + 4121ed2 + 905626d + 529973a + e28e80a + b64275a + 2f43075 + 05dea5f + b0f56ea + a0ae2ac + 8b01bd8 + fc7acfc + 87b1ffc + c00475b + 6d05c34 + 2f2787b + 229c668 + c164e00 + e5c1ff6 + 5023ed3 + 3c689b8 + 789b92c + ae927c2 + 7741eac + ab3bdcd + 6c02989 + 0d17da2 + 1035d13 + 361c1cf + b31816b + 0102405 + 84330e4 + 50b28a7 + 196892e + 55ecf0a + cdf2159 + 97a5f0f + 2951d73 + bbfc15c + 7aff06a + 2ec87c8 + 9fd7105 + 090f966 + 295dff4 + d43b026 + 827fd02 + 5559cd9 + cfb3de6 + 80fffc8 + c5d55c3 commit acb4607
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public function valid()
*/
public function hasChildren()
{
return $this->hasPages();
return $this->valid() && $this->current()->hasPages();
}

/**
Expand Down
135 changes: 135 additions & 0 deletions test/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,141 @@ public function testRecursiveIteration()
$this->assertEquals($expected, $actual);
}

/**
* @group 6825
* @group 4517
* @group 3211
*
* @link https://github.com/zendframework/zf2/issues/3211
*/
public function testHasChildrenCompatibility()
{
$nav = new Navigation\Navigation(array(
array(
'label' => 'Page 1',
'uri' => '#',
'pages' => array(
array(
'label' => 'Page 1.1',
'uri' => '#',
'pages' => array(
array(
'label' => 'Page 1.1.1',
'uri' => '#'
),
array(
'label' => 'Page 1.1.2',
'uri' => '#'
)
)
),
array(
'label' => 'Page 1.2',
'uri' => '#'
)
)
),
array(
'label' => 'Page 2',
'uri' => '#',
'pages' => array(
array(
'label' => 'Page 2.1',
'uri' => '#'
)
)
),
array(
'label' => 'Page 3',
'uri' => '#'
)
));

$page1 = $nav->findOneBy('label', 'Page 1');
$this->assertTrue($page1->hasChildren(), "page1's first child has children 1.1.1 1.1.2");

$page2 = $nav->findOneBy('label', 'Page 2');
$this->assertFalse($page2->hasChildren(), "page2's first child doesn't have children");
}

/**
* @group 6825
* @group 4517
* @group 3211
*/
public function testDetailedRecursiveIteration()
{
$nav = new Navigation\Navigation(array(
array(
'label' => 'Page 1',
'uri' => '#',
'pages' => array(
array(
'label' => 'Page 1.1',
'uri' => '#',
'pages' => array(
array(
'label' => 'Page 1.1.1',
'uri' => '#'
),
array(
'label' => 'Page 1.1.2',
'uri' => '#'
)
)
),
array(
'label' => 'Page 1.2',
'uri' => '#'
)
)
),
array(
'label' => 'Page 2',
'uri' => '#',
'pages' => array(
array(
'label' => 'Page 2.1',
'uri' => '#'
)
)
),
array(
'label' => 'Page 3',
'uri' => '#'
)
));

$expected = array(
'beginIteration',
'Page 1',
'beginChildren',
'Page 1.1',
'beginChildren',
'Page 1.1.1',
'Page 1.1.2',
'endChildren',
'Page 1.2',
'endChildren',
'Page 2',
'beginChildren',
'Page 2.1',
'endChildren',
'Page 3',
'endIteration',
);

$iterator = new TestAsset\RecursiveIteratorIterator($nav, \RecursiveIteratorIterator::SELF_FIRST);
$iterator->logger = array();
$iterator->rewind();
//#4517 logging with walking through RecursiveIterator
while ($iterator->valid()) {
$iterator->current();
$iterator->next();
}
$this->assertEquals($expected, $iterator->logger);
}

public function testSettingPageOrderShouldUpdateContainerOrder()
{
$nav = new Navigation\Navigation(array(
Expand Down
44 changes: 44 additions & 0 deletions test/TestAsset/RecursiveIteratorIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Navigation\TestAsset;

class RecursiveIteratorIterator extends \RecursiveIteratorIterator
{
/**
*
* @var \ArrayAccess|array
*/
public $logger = array();

public function beginIteration()
{
$this->logger[] = 'beginIteration';
}

public function endIteration()
{
$this->logger[] = 'endIteration';
}

public function beginChildren()
{
$this->logger[] = 'beginChildren';
}

public function endChildren()
{
$this->logger[] = 'endChildren';
}

public function current()
{
$this->logger[] = parent::current()->getLabel();
}
}

0 comments on commit acb4607

Please sign in to comment.