Skip to content
Permalink
Browse files

Removing ClassRegistry use from FormHelper and its test case.

  • Loading branch information...
markstory committed Jul 15, 2010
1 parent 90b0ac7 commit 576eba3ef9f1c65431cb7a286dcdf46bba6c257b
Showing with 21 additions and 42 deletions.
  1. +9 −16 cake/libs/view/helpers/form.php
  2. +12 −26 cake/tests/cases/libs/view/helpers/form.test.php
@@ -188,7 +188,6 @@ protected function _isRequiredField($validateProperties) {
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 @@ function create($model = null, $options = array()) {
$actionDefaults = array(
'plugin' => $this->plugin,
'controller' => $view->viewPath,
'controller' => $this->_View->viewPath,
'action' => $options['action'],
0 => $id
);
@@ -372,8 +371,7 @@ public function end($options = null) {
$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 @@ public function secure($fields = array()) {
*/
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 @@ public function error($field, $text = null, $options = array()) {
*/
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 @@ public function input($fieldName, $options = array()) {
(!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 @@ public function hidden($fieldName, $options = array()) {
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 @@ protected function _name($options = array(), $field = null, $key = 'name') {
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)) {
@@ -678,7 +678,6 @@ function setUp() {
$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 @@ function setUp() {
* @return void
*/
function tearDown() {
ClassRegistry::removeObject('view');
ClassRegistry::removeObject('Contact');
ClassRegistry::removeObject('ContactNonStandardPk');
ClassRegistry::removeObject('ContactTag');
@@ -2088,8 +2086,8 @@ function testInputSelectType() {
$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 @@ function testInputSelectType() {
$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 @@ function testInputSelectType() {
$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 @@ function testInputSelectType() {
$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 @@ function testInputWithNonStandardPrimaryKeyMakesHidden() {
* @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 @@ function testInputOverridingMagicSelectType() {
$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 @@ function testInputOverridingMagicSelectType() {
* @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 @@ function testFormInputs() {
);
$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 @@ function testSelectMultiple() {
* @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 @@ function testFileUploadField() {
* @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(

0 comments on commit 576eba3

Please sign in to comment.
You can’t perform that action at this time.