Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

actually add t/compound/empty.t

  • Loading branch information...
commit 761b3809e5f831244c4a2330569e596da3e46e49 1 parent f2111a2
Gerda Shank authored
Showing with 77 additions and 0 deletions.
  1. +77 −0 t/compound/empty.t
77 t/compound/empty.t
View
@@ -0,0 +1,77 @@
+use strict;
+use warnings;
+use Test::More;
+use Data::Printer;
+
+# tests behavior for an empty compound field, where the compund field value
+# is undef
+{
+ {
+ package MyApp::Test::Compound;
+ use HTML::FormHandler::Moose;
+ extends 'HTML::FormHandler';
+
+ has_field 'comp_foo' => ( type => 'Compound', default => { one => 1, two => 2, three => 3 } );
+ has_field 'comp_foo.one';
+ has_field 'comp_foo.two';
+ has_field 'comp_foo.three';
+ has_field 'bar';
+ }
+
+ my $form = MyApp::Test::Compound->new;
+ ok( $form );
+ my $params = {
+ 'comp_foo.one' => '',
+ 'comp_foo.two' => '',
+ 'comp_foo.three' => '',
+ 'bar' => 'my_bar',
+ };
+ $form->process( params => $params );
+ my $value = $form->value;
+ diag(p($value));
+ my $exp_value = {
+ comp_foo => undef,
+ bar => 'my_bar',
+ };
+ is_deeply( $value, $exp_value, 'got expected value' );
+}
+
+# tests behavior for an empty compound field with 'not_nullable', where the
+# compund field contains empty values
+{
+ {
+ package MyApp::Test::Compound;
+ use HTML::FormHandler::Moose;
+ extends 'HTML::FormHandler';
+
+ has_field 'comp_foo' => ( type => 'Compound', not_nullable => 1 );
+ has_field 'comp_foo.one';
+ has_field 'comp_foo.two';
+ has_field 'comp_foo.three';
+ has_field 'bar';
+ }
+
+ my $form = MyApp::Test::Compound->new;
+ ok( $form );
+ my $params = {
+ 'comp_foo.one' => '',
+ 'comp_foo.two' => '',
+ 'comp_foo.three' => '',
+ 'bar' => 'my_bar',
+ };
+$DB::single=1;
+ $form->process( params => $params );
+ my $value = $form->value;
+ my $exp_value = {
+ comp_foo => {
+ one => undef,
+ two => undef,
+ three => undef,
+ },
+ bar => 'my_bar',
+ };
+ is_deeply( $value, $exp_value, 'got expected value' );
+}
+
+
+done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.