forked from jayk/Form-Sensible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of vc.ionzero.com:FormSensible
- Loading branch information
Showing
5 changed files
with
137 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package MockReflector; | ||
use Moose; | ||
use namespace::autoclean; | ||
extends 'Form::Sensible::Reflector'; | ||
|
||
sub get_field_names { | ||
return qw/ field1 field2 field3 /; | ||
} | ||
|
||
sub get_all_field_definitions { | ||
return ( | ||
{ | ||
field_class => 'Text', | ||
name => 'field1', | ||
validation => { | ||
regex => qr/^(.+){3,}$/ | ||
}, | ||
}, | ||
{ | ||
field_class => 'FileSelector', | ||
name => 'field2', | ||
validation => {}, # wtf do we validate here? | ||
}, | ||
{ | ||
field_class => 'Text', | ||
name => 'field3', | ||
validation => { | ||
regex => qr/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/, | ||
}, | ||
}, | ||
); | ||
} | ||
|
||
sub create_form_object { | ||
my ( $self, $handle, $form_options ) = @_; | ||
|
||
return Form::Sensible::Form->new(name => "test"); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Form::Sensible; | ||
use FindBin; | ||
use lib "$FindBin::Bin/../lib"; | ||
use lib "t/lib"; | ||
use MockReflector; | ||
use Data::Dumper; | ||
|
||
my $reflector = MockReflector->new( with_trigger => 1 ); | ||
my $form = $reflector->reflect_from( undef, { form => { name => 'test' } } ); | ||
my $reflector_without_submit = MockReflector->new(); | ||
my $form_without_submit = | ||
$reflector_without_submit->reflect_from( undef, | ||
{ form => { name => 'test' } } ); | ||
|
||
my $expected_without_submit = Form::Sensible->create_form( | ||
{ | ||
name => "test", | ||
fields => [ | ||
{ | ||
field_class => 'Text', | ||
name => 'field1', | ||
validation => { regex => qr/^(.+){3,}$/ }, | ||
}, | ||
{ | ||
field_class => 'FileSelector', | ||
name => 'field2', | ||
validation => {}, # wtf do we validate here? | ||
}, | ||
{ | ||
field_class => 'Text', | ||
name => 'field3', | ||
validation => { | ||
regex => | ||
qr/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/, | ||
}, | ||
}, | ||
], | ||
} | ||
); | ||
|
||
my $expected = Form::Sensible->create_form( | ||
{ | ||
name => "test", | ||
fields => [ | ||
{ | ||
field_class => 'Text', | ||
name => 'field1', | ||
validation => { regex => qr/^(.+){3,}$/ }, | ||
}, | ||
{ | ||
field_class => 'FileSelector', | ||
name => 'field2', | ||
validation => {}, # wtf do we validate here? | ||
}, | ||
{ | ||
field_class => 'Text', | ||
name => 'field3', | ||
validation => { | ||
regex => | ||
qr/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/, | ||
}, | ||
}, | ||
{ | ||
field_class => 'Trigger', | ||
name => 'submit', | ||
} | ||
], | ||
} | ||
); | ||
is_deeply( $form, $expected, "forms compare correctly" ); | ||
is_deeply( $form_without_submit, $expected_without_submit, "forms compare correctly" ); | ||
done_testing(); |