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

Commit c8a47a5

Browse files
committed
Merge branch 'feature/110' into develop
Close #110
2 parents cb05c31 + 13c9a15 commit c8a47a5

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ All notable changes to this project will be documented in this file, in reverse
2525

2626
### Fixed
2727

28-
- Nothing.
28+
- [#110](https://github.com/zendframework/zend-view/pull/110) provides a fix
29+
for the navigation helpers to ensure that usage of either the `default` or
30+
`navigation` containers (documentation specified `default`, but usage only
31+
allowed `navigation` previously). When `default` is specified, the
32+
`Zend\Navigation\Navigation` service will be used for the container; if
33+
`navigation` is used, that service will be pulled instead (which is usually an
34+
alias for the `Zend\Navigation\Navigation` service anyways).
2935

3036
## 2.8.2 - 2017-03-20
3137

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)