mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fixing issue where an array to string conversion error could occur if you had multiple values for a model's primary key and you created a matching form. Tests added.
Fixes #1257
This commit is contained in:
parent
81ce6f40b9
commit
d56b812181
2 changed files with 27 additions and 1 deletions
|
@ -221,7 +221,8 @@ class FormHelper extends AppHelper {
|
||||||
$data = $this->fieldset[$modelEntity];
|
$data = $this->fieldset[$modelEntity];
|
||||||
$recordExists = (
|
$recordExists = (
|
||||||
isset($this->data[$model]) &&
|
isset($this->data[$model]) &&
|
||||||
!empty($this->data[$model][$data['key']])
|
!empty($this->data[$model][$data['key']]) &&
|
||||||
|
!is_array($this->data[$model][$data['key']])
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($recordExists) {
|
if ($recordExists) {
|
||||||
|
|
|
@ -5626,6 +5626,31 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertTags($result, $expected, true);
|
$this->assertTags($result, $expected, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that create() doesn't cause errors by multiple id's being in the primary key
|
||||||
|
* as could happen with multiple select or checkboxes.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testCreateWithMultipleIdInData() {
|
||||||
|
$encoding = strtolower(Configure::read('App.encoding'));
|
||||||
|
|
||||||
|
$this->Form->data['Contact']['id'] = array(1, 2);
|
||||||
|
$result = $this->Form->create('Contact');
|
||||||
|
$expected = array(
|
||||||
|
'form' => array(
|
||||||
|
'id' => 'ContactAddForm',
|
||||||
|
'method' => 'post',
|
||||||
|
'action' => '/contacts/add',
|
||||||
|
'accept-charset' => $encoding
|
||||||
|
),
|
||||||
|
'div' => array('style' => 'display:none;'),
|
||||||
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
||||||
|
'/div'
|
||||||
|
);
|
||||||
|
$this->assertTags($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that create() doesn't add in extra passed params.
|
* test that create() doesn't add in extra passed params.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue