Skip to content
Permalink
Browse files

Added 'before' and 'after' options to FormHelper::submit(). Test case…

…s updated.

Signed-off-by: Mark Story <mark@mark-story.com>
  • Loading branch information...
tPl0ch authored and markstory committed Oct 31, 2009
1 parent a855a6a commit 2331cfde60d92bd23b325f15e28ac1a0136f6333
Showing with 87 additions and 6 deletions.
  1. +17 −6 cake/libs/view/helpers/form.php
  2. +70 −0 cake/tests/cases/libs/view/helpers/form.test.php
@@ -1206,13 +1206,24 @@ function submit($caption = null, $options = array()) {
$divOptions = array_merge(array('class' => 'submit', 'tag' => 'div'), $div);
}
$before = "";
$after = "";
if (isset($options['before'])) {
$before = $options['before'];
unset($options['before']);
}
if (isset($options['after'])) {
$after = $options['after'];
unset($options['after']);
}
if (strpos($caption, '://') !== false) {
unset($options['type']);
$out .= $this->output(sprintf(
$out .= $this->output($before . sprintf(
$this->Html->tags['submitimage'],
$caption,
$this->_parseAttributes($options, null, '', ' ')
));
) . $after);
} elseif (preg_match('/\.(jpg|jpe|jpeg|gif|png|ico)$/', $caption)) {
unset($options['type']);
if ($caption{0} !== '/') {
@@ -1221,17 +1232,17 @@ function submit($caption = null, $options = array()) {
$caption = trim($caption, '/');
$url = $this->webroot($caption);
}
$out .= $this->output(sprintf(
$out .= $this->output($before . sprintf(
$this->Html->tags['submitimage'],
$url,
$this->_parseAttributes($options, null, '', ' ')
));
) . $after);
} else {
$options['value'] = $caption;
$out .= $this->output(sprintf(
$out .= $this->output($before . sprintf(
$this->Html->tags['submit'],
$this->_parseAttributes($options, null, '', ' ')
));
). $after);
}
if (isset($divOptions)) {
@@ -4667,6 +4667,36 @@ function testSubmitButton() {
'/div'
);
$this->assertTags($result, $expected);
$before = '--before--';
$after = '--after--';
$result = $this->Form->submit('Test', array('before' => $before));
$expected = array(
'div' => array('class' => 'submit'),
'--before--',
'input' => array('type' => 'submit', 'value' => 'Test'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Test', array('after' => $after));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'Test'),
'--after--',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Test', array('before' => $before, 'after' => $after));
$expected = array(
'div' => array('class' => 'submit'),
'--before--',
'input' => array('type' => 'submit', 'value' => 'Test'),
'--after--',
'/div'
);
$this->assertTags($result, $expected);
}
/**
@@ -4706,6 +4736,46 @@ function testSubmitImage() {
'/div'
);
$this->assertTags($result, $expected);
$after = '--after--';
$before = '--before--';
$result = $this->Form->submit('cake.power.gif', array('after' => $after));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
'--after--',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('cake.power.gif', array('before' => $before));
$expected = array(
'div' => array('class' => 'submit'),
'--before--',
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('cake.power.gif', array('before' => $before, 'after' => $after));
$expected = array(
'div' => array('class' => 'submit'),
'--before--',
'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'),
'--after--',
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->submit('Not.an.image', array('before' => $before, 'after' => $after));
$expected = array(
'div' => array('class' => 'submit'),
'--before--',
'input' => array('type' => 'submit', 'value' => 'Not.an.image'),
'--after--',
'/div'
);
$this->assertTags($result, $expected);
}
/**

0 comments on commit 2331cfd

Please sign in to comment.
You can’t perform that action at this time.