mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-19 16:10:54 +00:00
Updating FormHelper tests
This commit is contained in:
parent
e8efc67d3d
commit
1941be6a76
2 changed files with 112 additions and 114 deletions
|
@ -1574,7 +1574,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testMultipleInputValidation() {
|
||||
$Address = ClassRegistry::getObject('Address');
|
||||
$Address = ClassRegistry::init(array('class' => 'Address', 'table' => false));
|
||||
$Address->validationErrors[0] = array(
|
||||
'title' => array('This field cannot be empty'),
|
||||
'first_name' => array('This field cannot be empty')
|
||||
|
@ -1789,16 +1789,17 @@ class FormHelperTest extends CakeTestCase {
|
|||
|
||||
unset($this->Form->request->data);
|
||||
|
||||
$this->Form->validationErrors['Model']['field'] = array('Badness!');
|
||||
$result = $this->Form->input('Model.field');
|
||||
$Contact = ClassRegistry::getObject('Contact');
|
||||
$Contact->validationErrors['field'] = array('Badness!');
|
||||
$result = $this->Form->input('Contact.field');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text error'),
|
||||
'label' => array('for' => 'ModelField'),
|
||||
'label' => array('for' => 'ContactField'),
|
||||
'Field',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Model][field]',
|
||||
'id' => 'ModelField', 'class' => 'form-error'
|
||||
'type' => 'text', 'name' => 'data[Contact][field]',
|
||||
'id' => 'ContactField', 'class' => 'form-error'
|
||||
),
|
||||
array('div' => array('class' => 'error-message')),
|
||||
'Badness!',
|
||||
|
@ -1807,16 +1808,16 @@ class FormHelperTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Model.field', array(
|
||||
$result = $this->Form->input('Contact.field', array(
|
||||
'div' => false, 'error' => array('attributes' => array('wrap' => 'span'))
|
||||
));
|
||||
$expected = array(
|
||||
'label' => array('for' => 'ModelField'),
|
||||
'label' => array('for' => 'ContactField'),
|
||||
'Field',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Model][field]',
|
||||
'id' => 'ModelField', 'class' => 'form-error'
|
||||
'type' => 'text', 'name' => 'data[Contact][field]',
|
||||
'id' => 'ContactField', 'class' => 'form-error'
|
||||
),
|
||||
array('span' => array('class' => 'error-message')),
|
||||
'Badness!',
|
||||
|
@ -1824,32 +1825,32 @@ class FormHelperTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Model.field', array(
|
||||
$result = $this->Form->input('Contact.field', array(
|
||||
'div' => array('tag' => 'span'), 'error' => array('attributes' => array('wrap' => false))
|
||||
));
|
||||
$expected = array(
|
||||
'span' => array('class' => 'input text error'),
|
||||
'label' => array('for' => 'ModelField'),
|
||||
'label' => array('for' => 'ContactField'),
|
||||
'Field',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Model][field]',
|
||||
'id' => 'ModelField', 'class' => 'form-error'
|
||||
'type' => 'text', 'name' => 'data[Contact][field]',
|
||||
'id' => 'ContactField', 'class' => 'form-error'
|
||||
),
|
||||
'Badness!',
|
||||
'/span'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Model.field', array('after' => 'A message to you, Rudy'));
|
||||
$result = $this->Form->input('Contact.field', array('after' => 'A message to you, Rudy'));
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text error'),
|
||||
'label' => array('for' => 'ModelField'),
|
||||
'label' => array('for' => 'ContactField'),
|
||||
'Field',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Model][field]',
|
||||
'id' => 'ModelField', 'class' => 'form-error'
|
||||
'type' => 'text', 'name' => 'data[Contact][field]',
|
||||
'id' => 'ContactField', 'class' => 'form-error'
|
||||
),
|
||||
'A message to you, Rudy',
|
||||
array('div' => array('class' => 'error-message')),
|
||||
|
@ -1860,36 +1861,35 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Form->setEntity(null);
|
||||
$this->Form->setEntity('Model.field');
|
||||
$result = $this->Form->input('Model.field', array(
|
||||
$this->Form->setEntity('Contact.field');
|
||||
$result = $this->Form->input('Contact.field', array(
|
||||
'after' => 'A message to you, Rudy', 'error' => false
|
||||
));
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text'),
|
||||
'label' => array('for' => 'ModelField'),
|
||||
'label' => array('for' => 'ContactField'),
|
||||
'Field',
|
||||
'/label',
|
||||
'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'ModelField', 'class' => 'form-error'),
|
||||
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
|
||||
'A message to you, Rudy',
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
unset($this->Form->validationErrors['Model']['field']);
|
||||
$result = $this->Form->input('Model.field', array('after' => 'A message to you, Rudy'));
|
||||
$result = $this->Form->input('Object.field', array('after' => 'A message to you, Rudy'));
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text'),
|
||||
'label' => array('for' => 'ModelField'),
|
||||
'label' => array('for' => 'ObjectField'),
|
||||
'Field',
|
||||
'/label',
|
||||
'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'ModelField'),
|
||||
'input' => array('type' => 'text', 'name' => 'data[Object][field]', 'id' => 'ObjectField'),
|
||||
'A message to you, Rudy',
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Form->validationErrors['Model']['field'] = array('minLength');
|
||||
$result = $this->Form->input('Model.field', array(
|
||||
$Contact->validationErrors['field'] = array('minLength');
|
||||
$result = $this->Form->input('Contact.field', array(
|
||||
'error' => array(
|
||||
'minLength' => 'Le login doit contenir au moins 2 caractères',
|
||||
'maxLength' => 'login too large'
|
||||
|
@ -1897,10 +1897,10 @@ class FormHelperTest extends CakeTestCase {
|
|||
));
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text error'),
|
||||
'label' => array('for' => 'ModelField'),
|
||||
'label' => array('for' => 'ContactField'),
|
||||
'Field',
|
||||
'/label',
|
||||
'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'ModelField', 'class' => 'form-error'),
|
||||
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
|
||||
array('div' => array('class' => 'error-message')),
|
||||
'Le login doit contenir au moins 2 caractères',
|
||||
'/div',
|
||||
|
@ -1908,8 +1908,8 @@ class FormHelperTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->Form->validationErrors['Model']['field'] = array('maxLength');
|
||||
$result = $this->Form->input('Model.field', array(
|
||||
$Contact->validationErrors['field'] = array('maxLength');
|
||||
$result = $this->Form->input('Contact.field', array(
|
||||
'error' => array(
|
||||
'attributes' => array('wrap' => 'span', 'rel' => 'fake'),
|
||||
'minLength' => 'Le login doit contenir au moins 2 caractères',
|
||||
|
@ -1918,10 +1918,10 @@ class FormHelperTest extends CakeTestCase {
|
|||
));
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text error'),
|
||||
'label' => array('for' => 'ModelField'),
|
||||
'label' => array('for' => 'ContactField'),
|
||||
'Field',
|
||||
'/label',
|
||||
'input' => array('type' => 'text', 'name' => 'data[Model][field]', 'id' => 'ModelField', 'class' => 'form-error'),
|
||||
'input' => array('type' => 'text', 'name' => 'data[Contact][field]', 'id' => 'ContactField', 'class' => 'form-error'),
|
||||
array('span' => array('class' => 'error-message', 'rel' => 'fake')),
|
||||
'login too large',
|
||||
'/span',
|
||||
|
|
|
@ -134,10 +134,10 @@ class FormHelper extends AppHelper {
|
|||
'alias' => $model
|
||||
));
|
||||
} else {
|
||||
$object = ClassRegistry::init($model);
|
||||
$object = ClassRegistry::init($model, true);
|
||||
}
|
||||
|
||||
if (get_class($object) === 'AppModel') {
|
||||
if (!$object) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -153,11 +153,11 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
|
||||
if ($key === 'key') {
|
||||
return $this->fieldset[$object->alias]['key'];
|
||||
return $this->fieldset[$model]['key'];
|
||||
}
|
||||
|
||||
if (!isset($this->fieldset[$object->alias]['fields'])) {
|
||||
$fields = $this->fieldset[$object->alias]['fields'] = $object->schema();
|
||||
if (!isset($this->fieldset[$model]['fields'])) {
|
||||
$fields = $this->fieldset[$model]['fields'] = $object->schema();
|
||||
}
|
||||
|
||||
if ($key === 'fields') {
|
||||
|
@ -165,15 +165,15 @@ class FormHelper extends AppHelper {
|
|||
foreach ($object->hasAndBelongsToMany as $alias => $assocData) {
|
||||
$this->fieldset[$object->alias]['fields'][$alias] = array('type' => 'multiple');
|
||||
}
|
||||
return $this->fieldset[$object->alias]['fields'];
|
||||
} elseif (isset($this->fieldset[$object->alias]['fields'][$field])) {
|
||||
return $this->fieldset[$object->alias]['fields'][$field];
|
||||
return $this->fieldset[$model]['fields'];
|
||||
} elseif (isset($this->fieldset[$model]['fields'][$field])) {
|
||||
return $this->fieldset[$model]['fields'][$field];
|
||||
} else {
|
||||
return isset($object->hasAndBelongsToMany[$field]) ? array('type' => 'multiple') : null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($key === 'validates' && !isset($this->fieldset[$object->alias]['validates'])) {
|
||||
if ($key === 'validates' && !isset($this->fieldset[$model]['validates'])) {
|
||||
$validates = array();
|
||||
if (!empty($object->validate)) {
|
||||
foreach ($object->validate as $validateField => $validateProperties) {
|
||||
|
@ -182,15 +182,15 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
$this->fieldset[$object->alias]['validates'] = $validates;
|
||||
$this->fieldset[$model]['validates'] = $validates;
|
||||
}
|
||||
|
||||
if ($key === 'validates') {
|
||||
if (empty($field)) {
|
||||
return $this->fieldset[$object->alias]['validates'];
|
||||
return $this->fieldset[$model]['validates'];
|
||||
} else {
|
||||
return isset($this->fieldset[$object->alias]['validates'][$field]) ?
|
||||
$this->fieldset[$object->alias]['validates'] : null;
|
||||
return isset($this->fieldset[$model]['validates'][$field]) ?
|
||||
$this->fieldset[$model]['validates'] : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -593,8 +593,9 @@ class FormHelper extends AppHelper {
|
|||
$defaults = array('wrap' => true, 'class' => 'error-message', 'escape' => true);
|
||||
$options = array_merge($defaults, $options);
|
||||
$this->setEntity($field);
|
||||
|
||||
if ($error = $this->tagIsInvalid()) {
|
||||
if (!$error = $this->tagIsInvalid()) {
|
||||
return null;
|
||||
}
|
||||
if (is_array($text)) {
|
||||
if (isset($text['attributes']) && is_array($text['attributes'])) {
|
||||
$options = array_merge($options, $text['attributes']);
|
||||
|
@ -659,9 +660,6 @@ class FormHelper extends AppHelper {
|
|||
} else {
|
||||
return $error;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue