Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 2149 → Rev 2150

/trunk/api/js/dojo1.0/dojox/validate/tests/creditcard.js
New file
0,0 → 1,119
if(!dojo._hasResource["dojox.validate.tests.creditcard"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.validate.tests.creditcard"] = true;
dojo.provide("dojox.validate.tests.creditcard");
dojo.require("dojox.validate.creditCard");
 
tests.register("dojox.validate.tests.creditcard",
[{
name:"isValidLuhn",
runTests: function(tests) {
tests.t(dojox.validate.isValidLuhn('5105105105105100')); //test string input
tests.t(dojox.validate.isValidLuhn('5105-1051 0510-5100')); //test string input with dashes and spaces (commonly used when entering card #'s)
tests.t(dojox.validate.isValidLuhn(38520000023237)); //test numerical input as well
tests.f(dojox.validate.isValidLuhn(3852000002323)); //testing failures
tests.t(dojox.validate.isValidLuhn(18)); //length doesnt matter
tests.f(dojox.validate.isValidLuhn(818181)); //short length failure
}
},
{
name:"isValidCvv",
runTests: function(tests) {
tests.t(dojox.validate.isValidCvv('123','mc')); //string is ok
tests.f(dojox.validate.isValidCvv('5AA','ec')); //invalid characters are not ok
tests.t(dojox.validate.isValidCvv(723,'mc')); //numbers are ok too
tests.f(dojox.validate.isValidCvv(7234,'mc')); //too long
tests.t(dojox.validate.isValidCvv(612,'ec'));
tests.t(dojox.validate.isValidCvv(421,'vi'));
tests.t(dojox.validate.isValidCvv(543,'di'));
tests.t(dojox.validate.isValidCvv('1234','ax'));
tests.t(dojox.validate.isValidCvv(4321,'ax'));
tests.f(dojox.validate.isValidCvv(43215,'ax')); //too long
tests.f(dojox.validate.isValidCvv(215,'ax')); //too short
}
},
{
name:"isValidCreditCard",
runTests: function(tests) {
//misc checks
tests.t(dojox.validate.isValidCreditCard('5105105105105100','mc')); //test string input
tests.t(dojox.validate.isValidCreditCard('5105-1051 0510-5100','mc')); //test string input with dashes and spaces (commonly used when entering card #'s)
tests.t(dojox.validate.isValidCreditCard(5105105105105100,'mc')); //test numerical input as well
tests.f(dojox.validate.isValidCreditCard('5105105105105100','vi')); //fails, wrong card type
//Mastercard/Eurocard checks
tests.t(dojox.validate.isValidCreditCard('5105105105105100','mc'));
tests.t(dojox.validate.isValidCreditCard('5204105105105100','ec'));
tests.t(dojox.validate.isValidCreditCard('5303105105105100','mc'));
tests.t(dojox.validate.isValidCreditCard('5402105105105100','ec'));
tests.t(dojox.validate.isValidCreditCard('5501105105105100','mc'));
//Visa card checks
tests.t(dojox.validate.isValidCreditCard('4111111111111111','vi'));
tests.t(dojox.validate.isValidCreditCard('4111111111010','vi'));
//American Express card checks
tests.t(dojox.validate.isValidCreditCard('378 2822 4631 0005','ax'));
tests.t(dojox.validate.isValidCreditCard('341-1111-1111-1111','ax'));
//Diners Club/Carte Blanch card checks
tests.t(dojox.validate.isValidCreditCard('36400000000000','dc'));
tests.t(dojox.validate.isValidCreditCard('38520000023237','bl'));
tests.t(dojox.validate.isValidCreditCard('30009009025904','dc'));
tests.t(dojox.validate.isValidCreditCard('30108009025904','bl'));
tests.t(dojox.validate.isValidCreditCard('30207009025904','dc'));
tests.t(dojox.validate.isValidCreditCard('30306009025904','bl'));
tests.t(dojox.validate.isValidCreditCard('30405009025904','dc'));
tests.t(dojox.validate.isValidCreditCard('30504009025904','bl'));
//Discover card checks
tests.t(dojox.validate.isValidCreditCard('6011111111111117','di'));
//JCB card checks
tests.t(dojox.validate.isValidCreditCard('3530111333300000','jcb'));
tests.t(dojox.validate.isValidCreditCard('213100000000001','jcb'));
tests.t(dojox.validate.isValidCreditCard('180000000000002','jcb'));
tests.f(dojox.validate.isValidCreditCard('1800000000000002','jcb')); //should fail, good checksum, good prefix, but wrong length'
//Enroute card checks
tests.t(dojox.validate.isValidCreditCard('201400000000000','er'));
tests.t(dojox.validate.isValidCreditCard('214900000000000','er'));
}
},
{
name:"isValidCreditCardNumber",
runTests: function(tests) {
//misc checks
tests.t(dojox.validate.isValidCreditCardNumber('5105105105105100','mc')); //test string input
tests.t(dojox.validate.isValidCreditCardNumber('5105-1051 0510-5100','mc')); //test string input with dashes and spaces (commonly used when entering card #'s)
tests.t(dojox.validate.isValidCreditCardNumber(5105105105105100,'mc')); //test numerical input as well
tests.f(dojox.validate.isValidCreditCardNumber('5105105105105100','vi')); //fails, wrong card type
//Mastercard/Eurocard checks
tests.is("mc|ec", dojox.validate.isValidCreditCardNumber('5100000000000000')); //should match 'mc|ec'
tests.is("mc|ec", dojox.validate.isValidCreditCardNumber('5200000000000000')); //should match 'mc|ec'
tests.is("mc|ec", dojox.validate.isValidCreditCardNumber('5300000000000000')); //should match 'mc|ec'
tests.is("mc|ec", dojox.validate.isValidCreditCardNumber('5400000000000000')); //should match 'mc|ec'
tests.is("mc|ec", dojox.validate.isValidCreditCardNumber('5500000000000000')); //should match 'mc|ec'
tests.f(dojox.validate.isValidCreditCardNumber('55000000000000000')); //should fail, too long
//Visa card checks
tests.is("vi", dojox.validate.isValidCreditCardNumber('4111111111111111')); //should match 'vi'
tests.is("vi", dojox.validate.isValidCreditCardNumber('4111111111010')); //should match 'vi'
//American Express card checks
tests.is("ax", dojox.validate.isValidCreditCardNumber('378 2822 4631 0005')); //should match 'ax'
tests.is("ax", dojox.validate.isValidCreditCardNumber('341-1111-1111-1111')); //should match 'ax'
//Diners Club/Carte Blanch card checks
tests.is("dc|bl", dojox.validate.isValidCreditCardNumber('36400000000000')); //should match 'dc|bl'
tests.is("dc|bl", dojox.validate.isValidCreditCardNumber('38520000023237')); //should match 'dc|bl'
tests.is("dc|bl", dojox.validate.isValidCreditCardNumber('30009009025904')); //should match 'di|bl'
tests.is("dc|bl", dojox.validate.isValidCreditCardNumber('30108009025904')); //should match 'di|bl'
tests.is("dc|bl", dojox.validate.isValidCreditCardNumber('30207009025904')); //should match 'di|bl'
tests.is("dc|bl", dojox.validate.isValidCreditCardNumber('30306009025904')); //should match 'di|bl'
tests.is("dc|bl", dojox.validate.isValidCreditCardNumber('30405009025904')); //should match 'di|bl'
tests.is("dc|bl", dojox.validate.isValidCreditCardNumber('30504009025904')); //should match 'di|bl'
//Discover card checks
tests.is("di", dojox.validate.isValidCreditCardNumber('6011111111111117')); //should match 'di'
//JCB card checks
tests.is("jcb", dojox.validate.isValidCreditCardNumber('3530111333300000')); //should match 'jcb'
tests.is("jcb", dojox.validate.isValidCreditCardNumber('213100000000001')); //should match 'jcb'
tests.is("jcb", dojox.validate.isValidCreditCardNumber('180000000000002')); //should match 'jcb'
tests.f(dojox.validate.isValidCreditCardNumber('1800000000000002')); //should fail, good checksum, good prefix, but wrong length'
//Enroute card checks
tests.is("er", dojox.validate.isValidCreditCardNumber('201400000000000')); //should match 'er'
tests.is("er", dojox.validate.isValidCreditCardNumber('214900000000000')); //should match 'er'
}
}
]);
 
}
/trunk/api/js/dojo1.0/dojox/validate/tests/module.js
New file
0,0 → 1,14
if(!dojo._hasResource["dojox.validate.tests.module"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.validate.tests.module"] = true;
dojo.provide("dojox.validate.tests.module");
 
try{
dojo.require("dojox.validate.tests.creditcard");
dojo.require("dojox.validate.tests.validate");
 
}catch(e){
doh.debug(e);
console.debug(e);
}
 
}
/trunk/api/js/dojo1.0/dojox/validate/tests/validate.js
New file
0,0 → 1,545
if(!dojo._hasResource["dojox.validate.tests.validate"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.validate.tests.validate"] = true;
dojo.provide("dojox.validate.tests.validate");
 
dojo.require("dojox.validate._base");
dojo.require("dojox.validate.check");
dojo.require("dojox.validate.us");
dojo.require("dojox.validate.ca");
dojo.require("dojox.validate.web");
dojo.require("dojox.validate.isbn");
 
tests.register("dojox.validate.tests.validate",
[{
name: "isText",
runTest: function(tests){
tests.t(dojox.validate.isValidIsbn('0596007590')); //test string input
tests.t(dojox.validate.isValidIsbn('0-596-00759-0')); //test string input with dashes
tests.f(dojox.validate.isValidIsbn(0596007590)); //test numerical input as well
tests.t(dojox.validate.isValidIsbn("960-425-059-0"));
tests.t(dojox.validate.isValidIsbn(9604250590)); //test numerical input as well
tests.t(dojox.validate.isValidIsbn('0-9752298-0-X')); // test string with X
tests.t(dojox.validate.isValidIsbn('0-9752298-0-x'));
tests.t(dojox.validate.isValidIsbn('097522980x'));
tests.t(dojox.validate.isValidIsbn('097522980X'));
tests.f(dojox.validate.isValidIsbn(0596007598)); //testing failures
tests.f(dojox.validate.isValidIsbn('059-600759-X')); //testing failures
tests.f(dojox.validate.isValidIsbn('059600')); // too short
 
tests.t(dojox.validate.isValidIsbn('9780596007591'));
tests.t(dojox.validate.isValidIsbn('978-0-596 00759-1'));
tests.t(dojox.validate.isValidIsbn(9780596007591));
tests.f(dojox.validate.isValidIsbn('978059600759X'));
tests.f(dojox.validate.isValidIsbn('978-3250-596 00759-1 '));
tests.f(dojox.validate.isValidIsbn('3250-596 00759 '));
 
tests.t(dojox.validate.isText(' x'));
tests.t(dojox.validate.isText('x '));
tests.t(dojox.validate.isText(' x '));
tests.f(dojox.validate.isText(' '));
tests.f(dojox.validate.isText(''));
// test lengths
tests.t(dojox.validate.isText('123456', {length: 6} ));
tests.f(dojox.validate.isText('1234567', {length: 6} ));
tests.t(dojox.validate.isText('1234567', {minlength: 6} ));
tests.t(dojox.validate.isText('123456', {minlength: 6} ));
tests.f(dojox.validate.isText('12345', {minlength: 6} ));
tests.f(dojox.validate.isText('1234567', {maxlength: 6} ));
tests.t(dojox.validate.isText('123456', {maxlength: 6} ));
}
},
{
name: "isIpAddress",
runTest: function(tests){
tests.t(dojox.validate.isIpAddress('24.17.155.40'));
tests.f(dojox.validate.isIpAddress('024.17.155.040'));
tests.t(dojox.validate.isIpAddress('255.255.255.255'));
tests.f(dojox.validate.isIpAddress('256.255.255.255'));
tests.f(dojox.validate.isIpAddress('255.256.255.255'));
tests.f(dojox.validate.isIpAddress('255.255.256.255'));
tests.f(dojox.validate.isIpAddress('255.255.255.256'));
 
// test dotted hex
tests.t(dojox.validate.isIpAddress('0x18.0x11.0x9b.0x28'));
tests.f(dojox.validate.isIpAddress('0x18.0x11.0x9b.0x28', {allowDottedHex: false}) );
tests.t(dojox.validate.isIpAddress('0x18.0x000000011.0x9b.0x28'));
tests.t(dojox.validate.isIpAddress('0xff.0xff.0xff.0xff'));
tests.f(dojox.validate.isIpAddress('0x100.0xff.0xff.0xff'));
 
// test dotted octal
tests.t(dojox.validate.isIpAddress('0030.0021.0233.0050'));
tests.f(dojox.validate.isIpAddress('0030.0021.0233.0050', {allowDottedOctal: false}) );
tests.t(dojox.validate.isIpAddress('0030.0000021.0233.00000050'));
tests.t(dojox.validate.isIpAddress('0377.0377.0377.0377'));
tests.f(dojox.validate.isIpAddress('0400.0377.0377.0377'));
tests.f(dojox.validate.isIpAddress('0377.0378.0377.0377'));
tests.f(dojox.validate.isIpAddress('0377.0377.0380.0377'));
tests.f(dojox.validate.isIpAddress('0377.0377.0377.377'));
// test decimal
tests.t(dojox.validate.isIpAddress('3482223595'));
tests.t(dojox.validate.isIpAddress('0'));
tests.t(dojox.validate.isIpAddress('4294967295'));
tests.f(dojox.validate.isIpAddress('4294967296'));
tests.f(dojox.validate.isIpAddress('3482223595', {allowDecimal: false}));
// test hex
tests.t(dojox.validate.isIpAddress('0xCF8E83EB'));
tests.t(dojox.validate.isIpAddress('0x0'));
tests.t(dojox.validate.isIpAddress('0x00ffffffff'));
tests.f(dojox.validate.isIpAddress('0x100000000'));
tests.f(dojox.validate.isIpAddress('0xCF8E83EB', {allowHex: false}));
// IPv6
tests.t(dojox.validate.isIpAddress('fedc:BA98:7654:3210:FEDC:BA98:7654:3210'));
tests.t(dojox.validate.isIpAddress('1080:0:0:0:8:800:200C:417A'));
tests.f(dojox.validate.isIpAddress('1080:0:0:0:8:800:200C:417A', {allowIPv6: false}));
// Hybrid of IPv6 and IPv4
tests.t(dojox.validate.isIpAddress('0:0:0:0:0:0:13.1.68.3'));
tests.t(dojox.validate.isIpAddress('0:0:0:0:0:FFFF:129.144.52.38'));
tests.f(dojox.validate.isIpAddress('0:0:0:0:0:FFFF:129.144.52.38', {allowHybrid: false}));
}
},
{
name:"isUrl",
runTests: function(tests){
 
tests.t(dojox.validate.isUrl('www.yahoo.com'));
tests.t(dojox.validate.isUrl('http://www.yahoo.com'));
tests.t(dojox.validate.isUrl('https://www.yahoo.com'));
tests.f(dojox.validate.isUrl('http://.yahoo.com'));
tests.f(dojox.validate.isUrl('http://www.-yahoo.com'));
tests.f(dojox.validate.isUrl('http://www.yahoo-.com'));
tests.t(dojox.validate.isUrl('http://y-a---h-o-o.com'));
tests.t(dojox.validate.isUrl('http://www.y.com'));
tests.t(dojox.validate.isUrl('http://www.yahoo.museum'));
tests.t(dojox.validate.isUrl('http://www.yahoo.co.uk'));
tests.f(dojox.validate.isUrl('http://www.micro$oft.com'));
tests.t(dojox.validate.isUrl('http://www.y.museum:8080'));
tests.t(dojox.validate.isUrl('http://12.24.36.128:8080'));
tests.f(dojox.validate.isUrl('http://12.24.36.128:8080', {allowIP: false} ));
tests.t(dojox.validate.isUrl('www.y.museum:8080'));
tests.f(dojox.validate.isUrl('www.y.museum:8080', {scheme: true} ));
tests.t(dojox.validate.isUrl('localhost:8080', {allowLocal: true} ));
tests.f(dojox.validate.isUrl('localhost:8080', {} ));
tests.t(dojox.validate.isUrl('http://www.yahoo.com/index.html?a=12&b=hello%20world#anchor'));
tests.f(dojox.validate.isUrl('http://www.yahoo.xyz'));
tests.t(dojox.validate.isUrl('http://www.yahoo.com/index.html#anchor'));
tests.t(dojox.validate.isUrl('http://cocoon.apache.org/2.1/'));
}
},
{
name: "isEmailAddress",
runTests: function(tests) {
tests.t(dojox.validate.isEmailAddress('x@yahoo.com'));
tests.t(dojox.validate.isEmailAddress('x.y.z.w@yahoo.com'));
tests.f(dojox.validate.isEmailAddress('x..y.z.w@yahoo.com'));
tests.f(dojox.validate.isEmailAddress('x.@yahoo.com'));
tests.t(dojox.validate.isEmailAddress('x@z.com'));
tests.f(dojox.validate.isEmailAddress('x@yahoo.x'));
tests.t(dojox.validate.isEmailAddress('x@yahoo.museum'));
tests.t(dojox.validate.isEmailAddress("o'mally@yahoo.com"));
tests.f(dojox.validate.isEmailAddress("'mally@yahoo.com"));
tests.t(dojox.validate.isEmailAddress("fred&barney@stonehenge.com"));
tests.f(dojox.validate.isEmailAddress("fred&&barney@stonehenge.com"));
// local addresses
tests.t(dojox.validate.isEmailAddress("fred&barney@localhost", {allowLocal: true} ));
tests.f(dojox.validate.isEmailAddress("fred&barney@localhost"));
// addresses with cruft
tests.t(dojox.validate.isEmailAddress("mailto:fred&barney@stonehenge.com", {allowCruft: true} ));
tests.t(dojox.validate.isEmailAddress("<fred&barney@stonehenge.com>", {allowCruft: true} ));
tests.f(dojox.validate.isEmailAddress("mailto:fred&barney@stonehenge.com"));
tests.f(dojox.validate.isEmailAddress("<fred&barney@stonehenge.com>"));
// local addresses with cruft
tests.t(dojox.validate.isEmailAddress("<mailto:fred&barney@localhost>", {allowLocal: true, allowCruft: true} ));
tests.f(dojox.validate.isEmailAddress("<mailto:fred&barney@localhost>", {allowCruft: true} ));
tests.f(dojox.validate.isEmailAddress("<mailto:fred&barney@localhost>", {allowLocal: true} ));
}
},
{
name: "isEmailsAddressList",
runTests: function(tests) {
tests.t(dojox.validate.isEmailAddressList(
"x@yahoo.com \n x.y.z.w@yahoo.com ; o'mally@yahoo.com , fred&barney@stonehenge.com \n" )
);
tests.t(dojox.validate.isEmailAddressList(
"x@yahoo.com \n x.y.z.w@localhost \n o'mally@yahoo.com \n fred&barney@localhost",
{allowLocal: true} )
);
tests.f(dojox.validate.isEmailAddressList(
"x@yahoo.com; x.y.z.w@localhost; o'mally@yahoo.com; fred&barney@localhost", {listSeparator: ";"} )
);
tests.t(dojox.validate.isEmailAddressList(
"mailto:x@yahoo.com; <x.y.z.w@yahoo.com>; <mailto:o'mally@yahoo.com>; fred&barney@stonehenge.com",
{allowCruft: true, listSeparator: ";"} )
);
tests.f(dojox.validate.isEmailAddressList(
"mailto:x@yahoo.com; <x.y.z.w@yahoo.com>; <mailto:o'mally@yahoo.com>; fred&barney@stonehenge.com",
{listSeparator: ";"} )
);
tests.t(dojox.validate.isEmailAddressList(
"mailto:x@yahoo.com; <x.y.z.w@localhost>; <mailto:o'mally@localhost>; fred&barney@localhost",
{allowLocal: true, allowCruft: true, listSeparator: ";"} )
);
}
},
{
name: "getEmailAddressList",
runTests: function(tests) {
var list = "x@yahoo.com \n x.y.z.w@yahoo.com ; o'mally@yahoo.com , fred&barney@stonehenge.com";
tests.assertEquals(4, dojox.validate.getEmailAddressList(list).length);
 
var localhostList = "x@yahoo.com; x.y.z.w@localhost; o'mally@yahoo.com; fred&barney@localhost";
tests.assertEquals(0, dojox.validate.getEmailAddressList(localhostList).length);
tests.assertEquals(4, dojox.validate.getEmailAddressList(localhostList, {allowLocal: true} ).length);
}
},
{
name: "isInRange",
runTests: function(tests) {
// test integers
tests.f(dojox.validate.isInRange( '0', {min: 1, max: 100} ));
tests.t(dojox.validate.isInRange( '1', {min: 1, max: 100} ));
tests.f(dojox.validate.isInRange( '-50', {min: 1, max: 100} ));
tests.t(dojox.validate.isInRange( '+50', {min: 1, max: 100} ));
tests.t(dojox.validate.isInRange( '100', {min: 1, max: 100} ));
tests.f(dojox.validate.isInRange( '101', {min: 1, max: 100} ));
//test real numbers
tests.f(dojox.validate.isInRange( '0.9', {min: 1.0, max: 10.0} ));
tests.t(dojox.validate.isInRange( '1.0', {min: 1.0, max: 10.0} ));
tests.f(dojox.validate.isInRange( '-5.0', {min: 1.0, max: 10.0} ));
tests.t(dojox.validate.isInRange( '+5.50', {min: 1.0, max: 10.0} ));
tests.t(dojox.validate.isInRange( '10.0', {min: 1.0, max: 10.0} ));
tests.f(dojox.validate.isInRange( '10.1', {min: 1.0, max: 10.0} ));
tests.f(dojox.validate.isInRange( '5.566e28', {min: 5.567e28, max: 6.000e28} ));
tests.t(dojox.validate.isInRange( '5.7e28', {min: 5.567e28, max: 6.000e28} ));
tests.f(dojox.validate.isInRange( '6.00000001e28', {min: 5.567e28, max: 6.000e28} ));
tests.f(dojox.validate.isInRange( '10.000.000,12345e-5', {decimal: ",", max: 10000000.1e-5} ));
tests.f(dojox.validate.isInRange( '10.000.000,12345e-5', {decimal: ",", min: 10000000.2e-5} ));
tests.t(dojox.validate.isInRange('1,500,000', {separator: ',', min: 0}));
tests.f(dojox.validate.isInRange('1,500,000', {separator: ',', min: 1000, max: 20000}));
// test currency
tests.f(dojox.validate.isInRange('\u20AC123,456,789', {max: 123456788, symbol: '\u20AC'} ));
tests.f(dojox.validate.isInRange('\u20AC123,456,789', { min: 123456790, symbol: '\u20AC'} ));
tests.f(dojox.validate.isInRange('$123,456,789.07', { max: 123456789.06} ));
tests.f(dojox.validate.isInRange('$123,456,789.07', { min: 123456789.08} ));
tests.f(dojox.validate.isInRange('123.456.789,00 \u20AC', {max: 123456788, decimal: ",", symbol: '\u20AC'} ));
tests.f(dojox.validate.isInRange('123.456.789,00 \u20AC', {min: 123456790, decimal: ",", symbol: '\u20AC'} ));
tests.f(dojox.validate.isInRange('- T123 456 789-00', {decimal: "-", min:0} ));
tests.t(dojox.validate.isInRange('\u20AC123,456,789', { max: 123456790, symbol: '\u20AC'} ));
tests.t(dojox.validate.isInRange('$123,456,789.07', { min: 123456789.06} ));
// test non number
//tests.f("test25", dojox.validate.isInRange( 'a'));
}
},
{
name: "isUsPhoneNumber",
runTests: function(tests) {
tests.t(dojox.validate.us.isPhoneNumber('(111) 111-1111'));
tests.t(dojox.validate.us.isPhoneNumber('(111) 111 1111'));
tests.t(dojox.validate.us.isPhoneNumber('111 111 1111'));
tests.t(dojox.validate.us.isPhoneNumber('111.111.1111'));
tests.t(dojox.validate.us.isPhoneNumber('111-111-1111'));
tests.t(dojox.validate.us.isPhoneNumber('111/111-1111'));
tests.f(dojox.validate.us.isPhoneNumber('111 111-1111'));
tests.f(dojox.validate.us.isPhoneNumber('111-1111'));
tests.f(dojox.validate.us.isPhoneNumber('(111)-111-1111'));
// test extensions
tests.t(dojox.validate.us.isPhoneNumber('111-111-1111 x1'));
tests.t(dojox.validate.us.isPhoneNumber('111-111-1111 x12'));
tests.t(dojox.validate.us.isPhoneNumber('111-111-1111 x1234'));
}
},
{
name:"isUsSocialSecurityNumber",
runtests: function(tests) {
tests.t(dojox.validate.us.isSocialSecurityNumber('123-45-6789'));
tests.t(dojox.validate.us.isSocialSecurityNumber('123 45 6789'));
tests.t(dojox.validate.us.isSocialSecurityNumber('123456789'));
tests.f(dojox.validate.us.isSocialSecurityNumber('123-45 6789'));
tests.f(dojox.validate.us.isSocialSecurityNumber('12345 6789'));
tests.f(dojox.validate.us.isSocialSecurityNumber('123-456789'));
}
},
{
name:"isUsZipCode",
runtests: function(tests) {
tests.t(dojox.validate.us.isZipCode('12345-6789'));
tests.t(dojox.validate.us.isZipCode('12345 6789'));
tests.t(dojox.validate.us.isZipCode('123456789'));
tests.t(dojox.validate.us.isZipCode('12345'));
}
},
{
name:"isCaZipCode",
runtests: function(tests) {
tests.t(dojox.validate.ca.isPostalCode('A1Z 3F3'));
tests.f(dojox.validate.ca.isPostalCode('1AZ 3F3'));
tests.t(dojox.validate.ca.isPostalCode('a1z 3f3'));
tests.f(dojox.validate.ca.isPostalCode('xxxxxx'));
tests.t(dojox.validate.ca.isPostalCode('A1Z3F3'));
}
},
{
name:"isUsState",
runtests: function(tests) {
tests.t(dojox.validate.us.isState('CA'));
tests.t(dojox.validate.us.isState('ne'));
tests.t(dojox.validate.us.isState('PR'));
tests.f(dojox.validate.us.isState('PR', {allowTerritories: false} ));
tests.t(dojox.validate.us.isState('AA'));
tests.f(dojox.validate.us.isState('AA', {allowMilitary: false} ));
}
},
{
name:"formCheck",
runtests: function(tests) {
var f = {
// textboxes
tx1: {type: "text", value: " 1001 ", name: "tx1"},
tx2: {type: "text", value: " x", name: "tx2"},
tx3: {type: "text", value: "10/19/2005", name: "tx3"},
tx4: {type: "text", value: "10/19/2005", name: "tx4"},
tx5: {type: "text", value: "Foo@Localhost", name: "tx5"},
tx6: {type: "text", value: "Foo@Localhost", name: "tx6"},
tx7: {type: "text", value: "<Foo@Gmail.Com>", name: "tx7"},
tx8: {type: "text", value: " ", name: "tx8"},
tx9: {type: "text", value: "ca", name: "tx9"},
tx10: {type: "text", value: "homer SIMPSON", name: "tx10"},
tx11: {type: "text", value: "$1,000,000 (US)", name: "tx11"},
tx12: {type: "text", value: "as12.a13", name: "tx12"},
tx13: {type: "text", value: "4.13", name: "tx13"},
tx14: {type: "text", value: "15.681", name: "tx14"},
tx15: {value: "1", name: "tx15"},
cc_no: {type: "text", value: "5434 1111 1111 1111", name: "cc_no"},
cc_exp: {type: "text", value: "", name: "cc_exp"},
cc_type: {type: "text", value: "Visa", name: "cc_type"},
email: {type: "text", value: "foo@gmail.com", name: "email"},
email_confirm: {type: "text", value: "foo2@gmail.com", name: "email_confirm"},
// password
pw1: {type: "password", value: "123456", name: "pw1"},
pw2: {type: "password", value: "123456", name: "pw2"},
// textarea - they have a type property, even though no html attribute
ta1: {type: "textarea", value: "", name: "ta1"},
ta2: {type: "textarea", value: "", name: "ta2"},
// radio button groups
rb1: [
{type: "radio", value: "v0", name: "rb1", checked: false},
{type: "radio", value: "v1", name: "rb1", checked: false},
{type: "radio", value: "v2", name: "rb1", checked: true}
],
rb2: [
{type: "radio", value: "v0", name: "rb2", checked: false},
{type: "radio", value: "v1", name: "rb2", checked: false},
{type: "radio", value: "v2", name: "rb2", checked: false}
],
rb3: [
{type: "radio", value: "v0", name: "rb3", checked: false},
{type: "radio", value: "v1", name: "rb3", checked: false},
{type: "radio", value: "v2", name: "rb3", checked: false}
],
// checkboxes
cb1: {type: "checkbox", value: "cb1", name: "cb1", checked: false},
cb2: {type: "checkbox", value: "cb2", name: "cb2", checked: false},
// checkbox group with the same name
cb3: [
{type: "checkbox", value: "v0", name: "cb3", checked: false},
{type: "checkbox", value: "v1", name: "cb3", checked: false},
{type: "checkbox", value: "v2", name: "cb3", checked: false}
],
doubledip: [
{type: "checkbox", value: "vanilla", name: "doubledip", checked: false},
{type: "checkbox", value: "chocolate", name: "doubledip", checked: false},
{type: "checkbox", value: "chocolate chip", name: "doubledip", checked: false},
{type: "checkbox", value: "lemon custard", name: "doubledip", checked: true},
{type: "checkbox", value: "pistachio almond", name: "doubledip", checked: false}
],
// <select>
s1: {
type: "select-one",
name: "s1",
selectedIndex: -1,
options: [
{text: "option 1", value: "v0", selected: false},
{text: "option 2", value: "v1", selected: false},
{text: "option 3", value: "v2", selected: false}
]
},
// <select multiple>
s2: {
type: "select-multiple",
name: "s2",
selectedIndex: 1,
options: [
{text: "option 1", value: "v0", selected: false},
{text: "option 2", value: "v1", selected: true},
{text: "option 3", value: "v2", selected: true}
]
},
tripledip: {
type: "select-multiple",
name: "tripledip",
selectedIndex: 3,
options: [
{text: "option 1", value: "vanilla", selected: false},
{text: "option 2", value: "chocolate", selected: false},
{text: "option 3", value: "chocolate chip", selected: false},
{text: "option 4", value: "lemon custard", selected: true},
{text: "option 5", value: "pistachio almond", selected: true},
{text: "option 6", value: "mocha almond chip", selected: false}
]
},
doublea: {
type: "select-multiple",
name: "doublea",
selectedIndex: 2,
options: [
{text: "option 1", value: "vanilla", selected: false},
{text: "option 2", value: "chocolate", selected: true},
{text: "option 3", value: "", selected: true}
]
},
// <select> null selection
s3: {
type: "select-one",
name: "s3",
selectedIndex: 0,
options: [
{text: "option 1", value: "", selected: true},
{text: "option 2", value: "v1", selected: false},
{text: "option 3", value: "v2", selected: false}
]
},
selectAlien: {
name: "selectAlien",
multiple: "multiple",
id: "selectAlient",
size: "10",
length: 0,
options: [],
value:[]
}
};
// Profile for form input
var profile = {
// filters
trim: ["tx1", "tx2"],
uppercase: ["tx9"],
lowercase: ["tx5", "tx6", "tx7"],
ucfirst: ["tx10"],
digit: ["tx11"],
// required fields
required: ["tx2", "tx3", "tx4", "tx5", "tx6", "tx7", "tx8", "tx15", "pw1", "ta1", "rb1", "rb2",
"cb3", "s1", "s2", "s3",
{"doubledip":2}, {"tripledip":3}, {"doublea":2} ],
// dependant/conditional fields
dependencies: {
cc_exp: "cc_no",
cc_type: "cc_no"
},
// validated fields
constraints: {
tx1: dojox.validate.isInteger,
tx2: dojox.validate.isInteger,
tx3: [dojo.date.parse, {locale: 'en-us'}],
tx4: [dojo.date.parse, {locale: 'fr-fr'}],
tx5: [dojox.validate.isEmailAddress],
tx6: [dojox.validate.isEmailAddress, {allowLocal: true}],
tx7: [dojox.validate.isEmailAddress, {allowCruft: true}],
tx8: dojox.validate.isURL,
tx12: [[dojox.validate.isRealNumber],[dojox.validate.isInRange, {max:100.00,min:5.0}]],
tx13: [[dojox.validate.isRealNumber],[dojox.validate.isInRange, {max:100.00,min:5.0}]],
tx14: [[dojox.validate.isRealNumber],[dojox.validate.isInRange, {max:100.00,min:5.0}]]
},
// confirm fields
confirm: {
email_confirm: "email",
pw2: "pw1"
}
};
// results object
var results = dojox.validate.check(f, profile);
// test filter stuff
tests.asserEquals("1001", f.tx1.value );
tests.asserEquals("x", f.tx2.value );
tests.asserEquals("CA", f.tx9.value );
tests.asserEquals("foo@localhost", f.tx5.value );
tests.asserEquals("foo@localhost", f.tx6.value );
tests.asserEquals("<foo@gmail.com>", f.tx7.value );
tests.asserEquals("Homer Simpson", f.tx10.value );
tests.asserEquals("1000000", f.tx11.value );
// test missing stuff
tests.f(results.isSuccessful() );
tests.t(results.hasMissing() );
tests.f(results.isMissing("tx1") );
tests.f(results.isMissing("tx2") );
tests.f(results.isMissing("tx3") );
tests.f(results.isMissing("tx4") );
tests.f(results.isMissing("tx5") );
tests.f(results.isMissing("tx6") );
tests.f(results.isMissing("tx7") );
tests.t(results.isMissing("tx8") );
tests.f(results.isMissing("pw1") );
tests.f(results.isMissing("pw2") );
tests.t(results.isMissing("ta1") );
tests.f(results.isMissing("ta2") );
tests.f(results.isMissing("rb1") );
tests.t(results.isMissing("rb2") );
tests.f(results.isMissing("rb3") );
tests.t(results.isMissing("cb3") );
tests.t(results.isMissing("s1") );
tests.f(results.isMissing("s2") );
tests.t(results.isMissing("s3"));
tests.t(results.isMissing("doubledip") );
tests.t(results.isMissing("tripledip") );
tests.t(results.isMissing("doublea"));
tests.f(results.isMissing("cc_no") );
tests.t(results.isMissing("cc_exp") );
tests.f(results.isMissing("cc_type") );
// missing: tx8, ta1, rb2, cb3, s1, s3, doubledip, tripledip, cc_exp
tests.asserEquals(10, results.getMissing().length );
// test constraint stuff
tests.t(results.hasInvalid() );
tests.f(results.isInvalid("tx1") );
tests.t(results.isInvalid("tx2") );
tests.f(results.isInvalid("tx3") );
tests.t(results.isInvalid("tx4") );
tests.t(results.isInvalid("tx5") );
tests.f(results.isInvalid("tx6") );
tests.f(results.isInvalid("tx7") );
tests.f(results.isInvalid("tx8") );
tests.f(results.isInvalid("pw1") );
tests.f(results.isInvalid("pw2") );
tests.f(results.isInvalid("ta1") );
tests.f(results.isInvalid("ta2") );
tests.f(results.isInvalid("email") );
tests.t(results.isInvalid("email_confirm") );
// invlaid: txt2, txt4, txt5, email_confirm, selectAlien
tests.asserEquals(7, results.getInvalid().length);
tests.t(results.isInvalid("tx12"));
tests.t(results.isInvalid("tx13"));
tests.f(results.isInvalid("tx14"));
tests.t(results.isInvalid("selectAlien"));
}
}
]);
 
}
/trunk/api/js/dojo1.0/dojox/validate/tests/runTests.html
New file
0,0 → 1,9
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Dijit Unit Test Runner</title>
<meta http-equiv="REFRESH" content="0;url=../../../util/doh/runner.html?testModule=dojox.validate.tests.module"></HEAD>
<BODY>
Redirecting to D.O.H runner.
</BODY>
</HTML>