PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 2ms

/wheels/tests/view/forms/label.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 93 lines | 76 code | 17 blank | 0 comment | 0 complexity | 9368620831c89de73668ebcc343849d8 MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cfinclude template="/wheelsMapping/view/functions.cfm">
 4
 5	<!--- plain helpers --->
 6	
 7	<cffunction name="test_custom_label_on_plain_helper">
 8		<cfset loc.actual = checkBoxTag(name="the-name", label="The Label:")>
 9		<cfset loc.expected = '<label for="the-name-1">The Label:<input id="the-name-1" name="the-name" type="checkbox" value="1" /></label>'>
10		<cfset assert('loc.actual eq loc.expected')>
11	</cffunction>
12
13	<cffunction name="test_custom_label_on_plain_helper_and_overriding_id">
14		<cfset loc.actual = checkBoxTag(name="the-name", label="The Label:", id="the-id")>
15		<cfset loc.expected = '<label for="the-id">The Label:<input id="the-id" name="the-name" type="checkbox" value="1" /></label>'>
16		<cfset assert('loc.actual eq loc.expected')>
17	</cffunction>
18
19	<cffunction name="test_blank_label_on_plain_helper">
20		<cfset loc.actual = textFieldTag(name="the-name", label="")>
21		<cfset loc.expected = '<input id="the-name" name="the-name" type="text" value="" />'>
22		<cfset assert('loc.actual eq loc.expected')>
23	</cffunction>
24
25
26	<!--- object based helpers --->
27
28	<cffunction name="test_custom_label_on_object_helper">
29		<cfset tag = model("tag").findOne()>
30		<cfset loc.actual = textField(objectName="tag", property="name", label="The Label:")>
31		<cfset loc.expected = '<label for="tag-name">The Label:<input id="tag-name" maxlength="50" name="tag[name]" type="text" value="releases" /></label>'>
32		<cfset assert('loc.actual eq loc.expected')>
33	</cffunction>
34
35	<cffunction name="test_custom_label_on_object_helper_and_overriding_id">
36		<cfset tag = model("tag").findOne()>
37		<cfset loc.actual = textField(objectName="tag", property="name", label="The Label:", id="the-id")>
38		<cfset loc.expected = '<label for="the-id">The Label:<input id="the-id" maxlength="50" name="tag[name]" type="text" value="releases" /></label>'>
39		<cfset assert('loc.actual eq loc.expected')>
40	</cffunction>
41
42	<cffunction name="test_blank_label_on_object_helper">
43		<cfset tag = model("tag").findOne()>
44		<cfset loc.actual = textField(objectName="tag", property="name", label="")>
45		<cfset loc.expected = '<input id="tag-name" maxlength="50" name="tag[name]" type="text" value="releases" />'>
46		<cfset assert('loc.actual eq loc.expected')>
47	</cffunction>
48	
49	<cffunction name="test_automatic_label_on_object_helper_with_around_placement">
50		<cfset tag = model("tag").findOne()>
51		<cfset loc.actual = textField(objectName="tag", property="name", labelPlacement="around")>
52		<cfset loc.expected = '<label for="tag-name">Tag name<input id="tag-name" maxlength="50" name="tag[name]" type="text" value="releases" /></label>'>
53		<cfset assert('loc.actual eq loc.expected')>
54	</cffunction>	
55
56	<cffunction name="test_automatic_label_on_object_helper_with_before_placement">
57		<cfset tag = model("tag").findOne()>
58		<cfset loc.actual = textField(objectName="tag", property="name", labelPlacement="before")>
59		<cfset loc.expected = '<label for="tag-name">Tag name</label><input id="tag-name" maxlength="50" name="tag[name]" type="text" value="releases" />'>
60		<cfset assert('loc.actual eq loc.expected')>
61	</cffunction>
62
63	<cffunction name="test_automatic_label_on_object_helper_with_after_placement">
64		<cfset tag = model("tag").findOne()>
65		<cfset loc.actual = textField(objectName="tag", property="name", labelPlacement="after")>
66		<cfset loc.expected = '<input id="tag-name" maxlength="50" name="tag[name]" type="text" value="releases" /><label for="tag-name">Tag name</label>'>
67		<cfset assert('loc.actual eq loc.expected')>
68	</cffunction>	
69	
70	<cffunction name="test_automatic_label_on_object_helper_with_non_persisted_property">
71		<cfset tag = model("tag").findOne()>
72		<cfset loc.actual = textField(objectName="tag", property="virtual")>
73		<cfset loc.expected = '<label for="tag-virtual">Virtual property<input id="tag-virtual" name="tag[virtual]" type="text" value="" /></label>'>
74		<cfset assert('loc.actual eq loc.expected')>
75	</cffunction>
76	
77	<cffunction name="test_automatic_label_in_error_message">
78		<cfset tag = Duplicate(model("tag").new())> <!--- use a deep copy so as not to affect the cached model --->
79		<cfset tag.validatesPresenceOf(property="name")>
80		<cfset tag.valid()>
81		<cfset loc.errors = tag.errorsOn(property="name")>
82		<cfset assert('ArrayLen(loc.errors) eq 1 and loc.errors[1].message is "Tag name can''t be empty"')>
83	</cffunction>
84	
85	<cffunction name="test_automatic_label_in_error_message_with_non_persisted_property">
86		<cfset tag = Duplicate(model("tag").new())>
87		<cfset tag.validatesPresenceOf(property="virtual")>
88		<cfset tag.valid()>
89		<cfset loc.errors = tag.errorsOn(property="virtual")>
90		<cfset assert('ArrayLen(loc.errors) eq 1 and loc.errors[1].message is "Virtual property can''t be empty"')>
91	</cffunction>
92
93</cfcomponent>