Skip to content

Commit

Permalink
Remove deprecated parameters and update tests.
Browse files Browse the repository at this point in the history
Remove deprecated forms of inputs() and update tests. Shuffle tests
around to match the separation added earlier.
  • Loading branch information
markstory committed Mar 4, 2014
1 parent 417bfd8 commit 45fe7eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 84 deletions.
26 changes: 7 additions & 19 deletions src/View/Helper/FormHelper.php
Expand Up @@ -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.
Expand All @@ -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)) {
Expand All @@ -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 = (
Expand All @@ -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) {
Expand Down
77 changes: 12 additions & 65 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand All @@ -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(),
Expand Down

0 comments on commit 45fe7eb

Please sign in to comment.