@@ -35,4 +35,38 @@ public function testGetSetHasValue()
35
35
36
36
$ this ->assertTrue ($ field ->hasValue (), '->hasValue() always returns true ' );
37
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
+ }
38
72
}
0 commit comments