PageRenderTime 475ms CodeModel.GetById 241ms app.highlight 2ms RepoModel.GetById 230ms 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
  1<cfcomponent extends="wheelsMapping.Test">
  2
  3	<cffunction name="setup">
  4		<cfset loc.authorModel = model("author")>
  5	</cffunction>
  6
  7	<cffunction name="test_set_where_auto_equals">
  8		<cfset loc.authorModel.where(id=1)>
  9		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
 10		<cfset assert('loc.whereData.operation eq "eql"')>
 11		<cfset assert('loc.whereData.property eq "id"')>
 12		<cfset assert('loc.whereData.value eq 1')>
 13		<cfset assert('loc.whereData.negate eq false')>
 14	</cffunction>
 15
 16	<cffunction name="test_set_multiple_where_auto_equals">
 17		<cfset loc.authorModel.where(id=1, firstName="Per")>
 18		<cfset loc.firstNameData = loc.authorModel.toQuery().where[1]>
 19		<cfset loc.idData = loc.authorModel.toQuery().where[2]>
 20		<cfset assert('loc.firstNameData.operation eq "eql"')>
 21		<cfset assert('loc.firstNameData.property eq "firstName"')>
 22		<cfset assert('loc.firstNameData.value eq "Per"')>
 23		<cfset assert('loc.firstNameData.negate eq false')>
 24		<cfset assert('loc.idData.operation eq "eql"')>
 25		<cfset assert('loc.idData.property eq "id"')>
 26		<cfset assert('loc.idData.value eq 1')>
 27		<cfset assert('loc.idData.negate eq false')>
 28	</cffunction>
 29
 30	<cffunction name="test_set_where_must_be_called_first">
 31		<cftry>
 32			<cfset loc.authorModel.where(id=1)>
 33			<cfcatch type="Wheels.IncorrectQueryMethodChaining">
 34				<cfset assert('true eq true') />
 35			</cfcatch>
 36		</cftry>
 37	</cffunction>
 38
 39	<cffunction name="test_set_where_property_equals">
 40		<cfset loc.authorModel.where(property="id", eql=1)>
 41		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
 42		<cfset assert('loc.whereData.operation eq "eql"')>
 43		<cfset assert('loc.whereData.property eq "id"')>
 44		<cfset assert('loc.whereData.value eq 1')>
 45		<cfset assert('loc.whereData.negate eq false')>
 46	</cffunction>
 47
 48	<cffunction name="test_set_where_property_not_equals">
 49		<cfset loc.authorModel.where(property="id", notEql=1)>
 50		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
 51		<cfset assert('loc.whereData.operation eq "eql"')>
 52		<cfset assert('loc.whereData.property eq "id"')>
 53		<cfset assert('loc.whereData.value eq 1')>
 54		<cfset assert('loc.whereData.negate eq true')>
 55	</cffunction>
 56
 57	<cffunction name="test_set_where_property_in">
 58		<cfset loc.idList = "1,2,3">
 59		<cfset loc.authorModel.where(property="id", in=loc.idList)>
 60		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
 61		<cfset assert('loc.whereData.operation eq "in"')>
 62		<cfset assert('loc.whereData.property eq "id"')>
 63		<cfset assert('IsArray(loc.whereData.value) and ArrayLen(loc.whereData.value) eq 3')>
 64		<cfset assert('loc.whereData.negate eq false')>
 65	</cffunction>
 66
 67	<cffunction name="test_set_where_property_not_in">
 68		<cfset loc.idList = "1,2,3">
 69		<cfset loc.authorModel.where(property="id", notIn=loc.idList)>
 70		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
 71		<cfset assert('loc.whereData.operation eq "in"')>
 72		<cfset assert('loc.whereData.property eq "id"')>
 73		<cfset assert('IsArray(loc.whereData.value) and ArrayLen(loc.whereData.value) eq 3')>
 74		<cfset assert('loc.whereData.negate eq true')>
 75	</cffunction>
 76
 77	<cffunction name="test_set_where_property_between">
 78		<cfset loc.idList = "1,3">
 79		<cfset loc.authorModel.where(property="id", between=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 false')>
 85	</cffunction>
 86
 87	<cffunction name="test_set_where_property_not_between">
 88		<cfset loc.idList = "1,3">
 89		<cfset loc.authorModel.where(property="id", notBetween=loc.idList)>
 90		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
 91		<cfset assert('loc.whereData.operation eq "between"')>
 92		<cfset assert('loc.whereData.property eq "id"')>
 93		<cfset assert('IsArray(loc.whereData.value) and ArrayLen(loc.whereData.value) eq 2')>
 94		<cfset assert('loc.whereData.negate eq true')>
 95	</cffunction>
 96
 97	<cffunction name="test_set_where_property_greater_than">
 98		<cfset loc.authorModel.where(property="id", greaterThan=3)>
 99		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
100		<cfset assert('loc.whereData.operation eq "greaterthan"')>
101		<cfset assert('loc.whereData.property eq "id"')>
102		<cfset assert('loc.whereData.value eq 3')>
103		<cfset assert('loc.whereData.negate eq false')>
104	</cffunction>
105
106	<cffunction name="test_set_where_property_greater_than_equal">
107		<cfset loc.authorModel.where(property="id", greaterThanEql=3)>
108		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
109		<cfset assert('loc.whereData.operation eq "greaterthaneql"')>
110		<cfset assert('loc.whereData.property eq "id"')>
111		<cfset assert('loc.whereData.value eq 3')>
112		<cfset assert('loc.whereData.negate eq false')>
113	</cffunction>
114
115	<cffunction name="test_set_where_property_less_than">
116		<cfset loc.authorModel.where(property="id", lessThan=3)>
117		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
118		<cfset assert('loc.whereData.operation eq "lessThan"')>
119		<cfset assert('loc.whereData.property eq "id"')>
120		<cfset assert('loc.whereData.value eq 3')>
121		<cfset assert('loc.whereData.negate eq false')>
122	</cffunction>
123
124	<cffunction name="test_set_where_property_less_than_equal">
125		<cfset loc.authorModel.where(property="id", lessThanEql=3)>
126		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
127		<cfset assert('loc.whereData.operation eq "lessThanEql"')>
128		<cfset assert('loc.whereData.property eq "id"')>
129		<cfset assert('loc.whereData.value eq 3')>
130		<cfset assert('loc.whereData.negate eq false')>
131	</cffunction>
132
133	<cffunction name="test_set_where_property_is_null">
134		<cfset loc.authorModel.where(property="id", null=true)>
135		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
136		<cfset assert('loc.whereData.operation eq "null"')>
137		<cfset assert('loc.whereData.property eq "id"')>
138		<cfset assert('loc.whereData.value eq ""')>
139		<cfset assert('loc.whereData.negate eq false')>
140	</cffunction>
141
142	<cffunction name="test_set_where_property_is_not_null">
143		<cfset loc.authorModel.where(property="id", null=false)>
144		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
145		<cfset assert('loc.whereData.operation eq "null"')>
146		<cfset assert('loc.whereData.property eq "id"')>
147		<cfset assert('loc.whereData.value eq ""')>
148		<cfset assert('loc.whereData.negate eq true')>
149	</cffunction>
150
151	<cffunction name="test_set_where_to_sql">
152		<cfset loc.authorModel.where(sql="id = 3")>
153		<cfset loc.whereData = loc.authorModel.toQuery().where[1]>
154		<cfset assert('loc.whereData.operation eq "sql"')>
155		<cfset assert('loc.whereData.value eq "id = 3"')>
156		<cfset assert('loc.whereData.negate eq false')>
157	</cffunction>
158
159</cfcomponent>