my
$form
= Spark::Form->new(
plugin_ns
=>
'TestApp::Form::Field'
);
is_deeply([
$form
->fields], [],
"Fields are not yet populated"
);
$form
->add(
'custom'
,
'gt6'
,
min_length
=> 6);
cmp_ok(
scalar
$form
->fields,
'=='
, 1,
"Custom field 1 added"
);
$form
->add(
'custom'
,
'gt2'
,
min_length
=> 2);
cmp_ok(
scalar
$form
->fields,
'=='
, 2,
"Custom field 2 added"
);
my
%data
= (
gt6
=>
'1'
,
gt2
=>
'1'
,
);
$form
->data(\
%data
);
$form
->validate;
cmp_ok(
$form
->valid,
'=='
, 0,
"Dataset 1 is invalid"
);
cmp_ok(
scalar
$form
->errors,
'=='
, 2,
"Dataset 1 has 2 errors"
);
%data
= (
gt6
=>
'12'
,
gt2
=>
'12'
,
);
$form
->data(\
%data
);
$form
->validate;
cmp_ok(
$form
->valid,
'=='
, 0,
"Dataset 2 is invalid"
);
cmp_ok(
scalar
$form
->errors,
'=='
, 1,
"Dataset 2 has 1 error"
);
%data
= (
gt6
=>
'123456'
,
gt2
=>
'12'
,
);
$form
->data(\
%data
);
$form
->validate;
cmp_ok(
$form
->valid,
'=='
, 1,
"Dataset 3 is valid"
);
is_deeply([
$form
->errors], [],
"Dataset 3 has no errors"
);