Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/Zend/Navigation/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public function valid()
*/
public function hasChildren()
{
return $this->hasPages();
return ($this->valid() && $this->current()->hasPages());
}

/**
Expand Down
127 changes: 127 additions & 0 deletions tests/ZendTest/Navigation/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,133 @@ public function testRecursiveIteration()
$this->assertEquals($expected, $actual);
}

/**
*
* @see 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");
}

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 tests/ZendTest/Navigation/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();
}
}