-
Notifications
You must be signed in to change notification settings - Fork 16
/
IsValidConstraintTest.cfc
273 lines (224 loc) · 8.72 KB
/
IsValidConstraintTest.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import hyrule.system.core.constraint.IsValidConstraint;
component extends="mxunit.framework.TestCase" {
public void function setup(){
isValidConstraint = new IsValidConstraint();
user = new model.user();
}
// if someone passes a blank value validation for any type should pass
public void function testBlankReturnsTrue(){
isValidConstraint.setConstraintParameter("email");
assertTrue(isValidConstraint.validate(user,"email",""));
}
// IsValid any
public void function testAnyReturnsTrue(){
isValidConstraint.setConstraintParameter("any");
assertTrue(isValidConstraint.validate(user,"username","dan"));
}
/*
public void function testAnyReturnsFalse(){
var q = queryNew("id,username");
isValidConstraint.setConstraintParameter("any");
assertFalse(isValidConstraint.validate(user,"list",q));
}
*/
// IsValid Array
public void function testArrayReturnsTrue(){
isValidConstraint.setConstraintParameter("array");
assertTrue(isvalidConstraint.validate(user,"pets",[]));
}
public void function testArrayReturnsFalse(){
isValidConstraint.setConstraintParameter("array");
assertFalse(isvalidConstraint.validate(user,"pets",{}));
}
// IsValid Binary
public void function testBinaryReturnsTrue(){
isValidConstraint.setConstraintParameter("binary");
assertTrue(isvalidConstraint.validate(user,"name",toBinary(toBase64("dan"))));
}
public void function testBinaryReturnsFalse(){
isValidConstraint.setConstraintParameter("binary");
assertFalse(isvalidConstraint.validate(user,"name","dan"));
}
// IsValid Boolean
public void function testBooleanReturnsTrue(){
isValidConstraint.setConstraintParameter("boolean");
assertTrue(isvalidConstraint.validate(user,"canvote",true));
}
public void function testBooleanReturnsFalse(){
isValidConstraint.setConstraintParameter("boolean");
assertFalse(isvalidConstraint.validate(user,"canvote","yeshecan"));
}
// IsValid Component
public void function testComponentReturnsTrue(){
isValidConstraint.setConstraintParameter("component");
assertTrue(isvalidConstraint.validate(user,"user",user));
}
public void function testComponentReturnsFalse(){
isValidConstraint.setConstraintParameter("component");
assertFalse(isvalidConstraint.validate(user,"user","user"));
}
// IsValid CreditCard
public void function testCreditCardReturnsTrue(){
isValidConstraint.setConstraintParameter("creditcard");
assertTrue(isvalidConstraint.validate(user,"card","4111111111111111"));
}
public void function testCreditCardReturnsFalse(){
isValidConstraint.setConstraintParameter("creditcard");
assertFalse(isvalidConstraint.validate(user,"card","4234"));
}
// IsValid Date
public void function testDateReturnsTrue(){
isValidConstraint.setConstraintParameter("date");
assertTrue(isvalidConstraint.validate(user,"today",now()));
}
public void function testDateReturnsFalse(){
isValidConstraint.setConstraintParameter("date");
assertFalse(isvalidConstraint.validate(user,"today","now"));
}
// IsValid Email
public void function testEmailReturnsTrue(){
isValidConstraint.setConstraintParameter("email");
assertTrue(isvalidConstraint.validate(user,"email","danvega@googlemail.com"));
}
public void function testEmailReturnsFalse(){
isValidConstraint.setConstraintParameter("email");
assertFalse(isvalidConstraint.validate(user,"email","danvega@googlemail"));
}
// IsValid EuroDate
public void function testEuroDateReturnsTrue(){
isValidConstraint.setConstraintParameter("eurodate");
assertTrue(isvalidConstraint.validate(user,"dob","21 Aug 1978"));
}
public void function testEuroDateReturnsFalse(){
isValidConstraint.setConstraintParameter("eurodate");
assertFalse(isvalidConstraint.validate(user,"dob","33 years ago"));
}
// IsValid Float
public void function testFloatReturnsTrue(){
isValidConstraint.setConstraintParameter("float");
assertTrue(isvalidConstraint.validate(user,"salary","10.00"));
}
public void function testFloatReturnsFalse(){
isValidConstraint.setConstraintParameter("float");
assertFalse(isvalidConstraint.validate(user,"salary","10 bucks"));
}
// IsValid GUID
public void function testGUIDReturnsTrue(){
isValidConstraint.setConstraintParameter("guid");
assertTrue(isvalidConstraint.validate(user,"id","25892e17-80f6-415f-9c65-7395632f0223"));
}
public void function testGUIDReturnsFalse(){
isValidConstraint.setConstraintParameter("guid");
assertFalse(isvalidConstraint.validate(user,"id","1234-5678"));
}
// IsValid Integer
public void function testIntegerReturnsTrue(){
isValidConstraint.setConstraintParameter("integer");
assertTrue(isvalidConstraint.validate(user,"age","33"));
}
public void function testIntegerReturnsFalse(){
isValidConstraint.setConstraintParameter("integer");
assertFalse(isvalidConstraint.validate(user,"age","Thirty Three"));
}
// Query
public void function testQueryReturnsTrue(){
var q = queryNew("id,username");
isValidConstraint.setConstraintParameter("query");
assertTrue(isvalidConstraint.validate(user,"list",q));
}
public void function testQueryReturnsFalse(){
isValidConstraint.setConstraintParameter("query");
assertFalse(isvalidConstraint.validate(user,"list","1,2,3"));
}
// IsValid SSN
public void function testSSNReturnsTrue(){
isValidConstraint.setConstraintParameter("ssn");
assertTrue(isvalidConstraint.validate(user,"ssn","517-12-3456"));
}
public void function testSSNReturnsFalse(){
isValidConstraint.setConstraintParameter("ssn");
assertFalse(isvalidConstraint.validate(user,"ssn","517-12"));
}
// IsValid string
public void function testStringReturnsTrue(){
isValidConstraint.setConstraintParameter("string");
assertTrue(isvalidConstraint.validate(user,"message","Hello World"));
}
public void function testStringReturnsFalse(){
isValidConstraint.setConstraintParameter("string");
assertFalse(isvalidConstraint.validate(user,"message",[]));
}
// IsValid struct
public void function testStructReturnsTrue(){
isValidConstraint.setConstraintParameter("struct");
assertTrue(isvalidConstraint.validate(user,"details",{first="Dan",last="Vega"}));
}
public void function testStructReturnsFalse(){
isValidConstraint.setConstraintParameter("string");
assertFalse(isvalidConstraint.validate(user,"details",[]));
}
// IsValid telephone
public void function testTelephoneReturnsTrue(){
isValidConstraint.setConstraintParameter("telephone");
assertTrue(isvalidConstraint.validate(user,"phone","216-555-1234"));
}
public void function testTelephoneReturnsFalse(){
isValidConstraint.setConstraintParameter("telephone");
assertFalse(isvalidConstraint.validate(user,"phone","123456"));
}
// IsValid url
public void function testURLReturnsTrue(){
isValidConstraint.setConstraintParameter("url");
assertTrue(isvalidConstraint.validate(user,"website","http://www.danvega.org"));
}
public void function testURLReturnsFalse(){
isValidConstraint.setConstraintParameter("url");
assertFalse(isvalidConstraint.validate(user,"webpage","www.danvega"));
}
// IsValid uuid
public void function testUUIDReturnsTrue(){
isValidConstraint.setConstraintParameter("uuid");
assertTrue(isvalidConstraint.validate(user,"id",createUUID()));
}
public void function testUUIDReturnsFalse(){
isValidConstraint.setConstraintParameter("uuid");
assertFalse(isvalidConstraint.validate(user,"id","12345"));
}
// IsValid usdate
public void function testUSDateReturnsTrue(){
isValidConstraint.setConstraintParameter("usdate");
assertTrue(isvalidConstraint.validate(user,"dob","08/21/1978"));
}
public void function testUSDateReturnsFalse(){
isValidConstraint.setConstraintParameter("usdate");
assertFalse(isvalidConstraint.validate(user,"dob","33 years ago"));
}
// IsValid variableName
public void function testVariablenNameReturnsTrue(){
isValidConstraint.setConstraintParameter("variablename");
assertTrue(isvalidConstraint.validate(user,"x","userName"));
}
public void function testVariableNameReturnsFalse(){
isValidConstraint.setConstraintParameter("variableName");
assertFalse(isvalidConstraint.validate(user,"x","%userName"));
}
// IsVaid zipcode
public void function test5DigitZipReturnsTrue(){
isValidConstraint.setConstraintParameter("zipcode");
assertTrue(isvalidConstraint.validate(user,"zip","44107"));
}
public void function test9DigitZipReturnsTrue(){
isValidConstraint.setConstraintParameter("zipcode");
assertTrue(isvalidConstraint.validate(user,"zip","44107-1234"));
}
public void function testZipReturnsFalse(){
isValidConstraint.setConstraintParameter("zipcode");
assertFalse(isvalidConstraint.validate(user,"zip","1234"));
}
/**
* @mxunit:expectedException ISVALID_CONSTRAINT.INVALID_CONSTRAINT
*/
public void function testNonValidConstraintParameterThrowsError() {
isValidConstraint.setConstraintParameter([]);
}
}