4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DomCrawler\Tests\Field;
14 use Symfony\Component\DomCrawler\Field\InputFormField;
16 class FormFieldTest extends FormFieldTestCase
18 public function testGetName()
20 $node = $this->createNode('input', '', array('type' => 'text', 'name' => 'name', 'value' => 'value'));
21 $field = new InputFormField($node);
23 $this->assertEquals('name', $field->getName(), '->getName() returns the name of the field');
26 public function testGetSetHasValue()
28 $node = $this->createNode('input', '', array('type' => 'text', 'name' => 'name', 'value' => 'value'));
29 $field = new InputFormField($node);
31 $this->assertEquals('value', $field->getValue(), '->getValue() returns the value of the field');
33 $field->setValue('foo');
34 $this->assertEquals('foo', $field->getValue(), '->setValue() sets the value of the field');
36 $this->assertTrue($field->hasValue(), '->hasValue() always returns true');
39 public function testLabelReturnsNullIfNoneIsDefined()
41 $dom = new \DOMDocument();
42 $dom->loadHTML('<html><form><input type="text" id="foo" name="foo" value="foo" /><input type="submit" /></form></html>');
44 $field = new InputFormField($dom->getElementById('foo'));
45 $this->assertNull($field->getLabel(), '->getLabel() returns null if no label is defined');
48 public function testLabelIsAssignedByForAttribute()
50 $dom = new \DOMDocument();
51 $dom->loadHTML('<html><form>
52 <label for="foo">Foo label</label>
53 <input type="text" id="foo" name="foo" value="foo" />
54 <input type="submit" />
57 $field = new InputFormField($dom->getElementById('foo'));
58 $this->assertEquals('Foo label', $field->getLabel()->textContent, '->getLabel() returns the associated label');
61 public function testLabelIsAssignedByParentingRelation()
63 $dom = new \DOMDocument();
64 $dom->loadHTML('<html><form>
65 <label for="foo">Foo label<input type="text" id="foo" name="foo" value="foo" /></label>
66 <input type="submit" />
69 $field = new InputFormField($dom->getElementById('foo'));
70 $this->assertEquals('Foo label', $field->getLabel()->textContent, '->getLabel() returns the parent label');