PageRenderTime 50ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/tests/model/errors/errors.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 171 lines | 160 code | 11 blank | 0 comment | 0 complexity | 9996c9e215d61f3ef5aca0eab42943dd 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("user").findOne()>
  4. <cfset loc.user.addErrorToBase(message="base error1")>
  5. <cfset loc.user.addErrorToBase(message="base name error1", name="base_errors")>
  6. <cfset loc.user.addErrorToBase(message="base name error2", name="base_errors")>
  7. <cfset loc.user.addError(property="firstname", message="firstname error1")>
  8. <cfset loc.user.addError(property="firstname", message="firstname error2")>
  9. <cfset loc.user.addError(property="firstname", message="firstname name error1", name="firstname_errors")>
  10. <cfset loc.user.addError(property="firstname", message="firstname name error2", name="firstname_errors")>
  11. <cfset loc.user.addError(property="firstname", message="firstname name error3", name="firstname_errors")>
  12. <cfset loc.user.addError(property="lastname", message="lastname error1")>
  13. <cfset loc.user.addError(property="lastname", message="lastname error2")>
  14. <cfset loc.user.addError(property="lastname", message="lastname error3")>
  15. <cfset loc.user.addError(property="lastname", message="lastname name error1", name="lastname_errors")>
  16. <cfset loc.user.addError(property="lastname", message="lastname name error2", name="lastname_errors")>
  17. </cffunction>
  18. <cffunction name="test_error_information_for_lastname_property_no_name_provided">
  19. <cfset loc.r = loc.user.hasErrors(property="lastname")>
  20. <cfset assert('loc.r eq true')>
  21. <cfset loc.r = loc.user.errorCount(property="lastname")>
  22. <cfset assert('loc.r eq 3')>
  23. <cfset loc.user.clearErrors(property="lastname")>
  24. <cfset loc.r = loc.user.errorCount(property="lastname")>
  25. <cfset assert('loc.r eq 0')>
  26. <cfset loc.r = loc.user.hasErrors()>
  27. <cfset assert('loc.r eq true')>
  28. <cfset loc.r = loc.user.hasErrors(property="lastname")>
  29. <cfset assert('loc.r eq false')>
  30. <cfset loc.r = loc.user.hasErrors(property="lastname", name="lastname_errors")>
  31. <cfset assert('loc.r eq true')>
  32. </cffunction>
  33. <cffunction name="test_error_information_for_lastname_property_name_provided">
  34. <cfset loc.r = loc.user.hasErrors(property="lastname", name="lastname_errors")>
  35. <cfset assert('loc.r eq true')>
  36. <cfset loc.r = loc.user.errorCount(property="lastname", name="lastname_errors")>
  37. <cfset assert('loc.r eq 2')>
  38. <cfset loc.user.clearErrors(property="lastname", name="lastname_errors")>
  39. <cfset loc.r = loc.user.errorCount(property="lastname", name="lastname_errors")>
  40. <cfset assert('loc.r eq 0')>
  41. <cfset loc.r = loc.user.hasErrors()>
  42. <cfset assert('loc.r eq true')>
  43. <cfset loc.r = loc.user.hasErrors(property="lastname", name="lastname_errors")>
  44. <cfset assert('loc.r eq false')>
  45. <cfset loc.r = loc.user.hasErrors(property="lastname")>
  46. <cfset assert('loc.r eq true')>
  47. </cffunction>
  48. <cffunction name="test_error_information_for_firstname_property_no_name_provided">
  49. <cfset loc.r = loc.user.hasErrors(property="firstname")>
  50. <cfset assert('loc.r eq true')>
  51. <cfset loc.r = loc.user.errorCount(property="firstname")>
  52. <cfset assert('loc.r eq 2')>
  53. <cfset loc.user.clearErrors(property="firstname")>
  54. <cfset loc.r = loc.user.errorCount(property="firstname")>
  55. <cfset assert('loc.r eq 0')>
  56. <cfset loc.r = loc.user.hasErrors()>
  57. <cfset assert('loc.r eq true')>
  58. <cfset loc.r = loc.user.hasErrors(property="firstname")>
  59. <cfset assert('loc.r eq false')>
  60. <cfset loc.r = loc.user.hasErrors(property="firstname", name="firstname_errors")>
  61. <cfset assert('loc.r eq true')>
  62. </cffunction>
  63. <cffunction name="test_error_information_for_firstname_property_name_provided">
  64. <cfset loc.r = loc.user.hasErrors(property="firstname", name="firstname_errors")>
  65. <cfset assert('loc.r eq true')>
  66. <cfset loc.r = loc.user.errorCount(property="firstname", name="firstname_errors")>
  67. <cfset assert('loc.r eq 3')>
  68. <cfset loc.user.clearErrors(property="firstname", name="firstname_errors")>
  69. <cfset loc.r = loc.user.errorCount(property="firstname", name="firstname_errors")>
  70. <cfset assert('loc.r eq 0')>
  71. <cfset loc.r = loc.user.hasErrors()>
  72. <cfset assert('loc.r eq true')>
  73. <cfset loc.r = loc.user.hasErrors(property="firstname", name="firstname_errors")>
  74. <cfset assert('loc.r eq false')>
  75. <cfset loc.r = loc.user.hasErrors(property="firstname")>
  76. <cfset assert('loc.r eq true')>
  77. </cffunction>
  78. <cffunction name="test_error_information_for_base_no_name_provided">
  79. <cfset loc.r = loc.user.hasErrors()>
  80. <cfset assert('loc.r eq true')>
  81. <cfset loc.r = loc.user.errorCount()>
  82. <cfset assert('loc.r eq 13')>
  83. <cfset loc.user.clearErrors()>
  84. <cfset loc.r = loc.user.errorCount()>
  85. <cfset assert('loc.r eq 0')>
  86. <cfset loc.r = loc.user.hasErrors()>
  87. <cfset assert('loc.r eq false')>
  88. <cfset loc.r = loc.user.hasErrors(property="lastname")>
  89. <cfset assert('loc.r eq false')>
  90. <cfset loc.r = loc.user.hasErrors(property="lastname", name="lastname_errors")>
  91. <cfset assert('loc.r eq false')>
  92. <cfset loc.r = loc.user.hasErrors(property="firstname")>
  93. <cfset assert('loc.r eq false')>
  94. <cfset loc.r = loc.user.hasErrors(property="firstname", name="firstname_errors")>
  95. <cfset assert('loc.r eq false')>
  96. </cffunction>
  97. <cffunction name="test_error_information_for_base_name_provided">
  98. <cfset loc.r = loc.user.hasErrors(name="base_errors")>
  99. <cfset assert('loc.r eq true')>
  100. <cfset loc.r = loc.user.errorCount(name="base_errors")>
  101. <cfset assert('loc.r eq 2')>
  102. <cfset loc.user.clearErrors(name="base_errors")>
  103. <cfset debug('loc.user.allErrors()', false)>
  104. <cfset loc.r = loc.user.errorCount(name="base_errors")>
  105. <cfset assert('loc.r eq 0')>
  106. <cfset loc.r = loc.user.hasErrors(name="base_errors")>
  107. <cfset assert('loc.r eq false')>
  108. <cfset loc.r = loc.user.hasErrors(property="lastname")>
  109. <cfset assert('loc.r eq true')>
  110. <cfset loc.r = loc.user.hasErrors(property="lastname", name="lastname_errors")>
  111. <cfset assert('loc.r eq true')>
  112. <cfset loc.r = loc.user.hasErrors(property="firstname")>
  113. <cfset assert('loc.r eq true')>
  114. <cfset loc.r = loc.user.hasErrors(property="firstname", name="firstname_errors")>
  115. <cfset assert('loc.r eq true')>
  116. </cffunction>
  117. <cffunction name="test_error_information_for_incorrect_property">
  118. <cfset loc.r = loc.user.hasErrors(property="firstnamex")>
  119. <cfset assert('loc.r eq false')>
  120. <cfset loc.r = loc.user.errorCount(property="firstnamex")>
  121. <cfset assert('loc.r eq 0')>
  122. <cfset loc.user.clearErrors(property="firstnamex")>
  123. <cfset loc.r = loc.user.hasErrors()>
  124. <cfset assert('loc.r eq true')>
  125. <cfset loc.r = loc.user.hasErrors(property="firstname")>
  126. <cfset assert('loc.r eq true')>
  127. <cfset loc.r = loc.user.hasErrors(property="firstname", name="firstname_errors")>
  128. <cfset assert('loc.r eq true')>
  129. </cffunction>
  130. <cffunction name="test_error_information_for_incorrect_name_on_property">
  131. <cfset loc.r = loc.user.hasErrors(property="firstname", name="firstname_errorsx")>
  132. <cfset assert('loc.r eq false')>
  133. <cfset loc.r = loc.user.errorCount(property="firstname", name="firstname_errorsx")>
  134. <cfset assert('loc.r eq 0')>
  135. <cfset loc.user.clearErrors(property="firstname", name="firstname_errorsx")>
  136. <cfset loc.r = loc.user.hasErrors()>
  137. <cfset assert('loc.r eq true')>
  138. <cfset loc.r = loc.user.hasErrors(property="firstname", name="firstname_errors")>
  139. <cfset assert('loc.r eq true')>
  140. <cfset loc.r = loc.user.hasErrors(property="firstname")>
  141. <cfset assert('loc.r eq true')>
  142. </cffunction>
  143. <cffunction name="test_error_information_for_incorrect_name_on_base">
  144. <cfset loc.r = loc.user.hasErrors(name="base_errorsx")>
  145. <cfset assert('loc.r eq false')>
  146. <cfset loc.r = loc.user.errorCount(name="base_errorsx")>
  147. <cfset assert('loc.r eq 0')>
  148. <cfset loc.user.clearErrors(name="base_errorsx")>
  149. <cfset loc.r = loc.user.hasErrors(name="base_errors")>
  150. <cfset assert('loc.r eq true')>
  151. <cfset loc.r = loc.user.hasErrors(property="lastname")>
  152. <cfset assert('loc.r eq true')>
  153. <cfset loc.r = loc.user.hasErrors(property="lastname", name="lastname_errors")>
  154. <cfset assert('loc.r eq true')>
  155. <cfset loc.r = loc.user.hasErrors(property="firstname")>
  156. <cfset assert('loc.r eq true')>
  157. <cfset loc.r = loc.user.hasErrors(property="firstname", name="firstname_errors")>
  158. <cfset assert('loc.r eq true')>
  159. </cffunction>
  160. </cfcomponent>