Browse Source

Remove deprecated parameters and update tests.

Remove deprecated forms of inputs() and update tests. Shuffle tests
around to match the separation added earlier.
Mark Story 12 years ago
parent
commit
45fe7eb709
2 changed files with 19 additions and 84 deletions
  1. 7 19
      src/View/Helper/FormHelper.php
  2. 12 65
      tests/TestCase/View/Helper/FormHelperTest.php

+ 7 - 19
src/View/Helper/FormHelper.php

@@ -720,8 +720,6 @@ class FormHelper extends Helper {
  * In addition to controller fields output, `$fields` can be used to control legend
  * and fieldset rendering.
  * `$this->Form->inputs('My legend');` Would generate an input set with a custom legend.
- * Passing `fieldset` and `legend` key in `$fields` array has been deprecated since 2.3,
- * for more fine grained control use the `fieldset` and `legend` keys in `$options` param.
  *
  * @param array $fields An array of fields to generate inputs for, or null.
  * @param array $blacklist A simple array of fields to not create inputs for.
@@ -740,22 +738,12 @@ class FormHelper extends Helper {
 
 		$modelFields = $context->fieldNames();
 
-		if (is_array($fields)) {
-			if (array_key_exists('legend', $fields) && !in_array('legend', $modelFields)) {
-				$legend = $fields['legend'];
-				unset($fields['legend']);
-			}
-
-			if (isset($fields['fieldset']) && !in_array('fieldset', $modelFields)) {
-				$fieldset = $fields['fieldset'];
-				unset($fields['fieldset']);
-			}
-		} elseif ($fields !== null) {
+		if (is_string($fields)) {
+			$legend = $fields;
+			$fields = [];
+		} elseif (is_bool($fields)) {
 			$fieldset = $legend = $fields;
-			if (!is_bool($fieldset)) {
-				$fieldset = true;
-			}
-			$fields = array();
+			$fields = [];
 		}
 
 		if (empty($fields)) {
@@ -782,7 +770,7 @@ class FormHelper extends Helper {
 		foreach ($fields as $name => $options) {
 			if (is_numeric($name) && !is_array($options)) {
 				$name = $options;
-				$options = array();
+				$options = [];
 			}
 			$entity = explode('.', $name);
 			$blacklisted = (
@@ -792,7 +780,7 @@ class FormHelper extends Helper {
 			if ($blacklisted) {
 				continue;
 			}
-			$out .= $this->input($name, $options);
+			$out .= $this->input($name, (array)$options);
 		}
 
 		if ($fieldset) {

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

@@ -2510,21 +2510,21 @@ class FormHelperTest extends TestCase {
 		);
 		$this->assertTags($result, $expected);
 
-		$result = $this->Form->inputs(array('legend' => 'Field of Dreams', 'fieldset' => true));
-		$expected = array(
-			'<fieldset',
-			'<legend',
-			'Field of Dreams',
-			'/legend',
-			'*/fieldset'
-		);
-		$this->assertTags($result, $expected);
-
 		$result = $this->Form->inputs(null, null, array('legend' => 'Field of Dreams', 'fieldset' => true));
-		$this->assertTags($result, $expected);
+		$this->assertContains('<legend>Field of Dreams</legend>', $result);
+		$this->assertContains('<fieldset>', $result);
 
 		$result = $this->Form->inputs('Field of Dreams', null, array('fieldset' => true));
-		$this->assertTags($result, $expected);
+		$this->assertContains('<legend>Field of Dreams</legend>', $result);
+		$this->assertContains('<fieldset>', $result);
+
+		$result = $this->Form->inputs(null, null, array('fieldset' => false, 'legend' => false));
+		$this->assertNotContains('<legend>', $result);
+		$this->assertNotContains('<fieldset>', $result);
+
+		$result = $this->Form->inputs(null, null, array('fieldset' => false, 'legend' => 'Hello'));
+		$this->assertNotContains('<legend>', $result);
+		$this->assertNotContains('<fieldset>', $result);
 
 		$this->Form->create($this->article);
 		$this->Form->request->params['prefix'] = 'admin';
@@ -2562,53 +2562,6 @@ class FormHelperTest extends TestCase {
 		$this->assertTags($result, $expected);
 
 		$this->Form->create($this->article);
-		$result = $this->Form->inputs(['id', 'title', 'body'], null, array('fieldset' => false, 'legend' => false));
-		$expected = array(
-			'input' => array('type' => 'hidden', 'name' => 'id', 'id' => 'id'),
-			array('div' => array('class' => 'input text required')),
-			'*/div',
-			array('div' => array('class' => 'input text')),
-			'*/div',
-		);
-		$this->assertTags($result, $expected);
-
-		$this->Form->create($this->article);
-		$result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
-		$expected = array(
-			'fieldset' => array(),
-			'input' => array('type' => 'hidden', 'name' => 'id', 'id' => 'id'),
-			array('div' => array('class' => 'input select required')),
-			'*/div',
-			array('div' => array('class' => 'input text required')),
-			'*/div',
-			array('div' => array('class' => 'input text')),
-			'*/div',
-			array('div' => array('class' => 'input text')),
-			'*/div',
-			'/fieldset'
-		);
-		$this->assertTags($result, $expected);
-
-		$this->Form->create($this->article);
-		$result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));
-		$expected = array(
-			'input' => array('type' => 'hidden', 'name' => 'id', 'id' => 'id'),
-			array('div' => array('class' => 'input select required')),
-			'*/div',
-			array('div' => array('class' => 'input text required')),
-			'*/div',
-			array('div' => array('class' => 'input text')),
-			'*/div',
-			array('div' => array('class' => 'input text')),
-			'*/div',
-		);
-		$this->assertTags($result, $expected);
-
-		$this->Form->create($this->article);
-		$result = $this->Form->inputs(null, null, array('fieldset' => false, 'legend' => 'Hello'));
-		$this->assertTags($result, $expected);
-
-		$this->Form->create($this->article);
 		$result = $this->Form->inputs('Hello');
 		$expected = array(
 			'fieldset' => array(),
@@ -2628,12 +2581,6 @@ class FormHelperTest extends TestCase {
 		);
 		$this->assertTags($result, $expected);
 
-		$result = $this->Form->inputs(array('legend' => 'Hello'));
-		$this->assertTags($result, $expected);
-
-		$result = $this->Form->inputs(null, null, array('legend' => 'Hello'));
-		$this->assertTags($result, $expected);
-
 		$this->Form->create(false);
 		$expected = array(
 			'fieldset' => array(),