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

Commit ca9d7b4

Browse files
committed
Merge pull request #110 from froschdesign/hotfix/navigation-fallback
Added fallback for navigation container names in view helpers Conflicts: test/Helper/Navigation/AbstractHelperTest.php
2 parents cb05c31 + eeb1506 commit ca9d7b4

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

src/Helper/Navigation/AbstractHelper.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,21 @@ protected function parseContainer(&$container = null)
251251
));
252252
}
253253

254+
// Fallback
255+
if (in_array($container, ['default', 'navigation'], true)) {
256+
// Uses class name
257+
if ($services->has(Navigation\Navigation::class)) {
258+
$container = $services->get(Navigation\Navigation::class);
259+
return;
260+
}
261+
262+
// Uses old service name
263+
if ($services->has('navigation')) {
264+
$container = $services->get('navigation');
265+
return;
266+
}
267+
}
268+
254269
/**
255270
* Load the navigation container from the root service locator
256271
*/

test/Helper/Navigation/AbstractHelperTest.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
namespace ZendTest\View\Helper\Navigation;
1111

12-
use Zend\View\Helper\Navigation;
12+
use Zend\Navigation\Navigation;
13+
use Zend\ServiceManager\ServiceManager;
14+
use Zend\View\Helper\Navigation as NavigationHelper;
1315

1416
class AbstractHelperTest extends AbstractTest
1517
{
@@ -19,12 +21,12 @@ class AbstractHelperTest extends AbstractTest
1921
*
2022
* @var string
2123
*/
22-
protected $_helperName = Navigation::class;
24+
protected $_helperName = NavigationHelper::class;
2325

2426
/**
2527
* View helper
2628
*
27-
* @var \Zend\View\Helper\Navigation\Breadcrumbs
29+
* @var NavigationHelper\Breadcrumbs
2830
*/
2931
protected $_helper;
3032
// @codingStandardsIgnoreEnd
@@ -85,4 +87,29 @@ public function testEventManagerIsNullByDefault()
8587
{
8688
$this->assertNull($this->_helper->getEventManager());
8789
}
90+
91+
public function testFallBackForContainerNames()
92+
{
93+
// Register navigation service with name equal to the documentation
94+
$this->serviceManager->setAllowOverride(true);
95+
$this->serviceManager->setService(
96+
'navigation',
97+
$this->serviceManager->get('Navigation')
98+
);
99+
$this->serviceManager->setAllowOverride(false);
100+
101+
$this->_helper->setServiceLocator($this->serviceManager);
102+
103+
$this->_helper->setContainer('navigation');
104+
$this->assertInstanceOf(
105+
Navigation::class,
106+
$this->_helper->getContainer()
107+
);
108+
109+
$this->_helper->setContainer('default');
110+
$this->assertInstanceOf(
111+
Navigation::class,
112+
$this->_helper->getContainer()
113+
);
114+
}
88115
}

test/Helper/Navigation/AbstractTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
abstract class AbstractTest extends TestCase
3333
{
3434
/**
35-
* @var
35+
* @var ServiceManager
3636
*/
3737
protected $serviceManager;
3838

0 commit comments

Comments
 (0)