PageRenderTime 183ms CodeModel.GetById 81ms app.highlight 1ms RepoModel.GetById 99ms app.codeStats 0ms

/wheels/tests/view/forms/select.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 73 lines | 63 code | 10 blank | 0 comment | 0 complexity | 1220b90ec6e1a46b990bd2eadfdfe907 MD5 | raw file
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cffunction name="setup">
 4		<cfset loc.controller = controller(name="ControllerWithModel")>
 5		<cfset loc.user = model("user")>
 6	</cffunction>
 7
 8	<cffunction name="test_with_list_as_options">
 9		<cfset loc.options = "Opt1,Opt2">
10	    <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.options, label=false)>
11	    <cfset loc.e = '<select id="user-firstname" name="user[firstname]"><option value="Opt1">Opt1</option><option value="Opt2">Opt2</option></select>'>
12	    <cfset assert('loc.e eq loc.r')>
13	</cffunction>
14
15	<cffunction name="test_with_array_as_options">
16		<cfset loc.options = ArrayNew(1)>
17		<cfset loc.options[1] = "Opt1">
18		<cfset loc.options[2] = "Opt2">
19		<cfset loc.options[3] = "Opt3">
20	    <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.options, label=false)>
21	    <cfset loc.e = '<select id="user-firstname" name="user[firstname]"><option value="Opt1">Opt1</option><option value="Opt2">Opt2</option><option value="Opt3">Opt3</option></select>'>
22	    <cfset assert('loc.e eq loc.r')>
23	</cffunction>
24
25	<cffunction name="test_with_struct_as_options">
26		<cfset loc.options = StructNew()>
27		<cfset loc.options.x = "xVal">
28		<cfset loc.options.y = "yVal">
29	    <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.options, label=false)>
30	    <cfset loc.e = '<select id="user-firstname" name="user[firstname]"><option value="x">xVal</option><option value="y">yVal</option></select>'>
31	    <cfset assert('loc.e eq loc.r')>
32	</cffunction>
33
34	<cffunction name="test_setting_text_field">
35		<cfset loc.users = loc.user.findAll(returnAs="objects", order="id")>
36	    <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.users, valueField="id", textField="firstName", label=false)>
37	    <cfset loc.e = '<select id="user-firstname" name="user[firstname]"><option value="#loc.users[1].id#">Tony</option><option value="#loc.users[2].id#">Chris</option><option value="#loc.users[3].id#">Per</option><option value="#loc.users[4].id#">Raul</option><option value="#loc.users[5].id#">Joe</option></select>'>
38	    <cfset assert('loc.e eq loc.r')>
39	</cffunction>
40
41	<cffunction name="test_first_non_numeric_property_default_text_field_on_query">
42		<cfset loc.users = loc.user.findAll(returnAs="query", order="id")>
43	    <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.users, label=false)>
44	    <cfset loc.e = '<select id="user-firstname" name="user[firstname]"><option value="#loc.users["id"][1]#">tonyp</option><option value="#loc.users["id"][2]#">chrisp</option><option value="#loc.users["id"][3]#">perd</option><option value="#loc.users["id"][4]#">raulr</option><option value="#loc.users["id"][5]#">joeb</option></select>'>
45	    <cfset assert('loc.e eq loc.r')>
46	</cffunction>
47
48	<cffunction name="test_first_non_numeric_property_default_text_field_on_objects">
49		<cfset loc.users = loc.user.findAll(returnAs="objects", order="id")>
50	    <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.users, label=false)>
51	    <cfset loc.e = '<select id="user-firstname" name="user[firstname]"><option value="#loc.users[1].id#">tonyp</option><option value="#loc.users[2].id#">chrisp</option><option value="#loc.users[3].id#">perd</option><option value="#loc.users[4].id#">raulr</option><option value="#loc.users[5].id#">joeb</option></select>'>
52	    <cfset assert('loc.e eq loc.r')>
53	</cffunction>
54
55	<cffunction name="test_with_array_of_structs_as_options">
56		<cfset loc.options = []>
57		<cfset loc.options[1].tony = "petruzzi">
58		<cfset loc.options[2].per = "djurner">
59	    <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.options, label=false)>
60	    <cfset loc.e = '<select id="user-firstname" name="user[firstname]"><option value="petruzzi">tony</option><option value="djurner">per</option></select>'>
61	    <cfset assert('loc.e eq loc.r')>
62	</cffunction>
63
64	<cffunction name="test_with_array_of_structs_as_options_2">
65		<cfset loc.options = []>
66		<cfset loc.options[1] = {value="petruzzi", name="tony"}>
67		<cfset loc.options[2] = {value="djurner", name="per"}>
68	    <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.options, valueField="value", textField="name", label=false)>
69	    <cfset loc.e = '<select id="user-firstname" name="user[firstname]"><option value="petruzzi">tony</option><option value="djurner">per</option></select>'>
70	    <cfset assert('loc.e eq loc.r')>
71	</cffunction>
72
73</cfcomponent>