PageRenderTime 32ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/wheels/tests/model/validations/default_validations.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 80 lines | 67 code | 13 blank | 0 comment | 0 complexity | 4807899fce655dcce2cc6f83108ef482 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="setup">
  3. <cfset loc.user = model("UserBlank").new()>
  4. <cfset loc.user.username = "gavin@cfwheels.org">
  5. <cfset loc.user.password = "disismypassword">
  6. <cfset loc.user.firstName = "Gavin">
  7. <cfset loc.user.lastName = "Gavinsson">
  8. </cffunction>
  9. <cffunction name="test_validates_presence_of_invalid">
  10. <cfset StructDelete(loc.user, "username")> <!--- missing key --->
  11. <cfset loc.user.password = ""> <!--- zero length string --->
  12. <cfset loc.user.firstName = " "> <!--- empty string --->
  13. <cfset loc.user.valid()>
  14. <cfset assert('ArrayLen(loc.user.allErrors()) eq 3')>
  15. </cffunction>
  16. <cffunction name="test_validates_presence_of_valid">
  17. <cfset loc.user.password = "something">
  18. <cfset loc.user.firstName = "blahblah">
  19. <cfset assert('loc.user.valid()')>
  20. </cffunction>
  21. <cffunction name="test_validates_length_of_invalid">
  22. <cfset loc.user.state = "Too many characters!">
  23. <cfset loc.user.valid()>
  24. <cfset loc.arrResult = loc.user.errorsOn("state")>
  25. <cfset assert('ArrayLen(loc.arrResult) eq 1 AND loc.arrResult[1].message eq "State is the wrong length"')>
  26. </cffunction>
  27. <cffunction name="test_validates_length_of_valid">
  28. <cfset loc.user.state = "FL">
  29. <cfset assert('loc.user.valid()')>
  30. </cffunction>
  31. <cffunction name="test_validates_numericality_of_invalid">
  32. <cfset loc.user.birthDayMonth = "This is not a number!">
  33. <cfset loc.user.valid()>
  34. <cfset loc.arrResult = loc.user.errorsOn("birthDayMonth")>
  35. <cfset assert('ArrayLen(loc.arrResult) eq 1 AND loc.arrResult[1].message eq "Birthdaymonth is not a number"')>
  36. </cffunction>
  37. <cffunction name="test_validates_numericality_of_valid">
  38. <cfset loc.user.birthDayMonth = "7">
  39. <cfset assert('loc.user.valid()')>
  40. </cffunction>
  41. <cffunction name="test_validates_numericality_of_integer_invalid">
  42. <cfset loc.user.birthDayMonth = "7.825">
  43. <cfset loc.user.valid()>
  44. <cfset loc.arrResult = loc.user.errorsOn("birthDayMonth")>
  45. <cfset assert('ArrayLen(loc.arrResult) eq 1 AND loc.arrResult[1].message eq "Birthdaymonth is not a number"')>
  46. </cffunction>
  47. <cffunction name="test_validates_format_of_date_invalid">
  48. <cfset loc.user.birthDay = "This is not a date!">
  49. <cfset loc.user.valid()>
  50. <cfset loc.arrResult = loc.user.errorsOn("birthDay")>
  51. <cfset assert('ArrayLen(loc.arrResult) eq 1 AND loc.arrResult[1].message eq "Birth day is invalid"')>
  52. </cffunction>
  53. <cffunction name="test_validates_format_of_date_valid">
  54. <cfset loc.user.birthDay = "01/01/2000">
  55. <cfset assert('loc.user.valid()')>
  56. </cffunction>
  57. <cffunction name="test_validates_format_of_time_invalid">
  58. <cfset loc.user.birthTime = "This is not a time!">
  59. <cfset loc.user.valid()>
  60. <cfset loc.arrResult = loc.user.errorsOn("birthTime")>
  61. <cfset assert('ArrayLen(loc.arrResult) eq 1 AND loc.arrResult[1].message eq "Birthtime is invalid"')>
  62. </cffunction>
  63. <cffunction name="test_validates_format_of_time_valid">
  64. <cfset loc.user.birthTime = "6:15 PM">
  65. <cfset assert('loc.user.valid()')>
  66. </cffunction>
  67. </cfcomponent>