PageRenderTime 244ms CodeModel.GetById 100ms app.highlight 2ms RepoModel.GetById 139ms app.codeStats 0ms

/wheels/tests/model/validations/conditional_validations.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 119 lines | 100 code | 19 blank | 0 comment | 0 complexity | cfe8df3d3943c75c0aff61d799cfff48 MD5 | raw file
  1<cfcomponent extends="wheelsMapping.Test">
  2
  3	<cffunction name="setup">
  4		<cfset StructDelete(application.wheels.models, "users", false)>
  5        <cfset loc.user = model("users").new()>
  6	    <cfset loc.user.username = "TheLongestNameInTheWorld">
  7        <cfset loc.args = {}>
  8        <cfset loc.args.property = "username">
  9        <cfset loc.args.maximum = "5">
 10	</cffunction>
 11
 12	<cffunction name="test_if_validation_using_expression_invalid">
 13		<cfset loc.args.condition="1 eq 1">
 14		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 15		<cfset assert_test(loc.user, false)>
 16	</cffunction>
 17
 18	<cffunction name="test_if_validation_using_expression_valid">
 19		<cfset loc.args.condition="1 eq 0">
 20		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 21		<cfset assert_test(loc.user, true)>
 22	</cffunction>
 23
 24	<cffunction name="test_if_validation_using_method_invalid">
 25		<cfset loc.args.condition="isnew()">
 26		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 27		<cfset assert_test(loc.user, false)>
 28	</cffunction>
 29
 30	<cffunction name="test_if_validation_using_method_valid">
 31		<cfset loc.args.condition="!isnew()">
 32		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 33		<cfset assert_test(loc.user, true)>
 34	</cffunction>
 35
 36	<cffunction name="test_if_validation_using_method_mixin_and_parameters_invalid">
 37		<cfset loc.args.condition="this.stupid_method(b='1' , a='2') eq 3">
 38		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 39		<cfset assert_test(loc.user, false)>
 40	</cffunction>
 41
 42	<cffunction name="test_if_validation_using_method_mixin_and_parameters_valid">
 43		<cfset loc.args.condition="this.stupid_method(b='1' , a='2') neq 3">
 44		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 45		<cfset assert_test(loc.user, true)>
 46	</cffunction>
 47
 48	<cffunction name="test_unless_validation_using_expression_valid">
 49		<cfset loc.args.unless="true">
 50		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 51		<cfset assert_test(loc.user, true)>
 52	</cffunction>
 53
 54	<cffunction name="test_unless_validation_using_expression_invalid">
 55		<cfset loc.args.unless="false">
 56		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 57		<cfset assert_test(loc.user, false)>
 58	</cffunction>
 59
 60	<cffunction name="test_unless_validation_using_method_valid">
 61		<cfset loc.args.unless="isnew()">
 62		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 63		<cfset assert_test(loc.user, true)>
 64	</cffunction>
 65
 66	<cffunction name="test_unless_validation_using_method_invalid">
 67		<cfset loc.args.unless="!isnew()">
 68		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 69		<cfset assert_test(loc.user, false)>
 70	</cffunction>
 71
 72	<cffunction name="test_unless_validation_using_method_mixin_and_parameters_valid">
 73		<cfset loc.args.unless="this.stupid_method(b='1' , a='2') eq 3">
 74		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 75		<cfset assert_test(loc.user, true)>
 76	</cffunction>
 77
 78	<cffunction name="test_unless_validation_using_method_mixin_and_parameters_invalid">
 79		<cfset loc.args.unless="this.stupid_method(b='1' , a='2') neq 3">
 80		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 81		<cfset assert_test(loc.user, false)>
 82	</cffunction>
 83
 84	<cffunction name="test_both_validations_if_trigged_unless_not_trigged_valid">
 85		<cfset loc.args.condition="1 eq 1">
 86		<cfset loc.args.unless="this.username eq 'TheLongestNameInTheWorld'">
 87		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 88		<cfset assert_test(loc.user, true)>
 89	</cffunction>
 90
 91	<cffunction name="test_both_validations_if_trigged_unless_trigged_invalid">
 92		<cfset loc.args.condition="1 eq 1">
 93		<cfset loc.args.unless="this.username eq ''">
 94		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
 95		<cfset assert_test(loc.user, false)>
 96	</cffunction>
 97
 98	<cffunction name="test_both_validations_if_not_trigged_unless_not_trigged_valid">
 99		<cfset loc.args.condition="1 eq 0">
100		<cfset loc.args.unless="this.username eq 'TheLongestNameInTheWorld'">
101		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
102		<cfset assert_test(loc.user, true)>
103	</cffunction>
104
105	<cffunction name="test_both_validations_if_not_trigged_unless_trigged_valid">
106		<cfset loc.args.condition="1 eq 0">
107		<cfset loc.args.unless="this.username eq ''">
108		<cfset loc.user.validatesLengthOf(argumentCollection=loc.args)>
109		<cfset assert_test(loc.user, true)>
110	</cffunction>
111
112	<cffunction name="assert_test">
113		<cfargument name="obj" type="any" required="true">
114		<cfargument name="expect" type="boolean" required="true">
115		<cfset loc.e = arguments.obj.valid()>
116		<cfset assert('loc.e eq #arguments.expect#')>
117	</cffunction>
118
119</cfcomponent>