From 78c15ea882cd7501d146f39f4e9d169dedbd3862 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Wed, 13 Jun 2012 09:57:54 +0200 Subject: [PATCH] BUGFIX: Fix correct input type for ImageFormAction replaces. ImageFormAction is deprecated, using the new API results in a submit input rather than an image input being generated. Added hasAttribute helper to FormField as well as test coverage. --- forms/FormAction.php | 5 ++++- forms/FormField.php | 2 +- tests/forms/FormActionTest.php | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/forms/FormActionTest.php diff --git a/forms/FormAction.php b/forms/FormAction.php index 2fb01f0ee..e273a0d4e 100644 --- a/forms/FormAction.php +++ b/forms/FormAction.php @@ -80,12 +80,15 @@ class FormAction extends FormField { } function getAttributes() { + $type = (isset($this->attributes['src'])) ? 'image' : 'submit'; + $type = ($this->useButtonTag) ? null : $type; + return array_merge( parent::getAttributes(), array( 'disabled' => ($this->isReadonly() || $this->isDisabled()), 'value' => $this->Title(), - 'type' => ($this->useButtonTag) ? null : 'submit', + 'type' => $type, 'title' => ($this->useButtonTag) ? $this->description : null, ) ); diff --git a/forms/FormField.php b/forms/FormField.php index 023f6621c..29d4f8130 100644 --- a/forms/FormField.php +++ b/forms/FormField.php @@ -357,7 +357,7 @@ class FormField extends RequestHandler { $attrs = $this->getAttributes(); return @$attrs[$name]; } - + /** * @return array */ diff --git a/tests/forms/FormActionTest.php b/tests/forms/FormActionTest.php new file mode 100644 index 000000000..3e313f846 --- /dev/null +++ b/tests/forms/FormActionTest.php @@ -0,0 +1,16 @@ +assertContains('type="submit"', $formAction->getAttributesHTML()); + + $formAction->setAttribute('src', 'file.png'); + $this->assertContains('type="image"', $formAction->getAttributesHTML()); + } +} \ No newline at end of file