[DomCrawler] Fixed incorrect handling of image inputs

This commit is contained in:
Robbert Klarenbeek 2014-02-04 21:32:28 +01:00
parent 6a4d765c43
commit 816cf179ee
2 changed files with 23 additions and 1 deletions

View File

@ -384,7 +384,24 @@ class Form extends Link implements \ArrayAccess
// add submitted button if it has a valid name
if ('form' !== $this->button->nodeName && $this->button->hasAttribute('name') && $this->button->getAttribute('name')) {
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
if ('input' == $this->button->nodeName && 'image' == $this->button->getAttribute('type')) {
$name = $this->button->getAttribute('name');
$this->button->setAttribute('value', '0');
// temporarily change the name of the input node for the x coordinate
$this->button->setAttribute('name', $name.'.x');
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
// temporarily change the name of the input node for the y coordinate
$this->button->setAttribute('name', $name.'.y');
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
// restore the original name of the input node
$this->button->setAttribute('name', $name);
}
else {
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
}
}
// find form elements corresponding to the current form

View File

@ -223,6 +223,11 @@ class FormTest extends \PHPUnit_Framework_TestCase
<input type="submit" name="foobar" value="foobar" />',
array('foobar' => array('InputFormField', 'foobar')),
),
array(
'turns an image input into x and y fields',
'<input type="image" name="bar" />',
array('bar.x' => array('InputFormField', '0'), 'bar.y' => array('InputFormField', '0')),
),
array(
'returns textareas',
'<textarea name="foo">foo</textarea>