浏览代码

Adding test to prove that non-conventional primaryKeys and composite
keys

Jose Lorenzo Rodriguez 12 年之前
父节点
当前提交
9d657ca3e0
共有 2 个文件被更改,包括 21 次插入15 次删除
  1. 4 3
      src/View/Helper/FormHelper.php
  2. 17 12
      tests/TestCase/View/Helper/FormHelperTest.php

+ 4 - 3
src/View/Helper/FormHelper.php

@@ -848,7 +848,9 @@ class FormHelper extends Helper {
 		$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 @@ class FormHelper extends Helper {
 		}
 
 		$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 @@ class FormHelper extends Helper {
 	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 @@ class FormHelper extends Helper {
  * @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;
 		}
 

+ 17 - 12
tests/TestCase/View/Helper/FormHelperTest.php

@@ -2914,20 +2914,25 @@ class FormHelperTest extends TestCase {
  * @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);
 	}