Skip to content

Commit

Permalink
Adding test to prove that non-conventional primaryKeys and composite
Browse files Browse the repository at this point in the history
keys
  • Loading branch information
lorenzo committed Feb 27, 2014
1 parent d891182 commit 9d657ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/View/Helper/FormHelper.php
Expand Up @@ -848,7 +848,9 @@ public function input($fieldName, $options = []) {
$this->templates($options['templates']);
unset($options['templates']);

$input = $this->_getInput($fieldName, $options);
$label = $this->_getLabel($fieldName, $options);

if ($options['type'] !== 'radio') {
unset($options['label']);
}
Expand All @@ -862,7 +864,6 @@ public function input($fieldName, $options = []) {
}

$groupTemplate = $options['type'] === 'checkbox' ? 'checkboxFormGroup' : 'formGroup';
$input = $this->_getInput($fieldName, $options);
$result = $this->formatTemplate($groupTemplate, compact('input', 'label'));

if ($options['type'] !== 'hidden') {
Expand Down Expand Up @@ -1003,7 +1004,7 @@ protected function _optionsOptions($fieldName, $options) {
protected function _magicOptions($fieldName, $options, $allowOverride) {
$context = $this->_getContext();

if (!isset($options['required'])) {
if (!isset($options['required']) && $options['type'] !== 'hidden') {
$options['required'] = $context->isRequired($fieldName);
}

Expand Down Expand Up @@ -1055,7 +1056,7 @@ protected function _magicOptions($fieldName, $options, $allowOverride) {
* @return boolean|string false or Generated label element
*/
protected function _getLabel($fieldName, $options) {
if ($options['type'] === 'radio') {
if (in_array($options['type'], ['radio', 'hidden'])) {
return false;
}

Expand Down
29 changes: 17 additions & 12 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -2914,20 +2914,25 @@ public function testInputSelectType() {
* @return void
*/
public function testInputWithNonStandardPrimaryKeyMakesHidden() {
$this->markTestIncomplete('Need to revisit once models work again.');
$this->Form->create('User');
$this->Form->fieldset = array(
'User' => array(
'fields' => array(
'model_id' => array('type' => 'integer')
),
'validates' => array(),
'key' => 'model_id'
)
$this->article['schema']['_constraints']['primary']['columns'] = ['title'];
$this->Form->create($this->article);
$result = $this->Form->input('title');
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'title', 'id' => 'title'),
);
$this->assertTags($result, $expected);

$this->article['schema']['_constraints']['primary']['columns'] = ['title', 'body'];
$this->Form->create($this->article);
$result = $this->Form->input('title');
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'title', 'id' => 'title'),
);
$result = $this->Form->input('model_id');
$this->assertTags($result, $expected);

$result = $this->Form->input('body');
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'User[model_id]', 'id' => 'UserModelId'),
'input' => array('type' => 'hidden', 'name' => 'body', 'id' => 'body'),
);
$this->assertTags($result, $expected);
}
Expand Down

0 comments on commit 9d657ca

Please sign in to comment.