PageRenderTime 46ms CodeModel.GetById 22ms RepoModel.GetById 1ms 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
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="setup">
  3. <cfset loc.controller = controller(name="ControllerWithModel")>
  4. <cfset loc.user = model("user")>
  5. </cffunction>
  6. <cffunction name="test_with_list_as_options">
  7. <cfset loc.options = "Opt1,Opt2">
  8. <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.options, label=false)>
  9. <cfset loc.e = '<select id="user-firstname" name="user[firstname]"><option value="Opt1">Opt1</option><option value="Opt2">Opt2</option></select>'>
  10. <cfset assert('loc.e eq loc.r')>
  11. </cffunction>
  12. <cffunction name="test_with_array_as_options">
  13. <cfset loc.options = ArrayNew(1)>
  14. <cfset loc.options[1] = "Opt1">
  15. <cfset loc.options[2] = "Opt2">
  16. <cfset loc.options[3] = "Opt3">
  17. <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.options, label=false)>
  18. <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>'>
  19. <cfset assert('loc.e eq loc.r')>
  20. </cffunction>
  21. <cffunction name="test_with_struct_as_options">
  22. <cfset loc.options = StructNew()>
  23. <cfset loc.options.x = "xVal">
  24. <cfset loc.options.y = "yVal">
  25. <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.options, label=false)>
  26. <cfset loc.e = '<select id="user-firstname" name="user[firstname]"><option value="x">xVal</option><option value="y">yVal</option></select>'>
  27. <cfset assert('loc.e eq loc.r')>
  28. </cffunction>
  29. <cffunction name="test_setting_text_field">
  30. <cfset loc.users = loc.user.findAll(returnAs="objects", order="id")>
  31. <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.users, valueField="id", textField="firstName", label=false)>
  32. <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>'>
  33. <cfset assert('loc.e eq loc.r')>
  34. </cffunction>
  35. <cffunction name="test_first_non_numeric_property_default_text_field_on_query">
  36. <cfset loc.users = loc.user.findAll(returnAs="query", order="id")>
  37. <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.users, label=false)>
  38. <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>'>
  39. <cfset assert('loc.e eq loc.r')>
  40. </cffunction>
  41. <cffunction name="test_first_non_numeric_property_default_text_field_on_objects">
  42. <cfset loc.users = loc.user.findAll(returnAs="objects", 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[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>'>
  45. <cfset assert('loc.e eq loc.r')>
  46. </cffunction>
  47. <cffunction name="test_with_array_of_structs_as_options">
  48. <cfset loc.options = []>
  49. <cfset loc.options[1].tony = "petruzzi">
  50. <cfset loc.options[2].per = "djurner">
  51. <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.options, label=false)>
  52. <cfset loc.e = '<select id="user-firstname" name="user[firstname]"><option value="petruzzi">tony</option><option value="djurner">per</option></select>'>
  53. <cfset assert('loc.e eq loc.r')>
  54. </cffunction>
  55. <cffunction name="test_with_array_of_structs_as_options_2">
  56. <cfset loc.options = []>
  57. <cfset loc.options[1] = {value="petruzzi", name="tony"}>
  58. <cfset loc.options[2] = {value="djurner", name="per"}>
  59. <cfset loc.r = loc.controller.select(objectName="user", property="firstname", options=loc.options, valueField="value", textField="name", 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. </cfcomponent>