8000 [DomCrawler] Attach label to form fields by carlosV2 · Pull Request #18322 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DomCrawler] Attach label to form fields #18322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow field to havel a label attached
  • Loading branch information
Carlos Ortega Huetos committed Mar 26, 2016
commit 08e6ee160678646cbfa456434b529eba34c4fca1
20 changes: 18 additions & 2 deletions src/Symfony/Component/DomCrawler/Field/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ abstract class FormField
* @var \DOMElement
*/
protected $node;
/**
* @var \DOMElement
*/
protected $label;
/**
* @var string
*/
Expand All @@ -46,17 +50,29 @@ abstract class FormField
/**
* Constructor.
*
* @param \DOMElement $node The node associated with this field
* @param \DOMElement $node The node associated with this field
* @param \DOMElement|null $label The label associated with this field
*/
public function __construct(\DOMElement $node)
public function __construct(\DOMElement $node, \DOMElement $label = null)
{
$this->node = $node;
$this->label = $label;
$this->name = $node->getAttribute('name');
$this->xpath = new \DOMXPath($node->ownerDocument);

$this->initialize();
}

/**
* Returns the label tag associated to the field or null if none
*
* @return \DOMElement|null
*/
public function getLabel()
{
return $this->label;
}

/**
* Returns the name of the field.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/Field/FormFieldTest.php
6784
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@ public function testGetSetHasValue()

$this->assertTrue($field->hasValue(), '->hasValue() always returns true');
}

public function testGetLabel()
{
$node = $this->createNode('input', '', array());
$label = $this->createNode('label', '', array());

$field = new InputFormField($node);
$this->assertNull($field->getLabel(), '->getLabel() returns null if none associated');

$field = new InputFormField($node, $label);
$this->assertEquals($label, $field->getLabel(), '->getLabel() returns the field label');
}
}
0