Permalink
Browse files

Remove deprecated parameters and update tests.

Remove deprecated forms of inputs() and update tests. Shuffle tests
around to match the separation added earlier.
  • Loading branch information...
1 parent 417bfd8 commit 45fe7eb709692024cd7b134392adda06e7746190 @markstory markstory committed Mar 4, 2014
Showing with 19 additions and 84 deletions.
  1. +7 −19 src/View/Helper/FormHelper.php
  2. +12 −65 tests/TestCase/View/Helper/FormHelperTest.php
@@ -720,8 +720,6 @@ protected function _domId($value) {
* 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 @@ public function inputs($fields = null, $blacklist = null, $options = array()) {
$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 @@ public function inputs($fields = null, $blacklist = null, $options = array()) {
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 @@ public function inputs($fields = null, $blacklist = null, $options = array()) {
if ($blacklisted) {
continue;
}
- $out .= $this->input($name, $options);
+ $out .= $this->input($name, (array)$options);
}
if ($fieldset) {
@@ -2510,21 +2510,21 @@ public function testFormInputsLegendFieldset() {
);
$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';
@@ -2561,53 +2561,6 @@ public function testFormInputs() {
);
$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(
@@ -2628,12 +2581,6 @@ public function testFormInputs() {
);
$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(),

0 comments on commit 45fe7eb

Please sign in to comment.