From 576eba3ef9f1c65431cb7a286dcdf46bba6c257b Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 14 Jul 2010 23:09:35 -0400 Subject: [PATCH] Removing ClassRegistry use from FormHelper and its test case. --- cake/libs/view/helpers/form.php | 25 +++++------- .../cases/libs/view/helpers/form.test.php | 38 ++++++------------- 2 files changed, 21 insertions(+), 42 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 40633594c..503c2e50a 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -188,7 +188,6 @@ class FormHelper extends AppHelper { function create($model = null, $options = array()) { $created = $id = false; $append = ''; - $view =& ClassRegistry::getObject('view'); if (is_array($model) && empty($options)) { $options = $model; @@ -253,7 +252,7 @@ class FormHelper extends AppHelper { $actionDefaults = array( 'plugin' => $this->plugin, - 'controller' => $view->viewPath, + 'controller' => $this->_View->viewPath, 'action' => $options['action'], 0 => $id ); @@ -372,8 +371,7 @@ class FormHelper extends AppHelper { $this->setEntity(null); $out .= $this->Html->tags['formend']; - $view =& ClassRegistry::getObject('view'); - $view->modelScope = false; + $this->_View->modelScope = false; return $out; } @@ -421,8 +419,7 @@ class FormHelper extends AppHelper { */ function __secure($field = null, $value = null) { if (!$field) { - $view =& ClassRegistry::getObject('view'); - $field = $view->entity(); + $field = $this->_View->entity(); } elseif (is_string($field)) { $field = Set::filter(explode('.', $field), true); } @@ -535,8 +532,7 @@ class FormHelper extends AppHelper { */ function label($fieldName = null, $text = null, $options = array()) { if (empty($fieldName)) { - $view = ClassRegistry::getObject('view'); - $fieldName = implode('.', $view->entity()); + $fieldName = implode('.', $this->_View->entity()); } if ($text === null) { @@ -761,11 +757,10 @@ class FormHelper extends AppHelper { (!isset($options['options']) && in_array($options['type'], $types)) || (isset($magicType) && $options['type'] == 'text') ) { - $view =& ClassRegistry::getObject('view'); $varName = Inflector::variable( Inflector::pluralize(preg_replace('/_id$/', '', $fieldKey)) ); - $varOptions = $view->getVar($varName); + $varOptions = $this->_View->getVar($varName); if (is_array($varOptions)) { if ($options['type'] !== 'radio') { $options['type'] = 'select'; @@ -1229,8 +1224,7 @@ class FormHelper extends AppHelper { public function file($fieldName, $options = array()) { $options = array_merge($options, array('secure' => false)); $options = $this->_initInputField($fieldName, $options); - $view =& ClassRegistry::getObject('view'); - $field = $view->entity(); + $field = $this->_View->entity(); foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $suffix) { $this->__secure(array_merge($field, array($suffix))); @@ -1942,10 +1936,9 @@ class FormHelper extends AppHelper { return $options; } - $view = ClassRegistry::getObject('view'); - $name = $view->field; - if (!empty($view->fieldSuffix)) { - $name .= '[' . $view->fieldSuffix . ']'; + $name = $this->_View->field; + if (!empty($this->_View->fieldSuffix)) { + $name .= '[' . $this->_View->fieldSuffix . ']'; } if (is_array($options)) { diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 2a44a189d..b719d4129 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -678,7 +678,6 @@ class FormHelperTest extends CakeTestCase { $this->Form = new FormHelper($this->View); $this->Form->params['action'] = 'add'; - ClassRegistry::addObject('view', $view); ClassRegistry::addObject('Contact', new Contact()); ClassRegistry::addObject('ContactNonStandardPk', new ContactNonStandardPk()); ClassRegistry::addObject('OpenidUrl', new OpenidUrl()); @@ -708,7 +707,6 @@ class FormHelperTest extends CakeTestCase { * @return void */ function tearDown() { - ClassRegistry::removeObject('view'); ClassRegistry::removeObject('Contact'); ClassRegistry::removeObject('ContactNonStandardPk'); ClassRegistry::removeObject('ContactTag'); @@ -2088,8 +2086,8 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('user_id' => 'value')); - $view =& ClassRegistry::getObject('view'); - $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); + + $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); $result = $this->Form->input('Model.user_id', array('empty' => true)); $expected = array( 'div' => array('class' => 'input select'), @@ -2111,8 +2109,8 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('user_id' => null)); - $view =& ClassRegistry::getObject('view'); - $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); + + $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); $result = $this->Form->input('Model.user_id', array('empty' => 'Some Empty')); $expected = array( 'div' => array('class' => 'input select'), @@ -2135,8 +2133,8 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); $this->Form->data = array('Model' => array('user_id' => 'value')); - $view =& ClassRegistry::getObject('view'); - $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); + + $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); $result = $this->Form->input('Model.user_id', array('empty' => 'Some Empty')); $expected = array( 'div' => array('class' => 'input select'), @@ -2159,8 +2157,8 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); $this->Form->data = array('User' => array('User' => array('value'))); - $view =& ClassRegistry::getObject('view'); - $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); + + $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); $result = $this->Form->input('User.User', array('empty' => true)); $expected = array( 'div' => array('class' => 'input select'), @@ -2212,8 +2210,7 @@ class FormHelperTest extends CakeTestCase { * @return void */ function testInputOverridingMagicSelectType() { - $view =& ClassRegistry::getObject('view'); - $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); + $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); $result = $this->Form->input('Model.user_id', array('type' => 'text')); $expected = array( 'div' => array('class' => 'input text'), @@ -2224,8 +2221,7 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); //Check that magic types still work for plural/singular vars - $view =& ClassRegistry::getObject('view'); - $view->viewVars['types'] = array('value' => 'good', 'other' => 'bad'); + $this->View->viewVars['types'] = array('value' => 'good', 'other' => 'bad'); $result = $this->Form->input('Model.type'); $expected = array( 'div' => array('class' => 'input select'), @@ -2245,8 +2241,7 @@ class FormHelperTest extends CakeTestCase { * @return void */ function testInputMagicSelectChangeToRadio() { - $view =& ClassRegistry::getObject('view'); - $view->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); + $this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad'); $result = $this->Form->input('Model.user_id', array('type' => 'radio')); $this->assertPattern('/input type="radio"/', $result); } @@ -2281,7 +2276,6 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $View = ClassRegistry::getObject('view'); $this->Form->create('Contact'); $this->Form->params['prefix'] = 'admin'; $this->Form->action = 'admin_edit'; @@ -3242,8 +3236,7 @@ class FormHelperTest extends CakeTestCase { * @return void */ function testHabtmSelectBox() { - $view =& ClassRegistry::getObject('view'); - $view->viewVars['contactTags'] = array( + $this->View->viewVars['contactTags'] = array( 1 => 'blue', 2 => 'red', 3 => 'green' @@ -4974,13 +4967,6 @@ class FormHelperTest extends CakeTestCase { * @return void */ function testFileUploadOnOtherModel() { - ClassRegistry::removeObject('view'); - $controller =& new Controller(); - $controller->name = 'ValidateUsers'; - $controller->uses = array('ValidateUser'); - $controller->constructClasses(); - $view =& new View($controller, true); - $this->Form->create('ValidateUser', array('type' => 'file')); $result = $this->Form->file('ValidateProfile.city'); $expected = array(