diff --git a/src/View/Widget/WidgetRegistry.php b/src/View/Widget/WidgetRegistry.php index ab7a3c64595..13a4ce40432 100644 --- a/src/View/Widget/WidgetRegistry.php +++ b/src/View/Widget/WidgetRegistry.php @@ -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') { diff --git a/tests/TestCase/View/Widget/WidgetRegistryTest.php b/tests/TestCase/View/Widget/WidgetRegistryTest.php index 8e927a17991..14b34f4e6ea 100644 --- a/tests/TestCase/View/Widget/WidgetRegistryTest.php +++ b/tests/TestCase/View/Widget/WidgetRegistryTest.php @@ -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. *