Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Start adding tests for InputRegistry.

  • Loading branch information...
commit d264a825ad68e08dcd139f7b9426f893b70b0ebc 1 parent 944faad
@markstory markstory authored
View
8 src/View/Input/InputRegistry.php
@@ -56,7 +56,9 @@ class InputRegistry {
*/
public function __construct(StringTemplate $templates, array $widgets = null) {
$this->_templates = $templates;
- $this->add($widgets);
+ if (!empty($widgets)) {
+ $this->add($widgets);
+ }
}
/**
@@ -114,12 +116,12 @@ public function get($name) {
* implement InputInterface.
*/
protected function _resolveWidget($widget) {
- if (!is_array($widget)) {
+ if (is_object($widget)) {
return $widget;
}
$class = array_shift($widget);
$className = App::classname($class, 'View/Input');
- if ($className === false) {
+ if ($className === false || !class_exists($className)) {
throw new \RuntimeException(sprintf('Unable to locate widget class "%s"', $class));
}
$reflection = new ReflectionClass($className);
View
116 tests/TestCase/View/Input/InputRegistryTest.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org CakePHP(tm) Project
+ * @since CakePHP(tm) v3.0
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+namespace Cake\Test\TestCase\View\Input;
+
+use Cake\TestSuite\TestCase;
+use Cake\View\Input\InputRegistry;
+use Cake\View\StringTemplate;
+
+/**
+ * InputRegistry test case
+ */
+class InputRegistryTestCase extends TestCase {
+
+/**
+ * setup method
+ *
+ * @return void
+ */
+ public function setUp() {
+ parent::setUp();
+ $this->templates = new StringTemplate();
+ }
+
+/**
+ * Test adding new widgets.
+ *
+ * @return void
+ */
+ public function testAdd() {
+ $this->markTestIncomplete();
+ }
+
+/**
+ * Test getting registered widgets.
+ *
+ * @return void
+ */
+ public function testGet() {
+ $this->markTestIncomplete();
+ }
+
+/**
+ * Test getting fallback widgets.
+ *
+ * @return void
+ */
+ public function testGetFallback() {
+ $this->markTestIncomplete();
+ }
+
+/**
+ * Test getting errors
+ *
+ * @expectedException RuntimeException
+ * @expectedExceptionMessage Unknown widget "foo"
+ * @return void
+ */
+ public function testGetNoFallbackError() {
+ $inputs = new InputRegistry($this->templates);
+ $inputs->get('foo');
+ }
+
+/**
+ * Test getting resolve dependency
+ *
+ * @return void
+ */
+ public function testGetResolveDependency() {
+ $inputs = new InputRegistry($this->templates);
+ $inputs->add([
+ 'label' => ['Cake\View\Input\Label'],
+ 'multicheckbox' => ['Cake\View\Input\MultiCheckbox', 'label']
+ ]);
+ $result = $inputs->get('multicheckbox');
+ $this->assertInstanceOf('CakeView\Input\MultiCheckbox', $result);
+ }
+
+/**
+ * Test getting resolve dependency missing class
+ *
+ * @expectedException RuntimeException
+ * @expectedExceptionMessage Unable to locate widget class "TestApp\View\Derp"
+ * @return void
+ */
+ public function testGetResolveDependencyMissingClass() {
+ $inputs = new InputRegistry($this->templates);
+ $inputs->add(['test' => ['TestApp\View\Derp']]);
+ $inputs->get('test');
+ }
+
+/**
+ * Test getting resolve dependency missing dependency
+ *
+ * @expectedException RuntimeException
+ * @expectedExceptionMessage Unknown widget "label"
+ * @return void
+ */
+ public function testGetResolveDependencyMissingDependency() {
+ $inputs = new InputRegistry($this->templates);
+ $inputs->add(['multicheckbox' => ['Cake\View\Input\MultiCheckbox', 'label']]);
+ $inputs->get('multicheckbox');
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.