Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding test to prove that non-conventional primaryKeys and composite

keys
  • Loading branch information...
commit 9d657ca3e0fcdbd85bf7cc846d973d4d4038d024 1 parent d891182
@lorenzo lorenzo authored
View
7 src/View/Helper/FormHelper.php
@@ -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']);
}
@@ -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') {
@@ -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);
}
@@ -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;
}
View
29 tests/TestCase/View/Helper/FormHelperTest.php
@@ -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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.