updating FormHelper::inputs(), fixes #3770, tests updated

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6280 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-12-30 18:25:00 +00:00
parent a1198bb3b7
commit fdeb41a826
2 changed files with 17 additions and 8 deletions

View file

@ -444,8 +444,8 @@ class FormHelper extends AppHelper {
unset($fields['fieldset']);
}
} elseif ($fields !== null) {
$legend = $fields;
unset($fields);
$fieldset = $legend = $fields;
$fields = array();
}
if (empty($fields)) {
@ -473,8 +473,10 @@ class FormHelper extends AppHelper {
$out .= $this->input($name, $options);
}
if ($fieldset) {
if ($fieldset && $legend) {
return sprintf($this->Html->tags['fieldset'], $legend, $out);
} elseif ($fieldset) {
return sprintf("<fieldset>%s</fieldset>", $out);
} else {
return $out;
}

View file

@ -487,17 +487,24 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->inputs();
$this->assertPattern('/<legend>Edit Contact<\/legend>/', $result);
$result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
$this->assertPattern('/<fieldset[^<>]*>/', $result);
$this->assertNoPattern('/<legend>[^<>]+<\/legend>/', $result);
$result = $this->Form->inputs(false);
$this->assertNoPattern('/<fieldset[^<>]*>/', $result);
$this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result);
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => false));
$this->assertNoPattern('/<fieldset[^<>]*>/', $result);
$this->assertNoPattern('/<legend>[^<>]+<\/legend>/', $result);
$this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result);
$result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
$this->assertPattern('/<fieldset[^<>]*>/', $result);
$this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result);
$result = $this->Form->inputs(array('fieldset' => false, 'legend' => 'Hello'));
$this->assertNoPattern('/<fieldset[^<>]*>/', $result);
$this->assertNoPattern('/<legend>[^<>]+<\/legend>/', $result);
$this->assertNoPattern('/<legend>[^<>]*<\/legend>/', $result);
$result = $this->Form->inputs('Hello');
$this->assertPattern('/^<fieldset><legend[^<>]*>Hello<\/legend>.+<\/fieldset>$/s', $result);
$result = $this->Form->inputs(array('legend' => 'Hello'));
$this->assertPattern('/^<fieldset><legend[^<>]*>Hello<\/legend>.+<\/fieldset>$/s', $result);