|
| 1 | +/** |
| 2 | + * ******************************************************************************* |
| 3 | + * ******************************************************************************* |
| 4 | + */ |
| 5 | +component extends="coldbox.system.testing.BaseModelTest" model="cbvalidation.models.validators.EmptyValidator" { |
| 6 | + |
| 7 | + function beforeAll(){ |
| 8 | + super.beforeAll(); |
| 9 | + super.setup(); |
| 10 | + model.init(); |
| 11 | + } |
| 12 | + |
| 13 | + function run(){ |
| 14 | + describe( "empty validator", function(){ |
| 15 | + beforeEach( function(){ |
| 16 | + variables.result = createMock( "cbvalidation.models.result.ValidationResult" ).init(); |
| 17 | + } ); |
| 18 | + |
| 19 | + it( "skips over null values", function(){ |
| 20 | + expect( |
| 21 | + model.validate( |
| 22 | + variables.result, |
| 23 | + this, |
| 24 | + "test", |
| 25 | + javacast( "null", "" ), |
| 26 | + true |
| 27 | + ) |
| 28 | + ).toBeTrue(); |
| 29 | + } ); |
| 30 | + |
| 31 | + describe( "empty: true", function(){ |
| 32 | + it( "passes when given an empty string", function(){ |
| 33 | + expect( model.validate( variables.result, this, "test", "", true ) ).toBeTrue(); |
| 34 | + } ); |
| 35 | + |
| 36 | + it( "passes when given an empty array", function(){ |
| 37 | + expect( model.validate( variables.result, this, "test", [], true ) ).toBeTrue(); |
| 38 | + } ); |
| 39 | + |
| 40 | + it( "passes when given an empty struct", function(){ |
| 41 | + expect( model.validate( variables.result, this, "test", {}, true ) ).toBeTrue(); |
| 42 | + } ); |
| 43 | + |
| 44 | + it( "fails when given a non-empty string", function(){ |
| 45 | + expect( model.validate( result, this, "test", "woot", true ) ).toBeFalse(); |
| 46 | + } ); |
| 47 | + |
| 48 | + it( "fails when given a number", function(){ |
| 49 | + expect( model.validate( result, this, "test", 42.155, true ) ).toBeFalse(); |
| 50 | + } ); |
| 51 | + |
| 52 | + it( "fails when given a date", function(){ |
| 53 | + expect( model.validate( result, this, "test", now(), true ) ).toBeFalse(); |
| 54 | + } ); |
| 55 | + |
| 56 | + it( "fails when given a non-empty array", function(){ |
| 57 | + expect( model.validate( variables.result, this, "test", [ 1 ], true ) ).toBeFalse(); |
| 58 | + } ); |
| 59 | + |
| 60 | + it( "fails when given a non-empty struct", function(){ |
| 61 | + expect( |
| 62 | + model.validate( |
| 63 | + variables.result, |
| 64 | + this, |
| 65 | + "test", |
| 66 | + { "foo" : "bar" }, |
| 67 | + true |
| 68 | + ) |
| 69 | + ).toBeFalse(); |
| 70 | + } ); |
| 71 | + } ); |
| 72 | + |
| 73 | + describe( "empty: false", function(){ |
| 74 | + it( "fails when given an empty string", function(){ |
| 75 | + expect( model.validate( variables.result, this, "test", "", false ) ).toBeFalse(); |
| 76 | + } ); |
| 77 | + |
| 78 | + it( "fails when given an empty array", function(){ |
| 79 | + expect( model.validate( variables.result, this, "test", [], false ) ).toBeFalse(); |
| 80 | + } ); |
| 81 | + |
| 82 | + it( "fails when given an empty struct", function(){ |
| 83 | + expect( model.validate( variables.result, this, "test", {}, false ) ).toBeFalse(); |
| 84 | + } ); |
| 85 | + } ); |
| 86 | + } ); |
| 87 | + } |
| 88 | + |
| 89 | +} |
0 commit comments