From be8f582ac7ad90df80677ca47e93e7f17b852576 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 21 Jan 2010 18:08:41 -0800 Subject: [PATCH] Add tests for getFormProperties --- t/Definition.t | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/t/Definition.t b/t/Definition.t index 3c3504f26..287eb7c81 100644 --- a/t/Definition.t +++ b/t/Definition.t @@ -16,10 +16,12 @@ use lib "$FindBin::Bin/lib"; use WebGUI::Test; -use Test::More 'no_plan'; #tests => 1; +use Test::More tests => 10; use Test::Deep; use Test::Exception; +my $session = WebGUI::Test->session; + my $called_getProperties; { package WGT::Class; @@ -46,13 +48,6 @@ my $called_getProperties; ::can_ok +__PACKAGE__, 'get'; ::can_ok +__PACKAGE__, 'set'; - # can retreive property metadata - ::isa_ok +__PACKAGE__->getProperty('property1'), 'WebGUI::Definition::Meta::Property'; - - ::is +__PACKAGE__->getProperty('property1')->form->{'arbitrary_key'}, 'arbitrary_value', 'arbitrary keys mapped into the form attribute'; - - ::is +__PACKAGE__->getProperty('property2')->form->{'nother_key'}, 'nother_value', '... and again'; - ::cmp_deeply( [ +__PACKAGE__->getProperties ], [qw/property1 property2/], @@ -94,5 +89,41 @@ my $called_getProperties; @set_order = (); $object->set(property2 => 1, property3 => 0, property1 => 1); ::cmp_deeply( [ @set_order ], [3,1,2], '... and again'); + + ::cmp_deeply( + $object->getFormProperties('property1'), + { label => 'label' }, + 'getFormProperties works for a simple set of properties' + ); + } +{ + package WGT::Class3; + use WebGUI::Definition; + + attribute 'attribute1' => 'attribute1 value'; + property 'property1' => ( + label => ['webgui', 'WebGUI'], + options => \&property1_options, + ); + has session => ( + is => 'ro', + required => 1, + ); + sub property1_options { + return { one => 1, two => 2, three => 3 }; + } + + my $object = WGT::Class3->new({session => $session}); + + ::cmp_deeply( + $object->getFormProperties('property1'), + { + label => 'WebGUI', + options => { one => 1, two => 2, three => 3 }, + }, + 'getFormProperties handles i18n and subroutines' + ); + +}