merged branch li0n12/crawler_button (PR #5699)
This PR was merged into the 2.0 branch.
Commits
-------
b439d13
fixed DomCrwaler/Form to handle <button> when submitted
Discussion
----------
[DomCrawler] fixed Form to handle <button> when submitted
Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT
Issue appears when submitting form with <button> form element.
Name-value of this button wasn`t passed to the request.
This commit is contained in:
commit
f19e4b51d2
@ -30,8 +30,8 @@ class InputFormField extends FormField
|
|||||||
*/
|
*/
|
||||||
protected function initialize()
|
protected function initialize()
|
||||||
{
|
{
|
||||||
if ('input' != $this->node->nodeName) {
|
if ('input' != $this->node->nodeName && 'button' != $this->node->nodeName) {
|
||||||
throw new \LogicException(sprintf('An InputFormField can only be created from an input tag (%s given).', $this->node->nodeName));
|
throw new \LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $this->node->nodeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('checkbox' == $this->node->getAttribute('type')) {
|
if ('checkbox' == $this->node->getAttribute('type')) {
|
||||||
|
@ -293,7 +293,7 @@ class Form extends Link implements \ArrayAccess
|
|||||||
$root->appendChild($button);
|
$root->appendChild($button);
|
||||||
$xpath = new \DOMXPath($document);
|
$xpath = new \DOMXPath($document);
|
||||||
|
|
||||||
foreach ($xpath->query('descendant::input | descendant::textarea | descendant::select', $root) as $node) {
|
foreach ($xpath->query('descendant::input | descendant::button | descendant::textarea | descendant::select', $root) as $node) {
|
||||||
if (!$node->hasAttribute('name')) {
|
if (!$node->hasAttribute('name')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,11 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
|||||||
'<input type="submit" name="bar" value="bar" />',
|
'<input type="submit" name="bar" value="bar" />',
|
||||||
array('bar' => array('Symfony\\Component\\DomCrawler\\Field\\InputFormField', 'bar')),
|
array('bar' => array('Symfony\\Component\\DomCrawler\\Field\\InputFormField', 'bar')),
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'appends the submitted button value for Button element',
|
||||||
|
'<button type="submit" name="bar" value="bar">Bar</button>',
|
||||||
|
array('bar' => array('Symfony\\Component\\DomCrawler\\Field\\InputFormField', 'bar')),
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'appends the submitted button value but not other submit buttons',
|
'appends the submitted button value but not other submit buttons',
|
||||||
'<input type="submit" name="bar" value="bar" />
|
'<input type="submit" name="bar" value="bar" />
|
||||||
@ -404,7 +409,8 @@ class FormTest extends \PHPUnit_Framework_TestCase
|
|||||||
$dom = new \DOMDocument();
|
$dom = new \DOMDocument();
|
||||||
$dom->loadHTML('<html>'.$form.'</html>');
|
$dom->loadHTML('<html>'.$form.'</html>');
|
||||||
|
|
||||||
$nodes = $dom->getElementsByTagName('input');
|
$xPath = new \DOMXPath($dom);
|
||||||
|
$nodes = $xPath->query('//input | //button');
|
||||||
|
|
||||||
if (null === $currentUri) {
|
if (null === $currentUri) {
|
||||||
$currentUri = 'http://example.com/';
|
$currentUri = 'http://example.com/';
|
||||||
|
Reference in New Issue
Block a user