2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.validate.tests.validate"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.validate.tests.validate"] = true;
|
|
|
3 |
dojo.provide("dojox.validate.tests.validate");
|
|
|
4 |
|
|
|
5 |
dojo.require("dojox.validate._base");
|
|
|
6 |
dojo.require("dojox.validate.check");
|
|
|
7 |
dojo.require("dojox.validate.us");
|
|
|
8 |
dojo.require("dojox.validate.ca");
|
|
|
9 |
dojo.require("dojox.validate.web");
|
|
|
10 |
dojo.require("dojox.validate.isbn");
|
|
|
11 |
|
|
|
12 |
tests.register("dojox.validate.tests.validate",
|
|
|
13 |
[{
|
|
|
14 |
name: "isText",
|
|
|
15 |
runTest: function(tests){
|
|
|
16 |
tests.t(dojox.validate.isValidIsbn('0596007590')); //test string input
|
|
|
17 |
tests.t(dojox.validate.isValidIsbn('0-596-00759-0')); //test string input with dashes
|
|
|
18 |
tests.f(dojox.validate.isValidIsbn(0596007590)); //test numerical input as well
|
|
|
19 |
tests.t(dojox.validate.isValidIsbn("960-425-059-0"));
|
|
|
20 |
tests.t(dojox.validate.isValidIsbn(9604250590)); //test numerical input as well
|
|
|
21 |
tests.t(dojox.validate.isValidIsbn('0-9752298-0-X')); // test string with X
|
|
|
22 |
tests.t(dojox.validate.isValidIsbn('0-9752298-0-x'));
|
|
|
23 |
tests.t(dojox.validate.isValidIsbn('097522980x'));
|
|
|
24 |
tests.t(dojox.validate.isValidIsbn('097522980X'));
|
|
|
25 |
tests.f(dojox.validate.isValidIsbn(0596007598)); //testing failures
|
|
|
26 |
tests.f(dojox.validate.isValidIsbn('059-600759-X')); //testing failures
|
|
|
27 |
tests.f(dojox.validate.isValidIsbn('059600')); // too short
|
|
|
28 |
|
|
|
29 |
tests.t(dojox.validate.isValidIsbn('9780596007591'));
|
|
|
30 |
tests.t(dojox.validate.isValidIsbn('978-0-596 00759-1'));
|
|
|
31 |
tests.t(dojox.validate.isValidIsbn(9780596007591));
|
|
|
32 |
tests.f(dojox.validate.isValidIsbn('978059600759X'));
|
|
|
33 |
tests.f(dojox.validate.isValidIsbn('978-3250-596 00759-1 '));
|
|
|
34 |
tests.f(dojox.validate.isValidIsbn('3250-596 00759 '));
|
|
|
35 |
|
|
|
36 |
tests.t(dojox.validate.isText(' x'));
|
|
|
37 |
tests.t(dojox.validate.isText('x '));
|
|
|
38 |
tests.t(dojox.validate.isText(' x '));
|
|
|
39 |
tests.f(dojox.validate.isText(' '));
|
|
|
40 |
tests.f(dojox.validate.isText(''));
|
|
|
41 |
|
|
|
42 |
// test lengths
|
|
|
43 |
tests.t(dojox.validate.isText('123456', {length: 6} ));
|
|
|
44 |
tests.f(dojox.validate.isText('1234567', {length: 6} ));
|
|
|
45 |
tests.t(dojox.validate.isText('1234567', {minlength: 6} ));
|
|
|
46 |
tests.t(dojox.validate.isText('123456', {minlength: 6} ));
|
|
|
47 |
tests.f(dojox.validate.isText('12345', {minlength: 6} ));
|
|
|
48 |
tests.f(dojox.validate.isText('1234567', {maxlength: 6} ));
|
|
|
49 |
tests.t(dojox.validate.isText('123456', {maxlength: 6} ));
|
|
|
50 |
}
|
|
|
51 |
},
|
|
|
52 |
{
|
|
|
53 |
name: "isIpAddress",
|
|
|
54 |
runTest: function(tests){
|
|
|
55 |
tests.t(dojox.validate.isIpAddress('24.17.155.40'));
|
|
|
56 |
tests.f(dojox.validate.isIpAddress('024.17.155.040'));
|
|
|
57 |
tests.t(dojox.validate.isIpAddress('255.255.255.255'));
|
|
|
58 |
tests.f(dojox.validate.isIpAddress('256.255.255.255'));
|
|
|
59 |
tests.f(dojox.validate.isIpAddress('255.256.255.255'));
|
|
|
60 |
tests.f(dojox.validate.isIpAddress('255.255.256.255'));
|
|
|
61 |
tests.f(dojox.validate.isIpAddress('255.255.255.256'));
|
|
|
62 |
|
|
|
63 |
// test dotted hex
|
|
|
64 |
tests.t(dojox.validate.isIpAddress('0x18.0x11.0x9b.0x28'));
|
|
|
65 |
tests.f(dojox.validate.isIpAddress('0x18.0x11.0x9b.0x28', {allowDottedHex: false}) );
|
|
|
66 |
tests.t(dojox.validate.isIpAddress('0x18.0x000000011.0x9b.0x28'));
|
|
|
67 |
tests.t(dojox.validate.isIpAddress('0xff.0xff.0xff.0xff'));
|
|
|
68 |
tests.f(dojox.validate.isIpAddress('0x100.0xff.0xff.0xff'));
|
|
|
69 |
|
|
|
70 |
// test dotted octal
|
|
|
71 |
tests.t(dojox.validate.isIpAddress('0030.0021.0233.0050'));
|
|
|
72 |
tests.f(dojox.validate.isIpAddress('0030.0021.0233.0050', {allowDottedOctal: false}) );
|
|
|
73 |
tests.t(dojox.validate.isIpAddress('0030.0000021.0233.00000050'));
|
|
|
74 |
tests.t(dojox.validate.isIpAddress('0377.0377.0377.0377'));
|
|
|
75 |
tests.f(dojox.validate.isIpAddress('0400.0377.0377.0377'));
|
|
|
76 |
tests.f(dojox.validate.isIpAddress('0377.0378.0377.0377'));
|
|
|
77 |
tests.f(dojox.validate.isIpAddress('0377.0377.0380.0377'));
|
|
|
78 |
tests.f(dojox.validate.isIpAddress('0377.0377.0377.377'));
|
|
|
79 |
|
|
|
80 |
// test decimal
|
|
|
81 |
tests.t(dojox.validate.isIpAddress('3482223595'));
|
|
|
82 |
tests.t(dojox.validate.isIpAddress('0'));
|
|
|
83 |
tests.t(dojox.validate.isIpAddress('4294967295'));
|
|
|
84 |
tests.f(dojox.validate.isIpAddress('4294967296'));
|
|
|
85 |
tests.f(dojox.validate.isIpAddress('3482223595', {allowDecimal: false}));
|
|
|
86 |
|
|
|
87 |
// test hex
|
|
|
88 |
tests.t(dojox.validate.isIpAddress('0xCF8E83EB'));
|
|
|
89 |
tests.t(dojox.validate.isIpAddress('0x0'));
|
|
|
90 |
tests.t(dojox.validate.isIpAddress('0x00ffffffff'));
|
|
|
91 |
tests.f(dojox.validate.isIpAddress('0x100000000'));
|
|
|
92 |
tests.f(dojox.validate.isIpAddress('0xCF8E83EB', {allowHex: false}));
|
|
|
93 |
|
|
|
94 |
// IPv6
|
|
|
95 |
tests.t(dojox.validate.isIpAddress('fedc:BA98:7654:3210:FEDC:BA98:7654:3210'));
|
|
|
96 |
tests.t(dojox.validate.isIpAddress('1080:0:0:0:8:800:200C:417A'));
|
|
|
97 |
tests.f(dojox.validate.isIpAddress('1080:0:0:0:8:800:200C:417A', {allowIPv6: false}));
|
|
|
98 |
|
|
|
99 |
// Hybrid of IPv6 and IPv4
|
|
|
100 |
tests.t(dojox.validate.isIpAddress('0:0:0:0:0:0:13.1.68.3'));
|
|
|
101 |
tests.t(dojox.validate.isIpAddress('0:0:0:0:0:FFFF:129.144.52.38'));
|
|
|
102 |
tests.f(dojox.validate.isIpAddress('0:0:0:0:0:FFFF:129.144.52.38', {allowHybrid: false}));
|
|
|
103 |
}
|
|
|
104 |
},
|
|
|
105 |
{
|
|
|
106 |
name:"isUrl",
|
|
|
107 |
runTests: function(tests){
|
|
|
108 |
|
|
|
109 |
tests.t(dojox.validate.isUrl('www.yahoo.com'));
|
|
|
110 |
tests.t(dojox.validate.isUrl('http://www.yahoo.com'));
|
|
|
111 |
tests.t(dojox.validate.isUrl('https://www.yahoo.com'));
|
|
|
112 |
tests.f(dojox.validate.isUrl('http://.yahoo.com'));
|
|
|
113 |
tests.f(dojox.validate.isUrl('http://www.-yahoo.com'));
|
|
|
114 |
tests.f(dojox.validate.isUrl('http://www.yahoo-.com'));
|
|
|
115 |
tests.t(dojox.validate.isUrl('http://y-a---h-o-o.com'));
|
|
|
116 |
tests.t(dojox.validate.isUrl('http://www.y.com'));
|
|
|
117 |
tests.t(dojox.validate.isUrl('http://www.yahoo.museum'));
|
|
|
118 |
tests.t(dojox.validate.isUrl('http://www.yahoo.co.uk'));
|
|
|
119 |
tests.f(dojox.validate.isUrl('http://www.micro$oft.com'));
|
|
|
120 |
|
|
|
121 |
tests.t(dojox.validate.isUrl('http://www.y.museum:8080'));
|
|
|
122 |
tests.t(dojox.validate.isUrl('http://12.24.36.128:8080'));
|
|
|
123 |
tests.f(dojox.validate.isUrl('http://12.24.36.128:8080', {allowIP: false} ));
|
|
|
124 |
tests.t(dojox.validate.isUrl('www.y.museum:8080'));
|
|
|
125 |
tests.f(dojox.validate.isUrl('www.y.museum:8080', {scheme: true} ));
|
|
|
126 |
tests.t(dojox.validate.isUrl('localhost:8080', {allowLocal: true} ));
|
|
|
127 |
tests.f(dojox.validate.isUrl('localhost:8080', {} ));
|
|
|
128 |
tests.t(dojox.validate.isUrl('http://www.yahoo.com/index.html?a=12&b=hello%20world#anchor'));
|
|
|
129 |
tests.f(dojox.validate.isUrl('http://www.yahoo.xyz'));
|
|
|
130 |
tests.t(dojox.validate.isUrl('http://www.yahoo.com/index.html#anchor'));
|
|
|
131 |
tests.t(dojox.validate.isUrl('http://cocoon.apache.org/2.1/'));
|
|
|
132 |
}
|
|
|
133 |
},
|
|
|
134 |
{
|
|
|
135 |
name: "isEmailAddress",
|
|
|
136 |
runTests: function(tests) {
|
|
|
137 |
tests.t(dojox.validate.isEmailAddress('x@yahoo.com'));
|
|
|
138 |
tests.t(dojox.validate.isEmailAddress('x.y.z.w@yahoo.com'));
|
|
|
139 |
tests.f(dojox.validate.isEmailAddress('x..y.z.w@yahoo.com'));
|
|
|
140 |
tests.f(dojox.validate.isEmailAddress('x.@yahoo.com'));
|
|
|
141 |
tests.t(dojox.validate.isEmailAddress('x@z.com'));
|
|
|
142 |
tests.f(dojox.validate.isEmailAddress('x@yahoo.x'));
|
|
|
143 |
tests.t(dojox.validate.isEmailAddress('x@yahoo.museum'));
|
|
|
144 |
tests.t(dojox.validate.isEmailAddress("o'mally@yahoo.com"));
|
|
|
145 |
tests.f(dojox.validate.isEmailAddress("'mally@yahoo.com"));
|
|
|
146 |
tests.t(dojox.validate.isEmailAddress("fred&barney@stonehenge.com"));
|
|
|
147 |
tests.f(dojox.validate.isEmailAddress("fred&&barney@stonehenge.com"));
|
|
|
148 |
|
|
|
149 |
// local addresses
|
|
|
150 |
tests.t(dojox.validate.isEmailAddress("fred&barney@localhost", {allowLocal: true} ));
|
|
|
151 |
tests.f(dojox.validate.isEmailAddress("fred&barney@localhost"));
|
|
|
152 |
|
|
|
153 |
// addresses with cruft
|
|
|
154 |
tests.t(dojox.validate.isEmailAddress("mailto:fred&barney@stonehenge.com", {allowCruft: true} ));
|
|
|
155 |
tests.t(dojox.validate.isEmailAddress("<fred&barney@stonehenge.com>", {allowCruft: true} ));
|
|
|
156 |
tests.f(dojox.validate.isEmailAddress("mailto:fred&barney@stonehenge.com"));
|
|
|
157 |
tests.f(dojox.validate.isEmailAddress("<fred&barney@stonehenge.com>"));
|
|
|
158 |
|
|
|
159 |
// local addresses with cruft
|
|
|
160 |
tests.t(dojox.validate.isEmailAddress("<mailto:fred&barney@localhost>", {allowLocal: true, allowCruft: true} ));
|
|
|
161 |
tests.f(dojox.validate.isEmailAddress("<mailto:fred&barney@localhost>", {allowCruft: true} ));
|
|
|
162 |
tests.f(dojox.validate.isEmailAddress("<mailto:fred&barney@localhost>", {allowLocal: true} ));
|
|
|
163 |
}
|
|
|
164 |
},
|
|
|
165 |
{
|
|
|
166 |
name: "isEmailsAddressList",
|
|
|
167 |
runTests: function(tests) {
|
|
|
168 |
tests.t(dojox.validate.isEmailAddressList(
|
|
|
169 |
"x@yahoo.com \n x.y.z.w@yahoo.com ; o'mally@yahoo.com , fred&barney@stonehenge.com \n" )
|
|
|
170 |
);
|
|
|
171 |
tests.t(dojox.validate.isEmailAddressList(
|
|
|
172 |
"x@yahoo.com \n x.y.z.w@localhost \n o'mally@yahoo.com \n fred&barney@localhost",
|
|
|
173 |
{allowLocal: true} )
|
|
|
174 |
);
|
|
|
175 |
tests.f(dojox.validate.isEmailAddressList(
|
|
|
176 |
"x@yahoo.com; x.y.z.w@localhost; o'mally@yahoo.com; fred&barney@localhost", {listSeparator: ";"} )
|
|
|
177 |
);
|
|
|
178 |
tests.t(dojox.validate.isEmailAddressList(
|
|
|
179 |
"mailto:x@yahoo.com; <x.y.z.w@yahoo.com>; <mailto:o'mally@yahoo.com>; fred&barney@stonehenge.com",
|
|
|
180 |
{allowCruft: true, listSeparator: ";"} )
|
|
|
181 |
);
|
|
|
182 |
tests.f(dojox.validate.isEmailAddressList(
|
|
|
183 |
"mailto:x@yahoo.com; <x.y.z.w@yahoo.com>; <mailto:o'mally@yahoo.com>; fred&barney@stonehenge.com",
|
|
|
184 |
{listSeparator: ";"} )
|
|
|
185 |
);
|
|
|
186 |
tests.t(dojox.validate.isEmailAddressList(
|
|
|
187 |
"mailto:x@yahoo.com; <x.y.z.w@localhost>; <mailto:o'mally@localhost>; fred&barney@localhost",
|
|
|
188 |
{allowLocal: true, allowCruft: true, listSeparator: ";"} )
|
|
|
189 |
);
|
|
|
190 |
}
|
|
|
191 |
},
|
|
|
192 |
{
|
|
|
193 |
name: "getEmailAddressList",
|
|
|
194 |
runTests: function(tests) {
|
|
|
195 |
var list = "x@yahoo.com \n x.y.z.w@yahoo.com ; o'mally@yahoo.com , fred&barney@stonehenge.com";
|
|
|
196 |
tests.assertEquals(4, dojox.validate.getEmailAddressList(list).length);
|
|
|
197 |
|
|
|
198 |
var localhostList = "x@yahoo.com; x.y.z.w@localhost; o'mally@yahoo.com; fred&barney@localhost";
|
|
|
199 |
tests.assertEquals(0, dojox.validate.getEmailAddressList(localhostList).length);
|
|
|
200 |
tests.assertEquals(4, dojox.validate.getEmailAddressList(localhostList, {allowLocal: true} ).length);
|
|
|
201 |
}
|
|
|
202 |
},
|
|
|
203 |
{
|
|
|
204 |
name: "isInRange",
|
|
|
205 |
runTests: function(tests) {
|
|
|
206 |
// test integers
|
|
|
207 |
tests.f(dojox.validate.isInRange( '0', {min: 1, max: 100} ));
|
|
|
208 |
tests.t(dojox.validate.isInRange( '1', {min: 1, max: 100} ));
|
|
|
209 |
tests.f(dojox.validate.isInRange( '-50', {min: 1, max: 100} ));
|
|
|
210 |
tests.t(dojox.validate.isInRange( '+50', {min: 1, max: 100} ));
|
|
|
211 |
tests.t(dojox.validate.isInRange( '100', {min: 1, max: 100} ));
|
|
|
212 |
tests.f(dojox.validate.isInRange( '101', {min: 1, max: 100} ));
|
|
|
213 |
|
|
|
214 |
//test real numbers
|
|
|
215 |
tests.f(dojox.validate.isInRange( '0.9', {min: 1.0, max: 10.0} ));
|
|
|
216 |
tests.t(dojox.validate.isInRange( '1.0', {min: 1.0, max: 10.0} ));
|
|
|
217 |
tests.f(dojox.validate.isInRange( '-5.0', {min: 1.0, max: 10.0} ));
|
|
|
218 |
tests.t(dojox.validate.isInRange( '+5.50', {min: 1.0, max: 10.0} ));
|
|
|
219 |
tests.t(dojox.validate.isInRange( '10.0', {min: 1.0, max: 10.0} ));
|
|
|
220 |
tests.f(dojox.validate.isInRange( '10.1', {min: 1.0, max: 10.0} ));
|
|
|
221 |
tests.f(dojox.validate.isInRange( '5.566e28', {min: 5.567e28, max: 6.000e28} ));
|
|
|
222 |
tests.t(dojox.validate.isInRange( '5.7e28', {min: 5.567e28, max: 6.000e28} ));
|
|
|
223 |
tests.f(dojox.validate.isInRange( '6.00000001e28', {min: 5.567e28, max: 6.000e28} ));
|
|
|
224 |
tests.f(dojox.validate.isInRange( '10.000.000,12345e-5', {decimal: ",", max: 10000000.1e-5} ));
|
|
|
225 |
tests.f(dojox.validate.isInRange( '10.000.000,12345e-5', {decimal: ",", min: 10000000.2e-5} ));
|
|
|
226 |
tests.t(dojox.validate.isInRange('1,500,000', {separator: ',', min: 0}));
|
|
|
227 |
tests.f(dojox.validate.isInRange('1,500,000', {separator: ',', min: 1000, max: 20000}));
|
|
|
228 |
|
|
|
229 |
// test currency
|
|
|
230 |
tests.f(dojox.validate.isInRange('\u20AC123,456,789', {max: 123456788, symbol: '\u20AC'} ));
|
|
|
231 |
tests.f(dojox.validate.isInRange('\u20AC123,456,789', { min: 123456790, symbol: '\u20AC'} ));
|
|
|
232 |
tests.f(dojox.validate.isInRange('$123,456,789.07', { max: 123456789.06} ));
|
|
|
233 |
tests.f(dojox.validate.isInRange('$123,456,789.07', { min: 123456789.08} ));
|
|
|
234 |
tests.f(dojox.validate.isInRange('123.456.789,00 \u20AC', {max: 123456788, decimal: ",", symbol: '\u20AC'} ));
|
|
|
235 |
tests.f(dojox.validate.isInRange('123.456.789,00 \u20AC', {min: 123456790, decimal: ",", symbol: '\u20AC'} ));
|
|
|
236 |
tests.f(dojox.validate.isInRange('- T123 456 789-00', {decimal: "-", min:0} ));
|
|
|
237 |
tests.t(dojox.validate.isInRange('\u20AC123,456,789', { max: 123456790, symbol: '\u20AC'} ));
|
|
|
238 |
tests.t(dojox.validate.isInRange('$123,456,789.07', { min: 123456789.06} ));
|
|
|
239 |
|
|
|
240 |
// test non number
|
|
|
241 |
//tests.f("test25", dojox.validate.isInRange( 'a'));
|
|
|
242 |
}
|
|
|
243 |
},
|
|
|
244 |
{
|
|
|
245 |
name: "isUsPhoneNumber",
|
|
|
246 |
runTests: function(tests) {
|
|
|
247 |
tests.t(dojox.validate.us.isPhoneNumber('(111) 111-1111'));
|
|
|
248 |
tests.t(dojox.validate.us.isPhoneNumber('(111) 111 1111'));
|
|
|
249 |
tests.t(dojox.validate.us.isPhoneNumber('111 111 1111'));
|
|
|
250 |
tests.t(dojox.validate.us.isPhoneNumber('111.111.1111'));
|
|
|
251 |
tests.t(dojox.validate.us.isPhoneNumber('111-111-1111'));
|
|
|
252 |
tests.t(dojox.validate.us.isPhoneNumber('111/111-1111'));
|
|
|
253 |
tests.f(dojox.validate.us.isPhoneNumber('111 111-1111'));
|
|
|
254 |
tests.f(dojox.validate.us.isPhoneNumber('111-1111'));
|
|
|
255 |
tests.f(dojox.validate.us.isPhoneNumber('(111)-111-1111'));
|
|
|
256 |
|
|
|
257 |
// test extensions
|
|
|
258 |
tests.t(dojox.validate.us.isPhoneNumber('111-111-1111 x1'));
|
|
|
259 |
tests.t(dojox.validate.us.isPhoneNumber('111-111-1111 x12'));
|
|
|
260 |
tests.t(dojox.validate.us.isPhoneNumber('111-111-1111 x1234'));
|
|
|
261 |
}
|
|
|
262 |
},
|
|
|
263 |
{
|
|
|
264 |
name:"isUsSocialSecurityNumber",
|
|
|
265 |
runtests: function(tests) {
|
|
|
266 |
tests.t(dojox.validate.us.isSocialSecurityNumber('123-45-6789'));
|
|
|
267 |
tests.t(dojox.validate.us.isSocialSecurityNumber('123 45 6789'));
|
|
|
268 |
tests.t(dojox.validate.us.isSocialSecurityNumber('123456789'));
|
|
|
269 |
tests.f(dojox.validate.us.isSocialSecurityNumber('123-45 6789'));
|
|
|
270 |
tests.f(dojox.validate.us.isSocialSecurityNumber('12345 6789'));
|
|
|
271 |
tests.f(dojox.validate.us.isSocialSecurityNumber('123-456789'));
|
|
|
272 |
}
|
|
|
273 |
},
|
|
|
274 |
{
|
|
|
275 |
name:"isUsZipCode",
|
|
|
276 |
runtests: function(tests) {
|
|
|
277 |
tests.t(dojox.validate.us.isZipCode('12345-6789'));
|
|
|
278 |
tests.t(dojox.validate.us.isZipCode('12345 6789'));
|
|
|
279 |
tests.t(dojox.validate.us.isZipCode('123456789'));
|
|
|
280 |
tests.t(dojox.validate.us.isZipCode('12345'));
|
|
|
281 |
}
|
|
|
282 |
},
|
|
|
283 |
{
|
|
|
284 |
name:"isCaZipCode",
|
|
|
285 |
runtests: function(tests) {
|
|
|
286 |
tests.t(dojox.validate.ca.isPostalCode('A1Z 3F3'));
|
|
|
287 |
tests.f(dojox.validate.ca.isPostalCode('1AZ 3F3'));
|
|
|
288 |
tests.t(dojox.validate.ca.isPostalCode('a1z 3f3'));
|
|
|
289 |
tests.f(dojox.validate.ca.isPostalCode('xxxxxx'));
|
|
|
290 |
tests.t(dojox.validate.ca.isPostalCode('A1Z3F3'));
|
|
|
291 |
|
|
|
292 |
}
|
|
|
293 |
},
|
|
|
294 |
{
|
|
|
295 |
name:"isUsState",
|
|
|
296 |
runtests: function(tests) {
|
|
|
297 |
tests.t(dojox.validate.us.isState('CA'));
|
|
|
298 |
tests.t(dojox.validate.us.isState('ne'));
|
|
|
299 |
tests.t(dojox.validate.us.isState('PR'));
|
|
|
300 |
tests.f(dojox.validate.us.isState('PR', {allowTerritories: false} ));
|
|
|
301 |
tests.t(dojox.validate.us.isState('AA'));
|
|
|
302 |
tests.f(dojox.validate.us.isState('AA', {allowMilitary: false} ));
|
|
|
303 |
}
|
|
|
304 |
},
|
|
|
305 |
{
|
|
|
306 |
name:"formCheck",
|
|
|
307 |
runtests: function(tests) {
|
|
|
308 |
var f = {
|
|
|
309 |
// textboxes
|
|
|
310 |
tx1: {type: "text", value: " 1001 ", name: "tx1"},
|
|
|
311 |
tx2: {type: "text", value: " x", name: "tx2"},
|
|
|
312 |
tx3: {type: "text", value: "10/19/2005", name: "tx3"},
|
|
|
313 |
tx4: {type: "text", value: "10/19/2005", name: "tx4"},
|
|
|
314 |
tx5: {type: "text", value: "Foo@Localhost", name: "tx5"},
|
|
|
315 |
tx6: {type: "text", value: "Foo@Localhost", name: "tx6"},
|
|
|
316 |
tx7: {type: "text", value: "<Foo@Gmail.Com>", name: "tx7"},
|
|
|
317 |
tx8: {type: "text", value: " ", name: "tx8"},
|
|
|
318 |
tx9: {type: "text", value: "ca", name: "tx9"},
|
|
|
319 |
tx10: {type: "text", value: "homer SIMPSON", name: "tx10"},
|
|
|
320 |
tx11: {type: "text", value: "$1,000,000 (US)", name: "tx11"},
|
|
|
321 |
tx12: {type: "text", value: "as12.a13", name: "tx12"},
|
|
|
322 |
tx13: {type: "text", value: "4.13", name: "tx13"},
|
|
|
323 |
tx14: {type: "text", value: "15.681", name: "tx14"},
|
|
|
324 |
tx15: {value: "1", name: "tx15"},
|
|
|
325 |
cc_no: {type: "text", value: "5434 1111 1111 1111", name: "cc_no"},
|
|
|
326 |
cc_exp: {type: "text", value: "", name: "cc_exp"},
|
|
|
327 |
cc_type: {type: "text", value: "Visa", name: "cc_type"},
|
|
|
328 |
email: {type: "text", value: "foo@gmail.com", name: "email"},
|
|
|
329 |
email_confirm: {type: "text", value: "foo2@gmail.com", name: "email_confirm"},
|
|
|
330 |
// password
|
|
|
331 |
pw1: {type: "password", value: "123456", name: "pw1"},
|
|
|
332 |
pw2: {type: "password", value: "123456", name: "pw2"},
|
|
|
333 |
// textarea - they have a type property, even though no html attribute
|
|
|
334 |
ta1: {type: "textarea", value: "", name: "ta1"},
|
|
|
335 |
ta2: {type: "textarea", value: "", name: "ta2"},
|
|
|
336 |
// radio button groups
|
|
|
337 |
rb1: [
|
|
|
338 |
{type: "radio", value: "v0", name: "rb1", checked: false},
|
|
|
339 |
{type: "radio", value: "v1", name: "rb1", checked: false},
|
|
|
340 |
{type: "radio", value: "v2", name: "rb1", checked: true}
|
|
|
341 |
],
|
|
|
342 |
rb2: [
|
|
|
343 |
{type: "radio", value: "v0", name: "rb2", checked: false},
|
|
|
344 |
{type: "radio", value: "v1", name: "rb2", checked: false},
|
|
|
345 |
{type: "radio", value: "v2", name: "rb2", checked: false}
|
|
|
346 |
],
|
|
|
347 |
rb3: [
|
|
|
348 |
{type: "radio", value: "v0", name: "rb3", checked: false},
|
|
|
349 |
{type: "radio", value: "v1", name: "rb3", checked: false},
|
|
|
350 |
{type: "radio", value: "v2", name: "rb3", checked: false}
|
|
|
351 |
],
|
|
|
352 |
// checkboxes
|
|
|
353 |
cb1: {type: "checkbox", value: "cb1", name: "cb1", checked: false},
|
|
|
354 |
cb2: {type: "checkbox", value: "cb2", name: "cb2", checked: false},
|
|
|
355 |
// checkbox group with the same name
|
|
|
356 |
cb3: [
|
|
|
357 |
{type: "checkbox", value: "v0", name: "cb3", checked: false},
|
|
|
358 |
{type: "checkbox", value: "v1", name: "cb3", checked: false},
|
|
|
359 |
{type: "checkbox", value: "v2", name: "cb3", checked: false}
|
|
|
360 |
],
|
|
|
361 |
doubledip: [
|
|
|
362 |
{type: "checkbox", value: "vanilla", name: "doubledip", checked: false},
|
|
|
363 |
{type: "checkbox", value: "chocolate", name: "doubledip", checked: false},
|
|
|
364 |
{type: "checkbox", value: "chocolate chip", name: "doubledip", checked: false},
|
|
|
365 |
{type: "checkbox", value: "lemon custard", name: "doubledip", checked: true},
|
|
|
366 |
{type: "checkbox", value: "pistachio almond", name: "doubledip", checked: false}
|
|
|
367 |
],
|
|
|
368 |
// <select>
|
|
|
369 |
s1: {
|
|
|
370 |
type: "select-one",
|
|
|
371 |
name: "s1",
|
|
|
372 |
selectedIndex: -1,
|
|
|
373 |
options: [
|
|
|
374 |
{text: "option 1", value: "v0", selected: false},
|
|
|
375 |
{text: "option 2", value: "v1", selected: false},
|
|
|
376 |
{text: "option 3", value: "v2", selected: false}
|
|
|
377 |
]
|
|
|
378 |
},
|
|
|
379 |
// <select multiple>
|
|
|
380 |
s2: {
|
|
|
381 |
type: "select-multiple",
|
|
|
382 |
name: "s2",
|
|
|
383 |
selectedIndex: 1,
|
|
|
384 |
options: [
|
|
|
385 |
{text: "option 1", value: "v0", selected: false},
|
|
|
386 |
{text: "option 2", value: "v1", selected: true},
|
|
|
387 |
{text: "option 3", value: "v2", selected: true}
|
|
|
388 |
]
|
|
|
389 |
},
|
|
|
390 |
tripledip: {
|
|
|
391 |
type: "select-multiple",
|
|
|
392 |
name: "tripledip",
|
|
|
393 |
selectedIndex: 3,
|
|
|
394 |
options: [
|
|
|
395 |
{text: "option 1", value: "vanilla", selected: false},
|
|
|
396 |
{text: "option 2", value: "chocolate", selected: false},
|
|
|
397 |
{text: "option 3", value: "chocolate chip", selected: false},
|
|
|
398 |
{text: "option 4", value: "lemon custard", selected: true},
|
|
|
399 |
{text: "option 5", value: "pistachio almond", selected: true},
|
|
|
400 |
{text: "option 6", value: "mocha almond chip", selected: false}
|
|
|
401 |
]
|
|
|
402 |
},
|
|
|
403 |
doublea: {
|
|
|
404 |
type: "select-multiple",
|
|
|
405 |
name: "doublea",
|
|
|
406 |
selectedIndex: 2,
|
|
|
407 |
options: [
|
|
|
408 |
{text: "option 1", value: "vanilla", selected: false},
|
|
|
409 |
{text: "option 2", value: "chocolate", selected: true},
|
|
|
410 |
{text: "option 3", value: "", selected: true}
|
|
|
411 |
]
|
|
|
412 |
},
|
|
|
413 |
// <select> null selection
|
|
|
414 |
s3: {
|
|
|
415 |
type: "select-one",
|
|
|
416 |
name: "s3",
|
|
|
417 |
selectedIndex: 0,
|
|
|
418 |
options: [
|
|
|
419 |
{text: "option 1", value: "", selected: true},
|
|
|
420 |
{text: "option 2", value: "v1", selected: false},
|
|
|
421 |
{text: "option 3", value: "v2", selected: false}
|
|
|
422 |
]
|
|
|
423 |
},
|
|
|
424 |
selectAlien: {
|
|
|
425 |
name: "selectAlien",
|
|
|
426 |
multiple: "multiple",
|
|
|
427 |
id: "selectAlient",
|
|
|
428 |
size: "10",
|
|
|
429 |
length: 0,
|
|
|
430 |
options: [],
|
|
|
431 |
value:[]
|
|
|
432 |
}
|
|
|
433 |
};
|
|
|
434 |
|
|
|
435 |
// Profile for form input
|
|
|
436 |
var profile = {
|
|
|
437 |
// filters
|
|
|
438 |
trim: ["tx1", "tx2"],
|
|
|
439 |
uppercase: ["tx9"],
|
|
|
440 |
lowercase: ["tx5", "tx6", "tx7"],
|
|
|
441 |
ucfirst: ["tx10"],
|
|
|
442 |
digit: ["tx11"],
|
|
|
443 |
// required fields
|
|
|
444 |
required: ["tx2", "tx3", "tx4", "tx5", "tx6", "tx7", "tx8", "tx15", "pw1", "ta1", "rb1", "rb2",
|
|
|
445 |
"cb3", "s1", "s2", "s3",
|
|
|
446 |
{"doubledip":2}, {"tripledip":3}, {"doublea":2} ],
|
|
|
447 |
// dependant/conditional fields
|
|
|
448 |
dependencies: {
|
|
|
449 |
cc_exp: "cc_no",
|
|
|
450 |
cc_type: "cc_no"
|
|
|
451 |
},
|
|
|
452 |
// validated fields
|
|
|
453 |
constraints: {
|
|
|
454 |
tx1: dojox.validate.isInteger,
|
|
|
455 |
tx2: dojox.validate.isInteger,
|
|
|
456 |
tx3: [dojo.date.parse, {locale: 'en-us'}],
|
|
|
457 |
tx4: [dojo.date.parse, {locale: 'fr-fr'}],
|
|
|
458 |
tx5: [dojox.validate.isEmailAddress],
|
|
|
459 |
tx6: [dojox.validate.isEmailAddress, {allowLocal: true}],
|
|
|
460 |
tx7: [dojox.validate.isEmailAddress, {allowCruft: true}],
|
|
|
461 |
tx8: dojox.validate.isURL,
|
|
|
462 |
tx12: [[dojox.validate.isRealNumber],[dojox.validate.isInRange, {max:100.00,min:5.0}]],
|
|
|
463 |
tx13: [[dojox.validate.isRealNumber],[dojox.validate.isInRange, {max:100.00,min:5.0}]],
|
|
|
464 |
tx14: [[dojox.validate.isRealNumber],[dojox.validate.isInRange, {max:100.00,min:5.0}]]
|
|
|
465 |
},
|
|
|
466 |
// confirm fields
|
|
|
467 |
confirm: {
|
|
|
468 |
email_confirm: "email",
|
|
|
469 |
pw2: "pw1"
|
|
|
470 |
}
|
|
|
471 |
};
|
|
|
472 |
|
|
|
473 |
// results object
|
|
|
474 |
var results = dojox.validate.check(f, profile);
|
|
|
475 |
|
|
|
476 |
// test filter stuff
|
|
|
477 |
tests.asserEquals("1001", f.tx1.value );
|
|
|
478 |
tests.asserEquals("x", f.tx2.value );
|
|
|
479 |
tests.asserEquals("CA", f.tx9.value );
|
|
|
480 |
tests.asserEquals("foo@localhost", f.tx5.value );
|
|
|
481 |
tests.asserEquals("foo@localhost", f.tx6.value );
|
|
|
482 |
tests.asserEquals("<foo@gmail.com>", f.tx7.value );
|
|
|
483 |
tests.asserEquals("Homer Simpson", f.tx10.value );
|
|
|
484 |
tests.asserEquals("1000000", f.tx11.value );
|
|
|
485 |
|
|
|
486 |
// test missing stuff
|
|
|
487 |
tests.f(results.isSuccessful() );
|
|
|
488 |
tests.t(results.hasMissing() );
|
|
|
489 |
tests.f(results.isMissing("tx1") );
|
|
|
490 |
tests.f(results.isMissing("tx2") );
|
|
|
491 |
tests.f(results.isMissing("tx3") );
|
|
|
492 |
tests.f(results.isMissing("tx4") );
|
|
|
493 |
tests.f(results.isMissing("tx5") );
|
|
|
494 |
tests.f(results.isMissing("tx6") );
|
|
|
495 |
tests.f(results.isMissing("tx7") );
|
|
|
496 |
tests.t(results.isMissing("tx8") );
|
|
|
497 |
tests.f(results.isMissing("pw1") );
|
|
|
498 |
tests.f(results.isMissing("pw2") );
|
|
|
499 |
tests.t(results.isMissing("ta1") );
|
|
|
500 |
tests.f(results.isMissing("ta2") );
|
|
|
501 |
tests.f(results.isMissing("rb1") );
|
|
|
502 |
tests.t(results.isMissing("rb2") );
|
|
|
503 |
tests.f(results.isMissing("rb3") );
|
|
|
504 |
tests.t(results.isMissing("cb3") );
|
|
|
505 |
tests.t(results.isMissing("s1") );
|
|
|
506 |
tests.f(results.isMissing("s2") );
|
|
|
507 |
tests.t(results.isMissing("s3"));
|
|
|
508 |
tests.t(results.isMissing("doubledip") );
|
|
|
509 |
tests.t(results.isMissing("tripledip") );
|
|
|
510 |
tests.t(results.isMissing("doublea"));
|
|
|
511 |
tests.f(results.isMissing("cc_no") );
|
|
|
512 |
tests.t(results.isMissing("cc_exp") );
|
|
|
513 |
tests.f(results.isMissing("cc_type") );
|
|
|
514 |
// missing: tx8, ta1, rb2, cb3, s1, s3, doubledip, tripledip, cc_exp
|
|
|
515 |
tests.asserEquals(10, results.getMissing().length );
|
|
|
516 |
|
|
|
517 |
// test constraint stuff
|
|
|
518 |
tests.t(results.hasInvalid() );
|
|
|
519 |
tests.f(results.isInvalid("tx1") );
|
|
|
520 |
tests.t(results.isInvalid("tx2") );
|
|
|
521 |
tests.f(results.isInvalid("tx3") );
|
|
|
522 |
tests.t(results.isInvalid("tx4") );
|
|
|
523 |
tests.t(results.isInvalid("tx5") );
|
|
|
524 |
tests.f(results.isInvalid("tx6") );
|
|
|
525 |
tests.f(results.isInvalid("tx7") );
|
|
|
526 |
tests.f(results.isInvalid("tx8") );
|
|
|
527 |
tests.f(results.isInvalid("pw1") );
|
|
|
528 |
tests.f(results.isInvalid("pw2") );
|
|
|
529 |
tests.f(results.isInvalid("ta1") );
|
|
|
530 |
tests.f(results.isInvalid("ta2") );
|
|
|
531 |
tests.f(results.isInvalid("email") );
|
|
|
532 |
tests.t(results.isInvalid("email_confirm") );
|
|
|
533 |
|
|
|
534 |
// invlaid: txt2, txt4, txt5, email_confirm, selectAlien
|
|
|
535 |
|
|
|
536 |
tests.asserEquals(7, results.getInvalid().length);
|
|
|
537 |
tests.t(results.isInvalid("tx12"));
|
|
|
538 |
tests.t(results.isInvalid("tx13"));
|
|
|
539 |
tests.f(results.isInvalid("tx14"));
|
|
|
540 |
tests.t(results.isInvalid("selectAlien"));
|
|
|
541 |
}
|
|
|
542 |
}
|
|
|
543 |
]);
|
|
|
544 |
|
|
|
545 |
}
|