Added the Porter Stemmer module to improve searches. This doesn't deal with some...
[yaffs-website] / vendor / symfony / dom-crawler / Tests / Field / FormFieldTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DomCrawler\Tests\Field;
13
14 use Symfony\Component\DomCrawler\Field\InputFormField;
15
16 class FormFieldTest extends FormFieldTestCase
17 {
18     public function testGetName()
19     {
20         $node = $this->createNode('input', '', array('type' => 'text', 'name' => 'name', 'value' => 'value'));
21         $field = new InputFormField($node);
22
23         $this->assertEquals('name', $field->getName(), '->getName() returns the name of the field');
24     }
25
26     public function testGetSetHasValue()
27     {
28         $node = $this->createNode('input', '', array('type' => 'text', 'name' => 'name', 'value' => 'value'));
29         $field = new InputFormField($node);
30
31         $this->assertEquals('value', $field->getValue(), '->getValue() returns the value of the field');
32
33         $field->setValue('foo');
34         $this->assertEquals('foo', $field->getValue(), '->setValue() sets the value of the field');
35
36         $this->assertTrue($field->hasValue(), '->hasValue() always returns true');
37     }
38
39     public function testLabelReturnsNullIfNoneIsDefined()
40     {
41         $dom = new \DOMDocument();
42         $dom->loadHTML('<html><form><input type="text" id="foo" name="foo" value="foo" /><input type="submit" /></form></html>');
43
44         $field = new InputFormField($dom->getElementById('foo'));
45         $this->assertNull($field->getLabel(), '->getLabel() returns null if no label is defined');
46     }
47
48     public function testLabelIsAssignedByForAttribute()
49     {
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" />
55         </form></html>');
56
57         $field = new InputFormField($dom->getElementById('foo'));
58         $this->assertEquals('Foo label', $field->getLabel()->textContent, '->getLabel() returns the associated label');
59     }
60
61     public function testLabelIsAssignedByParentingRelation()
62     {
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" />
67         </form></html>');
68
69         $field = new InputFormField($dom->getElementById('foo'));
70         $this->assertEquals('Foo label', $field->getLabel()->textContent, '->getLabel() returns the parent label');
71     }
72 }