From e76601e5c8c9b67ca1105958b556b355375ae6bb Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 29 Oct 2019 17:19:22 +1300 Subject: [PATCH] BUG FormAction title property cannot be set if useButtonTag is false --- src/Forms/FormAction.php | 17 +++++++++++------ tests/php/Forms/FormActionTest.php | 13 +++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Forms/FormAction.php b/src/Forms/FormAction.php index 2e3556f9a..8f2320dfd 100644 --- a/src/Forms/FormAction.php +++ b/src/Forms/FormAction.php @@ -184,15 +184,20 @@ class FormAction extends FormField public function getAttributes() { - return array_merge( + $attributes = array_merge( parent::getAttributes(), - array( + [ 'disabled' => ($this->isReadonly() || $this->isDisabled()), - 'value' => $this->Title(), - 'type' => $this->getInputType(), - 'title' => ($this->useButtonTag) ? $this->description : null, - ) + 'value' => $this->Title(), + 'type' => $this->getInputType(), + ] ); + + // Override title with description if supplied + if ($this->getDescription()) { + $attributes['title'] = $this->getDescription(); + } + return $attributes; } /** diff --git a/tests/php/Forms/FormActionTest.php b/tests/php/Forms/FormActionTest.php index 6891832e5..328aadb79 100644 --- a/tests/php/Forms/FormActionTest.php +++ b/tests/php/Forms/FormActionTest.php @@ -16,4 +16,17 @@ class FormActionTest extends SapphireTest $formAction->setAttribute('src', 'file.png'); $this->assertContains('type="image"', $formAction->getAttributesHTML()); } + + public function testGetTitle() + { + // Test that description overrides title attribute, but doesn't prevent it from + // working if blank. + $action = new FormAction('test'); + $action->setAttribute('title', 'this is the title'); + $this->assertEquals('this is the title', $action->getAttribute('title')); + $action->setDescription('this is a better title'); + $this->assertEquals('this is a better title', $action->getAttribute('title')); + $action->setDescription(null); + $this->assertEquals('this is the title', $action->getAttribute('title')); + } }