Skip to content
This repository was archived by the owner on Jan 31, 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
15 changes: 15 additions & 0 deletions src/Helper/Navigation/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ protected function parseContainer(&$container = null)
));
}

// Fallback
if (in_array($container, ['default', 'navigation'], true)) {
// Uses class name
if ($services->has(Navigation\Navigation::class)) {
$container = $services->get(Navigation\Navigation::class);
return;
}

// Uses old service name
if ($services->has('navigation')) {
$container = $services->get('navigation');
return;
}
}

/**
* Load the navigation container from the root service locator
*/
Expand Down
28 changes: 28 additions & 0 deletions test/Helper/Navigation/AbstractHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace ZendTest\View\Helper\Navigation;

use Zend\Navigation\Navigation;
use Zend\ServiceManager\ServiceManager;

class AbstractHelperTest extends AbstractTest
{
/**
Expand Down Expand Up @@ -81,4 +84,29 @@ public function testEventManagerIsNullByDefault()
{
$this->assertNull($this->_helper->getEventManager());
}

public function testFallBackForContainerNames()
{
// Register navigation service with name equal to the documentation
$this->serviceManager->setAllowOverride(true);
$this->serviceManager->setService(
'navigation',
$this->serviceManager->get('Navigation')
);
$this->serviceManager->setAllowOverride(false);

$this->_helper->setServiceLocator($this->serviceManager);

$this->_helper->setContainer('navigation');
$this->assertInstanceOf(
Navigation::class,
$this->_helper->getContainer()
);

$this->_helper->setContainer('default');
$this->assertInstanceOf(
Navigation::class,
$this->_helper->getContainer()
);
}
}
2 changes: 1 addition & 1 deletion test/Helper/Navigation/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
abstract class AbstractTest extends \PHPUnit_Framework_TestCase
{
/**
* @var
* @var ServiceManager
*/
protected $serviceManager;

Expand Down