mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch '2.0' of github.com:cakephp/cakephp into 2.0
This commit is contained in:
commit
66cf86c154
72 changed files with 388 additions and 361 deletions
|
@ -498,7 +498,7 @@ class SchemaShell extends Shell {
|
|||
))->addSubcommand('dump', array(
|
||||
'help' => __d('cake_console', 'Dump database SQL based on a schema file to stdout.'),
|
||||
'parser' => array(
|
||||
'options' => compact('plugin', 'path', 'file', 'name', 'connection'),
|
||||
'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'write'),
|
||||
'arguments' => compact('name')
|
||||
)
|
||||
))->addSubcommand('create', array(
|
||||
|
|
|
@ -104,6 +104,7 @@ class Contact extends CakeTestModel {
|
|||
'non_existing' => array(),
|
||||
'idontexist' => array(),
|
||||
'imrequired' => array('rule' => array('between', 5, 30), 'allowEmpty' => false),
|
||||
'string_required' => 'notEmpty',
|
||||
'imalsorequired' => array('rule' => 'alphaNumeric', 'allowEmpty' => false),
|
||||
'imrequiredtoo' => array('rule' => 'notEmpty'),
|
||||
'required_one' => array('required' => array('rule' => array('notEmpty'))),
|
||||
|
@ -6584,6 +6585,141 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that required fields are created for various types of validation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testFormInputRequiredDetection() {
|
||||
$this->Form->create('Contact');
|
||||
|
||||
$result = $this->Form->input('Contact.non_existing');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text required'),
|
||||
'label' => array('for' => 'ContactNonExisting'),
|
||||
'Non Existing',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][non_existing]',
|
||||
'id' => 'ContactNonExisting'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.imrequired');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text required'),
|
||||
'label' => array('for' => 'ContactImrequired'),
|
||||
'Imrequired',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][imrequired]',
|
||||
'id' => 'ContactImrequired'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.imalsorequired');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text required'),
|
||||
'label' => array('for' => 'ContactImalsorequired'),
|
||||
'Imalsorequired',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][imalsorequired]',
|
||||
'id' => 'ContactImalsorequired'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.imrequiredtoo');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text required'),
|
||||
'label' => array('for' => 'ContactImrequiredtoo'),
|
||||
'Imrequiredtoo',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][imrequiredtoo]',
|
||||
'id' => 'ContactImrequiredtoo'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.required_one');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text required'),
|
||||
'label' => array('for' => 'ContactRequiredOne'),
|
||||
'Required One',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][required_one]',
|
||||
'id' => 'ContactRequiredOne'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.string_required');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text required'),
|
||||
'label' => array('for' => 'ContactStringRequired'),
|
||||
'String Required',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][string_required]',
|
||||
'id' => 'ContactStringRequired'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.imnotrequired');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text'),
|
||||
'label' => array('for' => 'ContactImnotrequired'),
|
||||
'Imnotrequired',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][imnotrequired]',
|
||||
'id' => 'ContactImnotrequired'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.imalsonotrequired');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text'),
|
||||
'label' => array('for' => 'ContactImalsonotrequired'),
|
||||
'Imalsonotrequired',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][imalsonotrequired]',
|
||||
'id' => 'ContactImalsonotrequired'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.imnotrequiredeither');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text'),
|
||||
'label' => array('for' => 'ContactImnotrequiredeither'),
|
||||
'Imnotrequiredeither',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][imnotrequiredeither]',
|
||||
'id' => 'ContactImnotrequiredeither'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testFormMagicInput method
|
||||
*
|
||||
|
@ -6671,117 +6807,6 @@ class FormHelperTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.non_existing');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text required'),
|
||||
'label' => array('for' => 'ContactNonExisting'),
|
||||
'Non Existing',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][non_existing]',
|
||||
'id' => 'ContactNonExisting'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.imrequired');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text required'),
|
||||
'label' => array('for' => 'ContactImrequired'),
|
||||
'Imrequired',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][imrequired]',
|
||||
'id' => 'ContactImrequired'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.imalsorequired');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text required'),
|
||||
'label' => array('for' => 'ContactImalsorequired'),
|
||||
'Imalsorequired',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][imalsorequired]',
|
||||
'id' => 'ContactImalsorequired'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.imrequiredtoo');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text required'),
|
||||
'label' => array('for' => 'ContactImrequiredtoo'),
|
||||
'Imrequiredtoo',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][imrequiredtoo]',
|
||||
'id' => 'ContactImrequiredtoo'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.required_one');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text required'),
|
||||
'label' => array('for' => 'ContactRequiredOne'),
|
||||
'Required One',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][required_one]',
|
||||
'id' => 'ContactRequiredOne'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.imnotrequired');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text'),
|
||||
'label' => array('for' => 'ContactImnotrequired'),
|
||||
'Imnotrequired',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][imnotrequired]',
|
||||
'id' => 'ContactImnotrequired'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.imalsonotrequired');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text'),
|
||||
'label' => array('for' => 'ContactImalsonotrequired'),
|
||||
'Imalsonotrequired',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][imalsonotrequired]',
|
||||
'id' => 'ContactImalsonotrequired'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->input('Contact.imnotrequiredeither');
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input text'),
|
||||
'label' => array('for' => 'ContactImnotrequiredeither'),
|
||||
'Imnotrequiredeither',
|
||||
'/label',
|
||||
'input' => array(
|
||||
'type' => 'text', 'name' => 'data[Contact][imnotrequiredeither]',
|
||||
'id' => 'ContactImnotrequiredeither'
|
||||
),
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
extract($this->dateRegex);
|
||||
$now = strtotime('now');
|
||||
|
|
|
@ -239,14 +239,16 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns if a field is required to be filled based on validation properties from the validating object
|
||||
* Returns if a field is required to be filled based on validation properties from the validating object.
|
||||
*
|
||||
* @param array $validateProperties
|
||||
* @return boolean true if field is required to be filled, false otherwise
|
||||
*/
|
||||
protected function _isRequiredField($validateProperties) {
|
||||
$required = false;
|
||||
if (is_array($validateProperties)) {
|
||||
if (is_string($validateProperties)) {
|
||||
return true;
|
||||
} elseif (is_array($validateProperties)) {
|
||||
|
||||
$dims = Set::countDim($validateProperties);
|
||||
if ($dims == 1 || ($dims == 2 && isset($validateProperties['rule']))) {
|
||||
|
|
Loading…
Reference in a new issue