From f3e64e180b549283d78d17e5e860c30415d08a10 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 2 Nov 2014 02:25:00 +0530 Subject: [PATCH] Fix inability to get View instance from widget registry. Even though View instance was added to registry it could not be retrieved as WidgetRegistry::_resolveWidget() throw exception if object did not implement WidgetInterface. --- src/View/Widget/WidgetRegistry.php | 8 +++++--- tests/TestCase/View/Widget/WidgetRegistryTest.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) 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. *