[DomCrawler] Fixed creating form objects from form nodes.

This commit is contained in:
Jakub Zalas 2013-12-29 12:45:05 +01:00
parent 83eea20bd8
commit 72d6322e25
2 changed files with 11 additions and 1 deletions

View File

@ -383,7 +383,7 @@ class Form extends Link implements \ArrayAccess
$root = $document->appendChild($document->createElement('_root'));
// add submitted button if it has a valid name
if ($this->button->hasAttribute('name') && $this->button->getAttribute('name')) {
if ('form' !== $this->button->nodeName && $this->button->hasAttribute('name') && $this->button->getAttribute('name')) {
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
}

View File

@ -273,6 +273,16 @@ class FormTest extends \PHPUnit_Framework_TestCase
$this->assertSame($dom->getElementsByTagName('form')->item(0), $form->getFormNode(), '->getFormNode() returns the form node associated with this form');
}
public function testGetFormNodeFromNamedForm()
{
$dom = new \DOMDocument();
$dom->loadHTML('<html><form name="my_form"><input type="submit" /></form></html>');
$form = new Form($dom->getElementsByTagName('form')->item(0), 'http://example.com');
$this->assertSame($dom->getElementsByTagName('form')->item(0), $form->getFormNode(), '->getFormNode() returns the form node associated with this form');
}
public function testGetMethod()
{
$form = $this->createForm('<form><input type="submit" /></form>');