Skip to content
Permalink
Browse files

Trying to make first tests pass

  • Loading branch information...
lorenzo committed Feb 23, 2014
1 parent ecfd4cf commit 064454493f0f41358bc0a1a8cc6349f262bd5abc
Showing with 23 additions and 59 deletions.
  1. +21 −57 src/View/Helper/FormHelper.php
  2. +2 −2 tests/TestCase/View/Helper/FormHelperTest.php
@@ -859,8 +859,7 @@ public function input($fieldName, $options = array()) {
'label' => null,
'error' => null,
'selected' => null,
'options' => null,
'templates' => []
'options' => null
];
$options = $this->_parseOptions($fieldName, $options);
@@ -870,77 +869,37 @@ public function input($fieldName, $options = array()) {
}
$template = 'groupContainer';
$error = null;
if ($options['type'] !== 'hidden' && $options['error'] !== false) {
$options['error'] = $this->error($fieldName, $error);
$template = 'groupContainerError';
$error = $this->error($fieldName, $options['error']);
$template = empty($error) ? $template : 'groupContainerError';
unset($options['error']);
}
$out['input'] = $this->_getInput($options);
$input = $this->{$options['type']}($fieldName, $options);
return $this->formatTemplate($template, [
'content' => $this->formatTemplate('formGroup', $out),
'error' => $options['error'],
'content' => $this->formatTemplate('formGroup', compact('input', 'label')),
'error' => $error,
'required' => null,
'type' => $options['type'],
]);
}
/**
* Generates an input element
*
* @param array $args The options for the input element
* @return string The generated input element
*/
protected function _getInput($args) {
extract($args);
switch ($type) {
case 'hidden':
return $this->hidden($fieldName, $options);
case 'checkbox':
return $this->checkbox($fieldName, $options);
case 'radio':
return $this->radio($fieldName, $radioOptions, $options);
case 'file':
return $this->file($fieldName, $options);
case 'select':
$options += array('options' => array(), 'value' => $selected);
$list = $options['options'];
unset($options['options']);
return $this->select($fieldName, $list, $options);
case 'time':
$options['value'] = $selected;
return $this->dateTime($fieldName, null, $timeFormat, $options);
case 'date':
$options['value'] = $selected;
return $this->dateTime($fieldName, $dateFormat, null, $options);
case 'datetime':
$options['value'] = $selected;
return $this->dateTime($fieldName, $dateFormat, $timeFormat, $options);
case 'textarea':
return $this->textarea($fieldName, $options + array('cols' => '30', 'rows' => '6'));
case 'url':
return $this->text($fieldName, array('type' => 'url') + $options);
default:
return $this->{$type}($fieldName, $options);
}
}
/**
* Generates input options array
*
* @param array $options
* @return array Options
*/
protected function _parseOptions($fieldName, $options) {
if (!empty($options['type'])) {
$typePassed = true;
if (empty($options['type'])) {
$typePassed = false;
$options['type'] = $this->_inputType($fieldName, $options);
}
$options = $this->_magicOptions($fieldName, $options);
if (in_array(['datetime', 'date', 'time', 'select'], $options['type'])) {
$options += ['empty' => false];
}
$options = $this->_magicOptions($fieldName, $options, $typePassed);
return $options;
}
@@ -1009,7 +968,7 @@ protected function _optionsOptions($fieldName, $options) {
* @param array $options
* @return array
*/
protected function _magicOptions($fieldName, $options) {
protected function _magicOptions($fieldName, $options, $allowOverride) {
$context = $this->_getContext();
$type = $context->type($fieldName);
$fielDef = $context->attributes($fieldName);
@@ -1026,7 +985,8 @@ protected function _magicOptions($fieldName, $options) {
// Missing HABTM
//...
if (in_array($options['type'], ['text', 'number', 'radio', 'select'])) {
$typesWithOptions = ['text', 'number', 'radio', 'select'];
if ($allowOverride && in_array($options['type'], $typesWithOptions)) {
$options = $this->_optionsOptions($fieldName, $options);
}
@@ -1043,6 +1003,10 @@ protected function _magicOptions($fieldName, $options) {
$options['maxlength'] = $fieldDef['length'];
}
if (in_array($options['type'], ['datetime', 'date', 'time', 'select'])) {
$options += ['empty' => false];
}
return $options;
}
@@ -1096,7 +1060,7 @@ protected function _extractOption($name, $options, $default = null) {
* @return string Generated label element
*/
protected function _inputLabel($fieldName, $label, $options) {
$labelAttributes = $this->domId(array(), 'for');
$labelAttributes = [];
$idKey = null;
if ($options['type'] === 'date' || $options['type'] === 'datetime') {
$firstInput = 'M';
@@ -2404,8 +2404,8 @@ public function testMultipleInputValidation() {
* @return void
*/
public function testInput() {
$this->markTestIncomplete('Need to revisit once models work again.');
$result = $this->Form->input('ValidateUser.balance');
$this->Form->create('ValidateUsers');

This comment has been minimized.

Copy link
@lorenzo

lorenzo Feb 23, 2014

Author Member

@markstory I'm trying to make input work, but I really cannot figure out how the context should work. No matter what I pass here is somehow wrong. Can you lend me a hand here? This is the 3.0-form-input branch

This comment has been minimized.

Copy link
@markstory

markstory Feb 24, 2014

Member

I can try and fix up some of the tests tonight when I get to my computer.

This comment has been minimized.

Copy link
@lorenzo

lorenzo Feb 24, 2014

Author Member

I already made a bunch of them work, not sure if that was the correct way, though :P

This comment has been minimized.

Copy link
@markstory

markstory Feb 24, 2014

Member

So far I have been passing this->article in as it uses the array context.

$result = $this->Form->input('ValidateUsers.balance');
$expected = array(
'div' => array('class'),
'label' => array('for'),

0 comments on commit 0644544

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