Skip to content
This repository
Browse code

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.
  • Loading branch information...
commit 78c15ea882cd7501d146f39f4e9d169dedbd3862 1 parent ce3d48e
authored June 13, 2012 chillu committed June 13, 2012
5  forms/FormAction.php
@@ -80,12 +80,15 @@ public function Type() {
80 80
 	}
81 81
 
82 82
 	function getAttributes() {
  83
+		$type = (isset($this->attributes['src'])) ? 'image' : 'submit';
  84
+		$type = ($this->useButtonTag) ? null : $type;
  85
+		
83 86
 		return array_merge(
84 87
 			parent::getAttributes(),
85 88
 			array(
86 89
 				'disabled' => ($this->isReadonly() || $this->isDisabled()),
87 90
 				'value' => $this->Title(),
88  
-				'type' => ($this->useButtonTag) ? null : 'submit',
  91
+				'type' => $type,
89 92
 				'title' => ($this->useButtonTag) ? $this->description : null,
90 93
 			)
91 94
 		);
2  forms/FormField.php
@@ -357,7 +357,7 @@ function getAttribute($name) {
357 357
 		$attrs = $this->getAttributes();
358 358
 		return @$attrs[$name];
359 359
 	}
360  
-
  360
+	
361 361
 	/**
362 362
 	 * @return array
363 363
 	 */
16  tests/forms/FormActionTest.php
... ...
@@ -0,0 +1,16 @@
  1
+<?php
  2
+
  3
+/**
  4
+ * @package framework
  5
+ * @subpackage tests
  6
+ */
  7
+class FormActionTest extends SapphireTest {
  8
+	
  9
+	public function testGetField() {
  10
+		$formAction = new FormAction('test');
  11
+		$this->assertContains('type="submit"',  $formAction->getAttributesHTML());
  12
+
  13
+		$formAction->setAttribute('src', 'file.png');
  14
+		$this->assertContains('type="image"', $formAction->getAttributesHTML());
  15
+	}
  16
+}

0 notes on commit 78c15ea

Please sign in to comment.
Something went wrong with that request. Please try again.