PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms 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
 1<cfcomponent extends="wheelsMapping.Test">
 2
 3	<cffunction name="setup">
 4		<cfset loc.user = model("UserBlank").new()>
 5		<cfset loc.user.username = "gavin@cfwheels.org">
 6		<cfset loc.user.password = "disismypassword">
 7		<cfset loc.user.firstName = "Gavin">
 8		<cfset loc.user.lastName = "Gavinsson">
 9	</cffunction>
10
11	<cffunction name="test_validates_presence_of_invalid">
12		<cfset StructDelete(loc.user, "username")> <!--- missing key --->
13		<cfset loc.user.password = ""> <!--- zero length string --->
14		<cfset loc.user.firstName = "      "> <!--- empty string --->
15		<cfset loc.user.valid()>
16		<cfset assert('ArrayLen(loc.user.allErrors()) eq 3')>
17	</cffunction>
18
19	<cffunction name="test_validates_presence_of_valid">
20		<cfset loc.user.password = "something">
21		<cfset loc.user.firstName = "blahblah">
22		<cfset assert('loc.user.valid()')>
23	</cffunction>
24
25	<cffunction name="test_validates_length_of_invalid">
26		<cfset loc.user.state = "Too many characters!">
27		<cfset loc.user.valid()>
28		<cfset loc.arrResult = loc.user.errorsOn("state")>
29		<cfset assert('ArrayLen(loc.arrResult) eq 1 AND loc.arrResult[1].message eq "State is the wrong length"')>
30	</cffunction>
31
32	<cffunction name="test_validates_length_of_valid">
33		<cfset loc.user.state = "FL">
34		<cfset assert('loc.user.valid()')>
35	</cffunction>
36
37	<cffunction name="test_validates_numericality_of_invalid">
38		<cfset loc.user.birthDayMonth = "This is not a number!">
39		<cfset loc.user.valid()>
40		<cfset loc.arrResult = loc.user.errorsOn("birthDayMonth")>
41		<cfset assert('ArrayLen(loc.arrResult) eq 1 AND loc.arrResult[1].message eq "Birthdaymonth is not a number"')>
42	</cffunction>
43
44	<cffunction name="test_validates_numericality_of_valid">
45		<cfset loc.user.birthDayMonth = "7">
46		<cfset assert('loc.user.valid()')>
47	</cffunction>
48
49	<cffunction name="test_validates_numericality_of_integer_invalid">
50		<cfset loc.user.birthDayMonth = "7.825">
51		<cfset loc.user.valid()>
52		<cfset loc.arrResult = loc.user.errorsOn("birthDayMonth")>
53		<cfset assert('ArrayLen(loc.arrResult) eq 1 AND loc.arrResult[1].message eq "Birthdaymonth is not a number"')>
54	</cffunction>
55
56	<cffunction name="test_validates_format_of_date_invalid">
57		<cfset loc.user.birthDay = "This is not a date!">
58		<cfset loc.user.valid()>
59		<cfset loc.arrResult = loc.user.errorsOn("birthDay")>
60		<cfset assert('ArrayLen(loc.arrResult) eq 1 AND loc.arrResult[1].message eq "Birth day is invalid"')>
61	</cffunction>
62
63	<cffunction name="test_validates_format_of_date_valid">
64		<cfset loc.user.birthDay = "01/01/2000">
65		<cfset assert('loc.user.valid()')>
66	</cffunction>
67
68	<cffunction name="test_validates_format_of_time_invalid">
69		<cfset loc.user.birthTime = "This is not a time!">
70		<cfset loc.user.valid()>
71		<cfset loc.arrResult = loc.user.errorsOn("birthTime")>
72		<cfset assert('ArrayLen(loc.arrResult) eq 1 AND loc.arrResult[1].message eq "Birthtime is invalid"')>
73	</cffunction>
74
75	<cffunction name="test_validates_format_of_time_valid">
76		<cfset loc.user.birthTime = "6:15 PM">
77		<cfset assert('loc.user.valid()')>
78	</cffunction>
79
80</cfcomponent>