Skip to content

Commit

Permalink
Fix inability to get View instance from widget registry.
Browse files Browse the repository at this point in the history
Even though View instance was added to registry it could not be retrieved as
WidgetRegistry::_resolveWidget() throw exception if object did not implement
WidgetInterface.
  • Loading branch information
ADmad committed Nov 1, 2014
1 parent e5a9dc8 commit f3e64e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/View/Widget/WidgetRegistry.php
Expand Up @@ -160,16 +160,18 @@ public function clear() {
* @param mixed $widget The widget to get
* @return WidgetInterface
* @throws \RuntimeException when class cannot be loaded or does not
* implement WidgetInterface.
* implement WidgetInterface or not a View instance.
*/
protected function _resolveWidget($widget) {
$type = gettype($widget);
if ($type === 'object' && $widget instanceof WidgetInterface) {
if ($type === 'object' &&
($widget instanceof WidgetInterface || $widget instanceof View)
) {
return $widget;
}
if ($type === 'object') {
throw new \RuntimeException(
'Input objects must implement Cake\View\Widget\WidgetInterface.'
'Widget objects must implement Cake\View\Widget\WidgetInterface.'
);
}
if ($type === 'string') {
Expand Down
12 changes: 12 additions & 0 deletions tests/TestCase/View/Widget/WidgetRegistryTest.php
Expand Up @@ -54,6 +54,18 @@ public function testAddInConstructor() {
$this->assertInstanceOf('Cake\View\Widget\Label', $result);
}

/**
* Test getting view instance from registry.
*
* @return void
*/
public function testGetViewInstance() {
$inputs = new WidgetRegistry($this->templates, $this->view, []);

$result = $inputs->get('_view');
$this->assertInstanceOf('Cake\View\View', $result);
}

/**
* Test loading widgets files in the app.
*
Expand Down

0 comments on commit f3e64e1

Please sign in to comment.