PageRenderTime 34ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wheels/tests/model/_query/where.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 159 lines | 141 code | 18 blank | 0 comment | 0 complexity | 85e7b797f1ea4d660ce4f91237daedb6 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="setup">
  3. <cfset loc.authorModel = model("author")>
  4. </cffunction>
  5. <cffunction name="test_set_where_auto_equals">
  6. <cfset loc.authorModel.where(id=1)>
  7. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  8. <cfset assert('loc.whereData.operation eq "eql"')>
  9. <cfset assert('loc.whereData.property eq "id"')>
  10. <cfset assert('loc.whereData.value eq 1')>
  11. <cfset assert('loc.whereData.negate eq false')>
  12. </cffunction>
  13. <cffunction name="test_set_multiple_where_auto_equals">
  14. <cfset loc.authorModel.where(id=1, firstName="Per")>
  15. <cfset loc.firstNameData = loc.authorModel.toQuery().where[1]>
  16. <cfset loc.idData = loc.authorModel.toQuery().where[2]>
  17. <cfset assert('loc.firstNameData.operation eq "eql"')>
  18. <cfset assert('loc.firstNameData.property eq "firstName"')>
  19. <cfset assert('loc.firstNameData.value eq "Per"')>
  20. <cfset assert('loc.firstNameData.negate eq false')>
  21. <cfset assert('loc.idData.operation eq "eql"')>
  22. <cfset assert('loc.idData.property eq "id"')>
  23. <cfset assert('loc.idData.value eq 1')>
  24. <cfset assert('loc.idData.negate eq false')>
  25. </cffunction>
  26. <cffunction name="test_set_where_must_be_called_first">
  27. <cftry>
  28. <cfset loc.authorModel.where(id=1)>
  29. <cfcatch type="Wheels.IncorrectQueryMethodChaining">
  30. <cfset assert('true eq true') />
  31. </cfcatch>
  32. </cftry>
  33. </cffunction>
  34. <cffunction name="test_set_where_property_equals">
  35. <cfset loc.authorModel.where(property="id", eql=1)>
  36. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  37. <cfset assert('loc.whereData.operation eq "eql"')>
  38. <cfset assert('loc.whereData.property eq "id"')>
  39. <cfset assert('loc.whereData.value eq 1')>
  40. <cfset assert('loc.whereData.negate eq false')>
  41. </cffunction>
  42. <cffunction name="test_set_where_property_not_equals">
  43. <cfset loc.authorModel.where(property="id", notEql=1)>
  44. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  45. <cfset assert('loc.whereData.operation eq "eql"')>
  46. <cfset assert('loc.whereData.property eq "id"')>
  47. <cfset assert('loc.whereData.value eq 1')>
  48. <cfset assert('loc.whereData.negate eq true')>
  49. </cffunction>
  50. <cffunction name="test_set_where_property_in">
  51. <cfset loc.idList = "1,2,3">
  52. <cfset loc.authorModel.where(property="id", in=loc.idList)>
  53. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  54. <cfset assert('loc.whereData.operation eq "in"')>
  55. <cfset assert('loc.whereData.property eq "id"')>
  56. <cfset assert('IsArray(loc.whereData.value) and ArrayLen(loc.whereData.value) eq 3')>
  57. <cfset assert('loc.whereData.negate eq false')>
  58. </cffunction>
  59. <cffunction name="test_set_where_property_not_in">
  60. <cfset loc.idList = "1,2,3">
  61. <cfset loc.authorModel.where(property="id", notIn=loc.idList)>
  62. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  63. <cfset assert('loc.whereData.operation eq "in"')>
  64. <cfset assert('loc.whereData.property eq "id"')>
  65. <cfset assert('IsArray(loc.whereData.value) and ArrayLen(loc.whereData.value) eq 3')>
  66. <cfset assert('loc.whereData.negate eq true')>
  67. </cffunction>
  68. <cffunction name="test_set_where_property_between">
  69. <cfset loc.idList = "1,3">
  70. <cfset loc.authorModel.where(property="id", between=loc.idList)>
  71. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  72. <cfset assert('loc.whereData.operation eq "between"')>
  73. <cfset assert('loc.whereData.property eq "id"')>
  74. <cfset assert('IsArray(loc.whereData.value) and ArrayLen(loc.whereData.value) eq 2')>
  75. <cfset assert('loc.whereData.negate eq false')>
  76. </cffunction>
  77. <cffunction name="test_set_where_property_not_between">
  78. <cfset loc.idList = "1,3">
  79. <cfset loc.authorModel.where(property="id", notBetween=loc.idList)>
  80. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  81. <cfset assert('loc.whereData.operation eq "between"')>
  82. <cfset assert('loc.whereData.property eq "id"')>
  83. <cfset assert('IsArray(loc.whereData.value) and ArrayLen(loc.whereData.value) eq 2')>
  84. <cfset assert('loc.whereData.negate eq true')>
  85. </cffunction>
  86. <cffunction name="test_set_where_property_greater_than">
  87. <cfset loc.authorModel.where(property="id", greaterThan=3)>
  88. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  89. <cfset assert('loc.whereData.operation eq "greaterthan"')>
  90. <cfset assert('loc.whereData.property eq "id"')>
  91. <cfset assert('loc.whereData.value eq 3')>
  92. <cfset assert('loc.whereData.negate eq false')>
  93. </cffunction>
  94. <cffunction name="test_set_where_property_greater_than_equal">
  95. <cfset loc.authorModel.where(property="id", greaterThanEql=3)>
  96. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  97. <cfset assert('loc.whereData.operation eq "greaterthaneql"')>
  98. <cfset assert('loc.whereData.property eq "id"')>
  99. <cfset assert('loc.whereData.value eq 3')>
  100. <cfset assert('loc.whereData.negate eq false')>
  101. </cffunction>
  102. <cffunction name="test_set_where_property_less_than">
  103. <cfset loc.authorModel.where(property="id", lessThan=3)>
  104. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  105. <cfset assert('loc.whereData.operation eq "lessThan"')>
  106. <cfset assert('loc.whereData.property eq "id"')>
  107. <cfset assert('loc.whereData.value eq 3')>
  108. <cfset assert('loc.whereData.negate eq false')>
  109. </cffunction>
  110. <cffunction name="test_set_where_property_less_than_equal">
  111. <cfset loc.authorModel.where(property="id", lessThanEql=3)>
  112. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  113. <cfset assert('loc.whereData.operation eq "lessThanEql"')>
  114. <cfset assert('loc.whereData.property eq "id"')>
  115. <cfset assert('loc.whereData.value eq 3')>
  116. <cfset assert('loc.whereData.negate eq false')>
  117. </cffunction>
  118. <cffunction name="test_set_where_property_is_null">
  119. <cfset loc.authorModel.where(property="id", null=true)>
  120. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  121. <cfset assert('loc.whereData.operation eq "null"')>
  122. <cfset assert('loc.whereData.property eq "id"')>
  123. <cfset assert('loc.whereData.value eq ""')>
  124. <cfset assert('loc.whereData.negate eq false')>
  125. </cffunction>
  126. <cffunction name="test_set_where_property_is_not_null">
  127. <cfset loc.authorModel.where(property="id", null=false)>
  128. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  129. <cfset assert('loc.whereData.operation eq "null"')>
  130. <cfset assert('loc.whereData.property eq "id"')>
  131. <cfset assert('loc.whereData.value eq ""')>
  132. <cfset assert('loc.whereData.negate eq true')>
  133. </cffunction>
  134. <cffunction name="test_set_where_to_sql">
  135. <cfset loc.authorModel.where(sql="id = 3")>
  136. <cfset loc.whereData = loc.authorModel.toQuery().where[1]>
  137. <cfset assert('loc.whereData.operation eq "sql"')>
  138. <cfset assert('loc.whereData.value eq "id = 3"')>
  139. <cfset assert('loc.whereData.negate eq false')>
  140. </cffunction>
  141. </cfcomponent>