Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions src/Symfony/Component/DomCrawler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

4.4.0
-----

* Added `Form::getName()` method.

4.3.0
-----

Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/DomCrawler/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ public function getMethod()
return $this->node->getAttribute('method') ? strtoupper($this->node->getAttribute('method')) : 'GET';
}

/**
* Gets the form name.
*
* If no name is defined on the form, an empty string is returned.
*/
public function getName(): string
{
return $this->node->getAttribute('name');
}

/**
* Returns true if the named field exists.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,18 @@ public function testGetMethodWithOverride()
$this->assertEquals('POST', $form->getMethod(), '->getMethod() returns the method attribute value of the form');
}

public function testGetName()
{
$form = $this->createForm('<form name="foo"><input type="submit" /></form>');
$this->assertSame('foo', $form->getName());
}

public function testGetNameOnFormWithoutName()
{
$form = $this->createForm('<form><input type="submit" /></form>');
$this->assertSame('', $form->getName());
}

public function testGetSetValue()
{
$form = $this->createForm('<form><input type="text" name="foo" value="foo" /><input type="submit" /></form>');
Expand Down