From f4d19c41f7652645d80d4c988552530c6b0d5363 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 16 Sep 2009 19:19:46 -0700 Subject: [PATCH] DataForms logs an error when it cannot load the requested form type. Fixes bug #10954. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Wobject/DataForm.pm | 26 ++++++------ t/Asset/Wobject/DataForm.t | 63 ++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 t/Asset/Wobject/DataForm.t diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index ae16c0b54..559f1e0b5 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -45,6 +45,7 @@ - fixed #10987: EMS Schedule -- No Permission Check - fixed #10924: Calendar event in last day of month does not display in month/day view - fixed #10901: Calendar More Button/Display Box IE8 error. + - fixed #10954: DataForm fails silently 7.7.19 - fixed #10838: Forwarded forum post email to new CS adds reply to original thread diff --git a/lib/WebGUI/Asset/Wobject/DataForm.pm b/lib/WebGUI/Asset/Wobject/DataForm.pm index d6d2f9fe9..a20543a72 100644 --- a/lib/WebGUI/Asset/Wobject/DataForm.pm +++ b/lib/WebGUI/Asset/Wobject/DataForm.pm @@ -51,22 +51,24 @@ These methods are available from this class: #------------------------------------------------------------------- sub _createForm { - my $self = shift; - my $data = shift; - my $value = shift; + my $self = shift; + my $data = shift; + my $value = shift; + my $session = $self->session; # copy select entries - my %param = map { $_ => $data->{$_} } qw(name width extras vertical defaultValue options); - $param{value} = $value; - $param{size} = $param{width}; + my %param = map { $_ => $data->{$_} } qw(name width extras vertical defaultValue options); + $param{value} = $value; + $param{size} = $param{width}; $param{height} = $data->{rows}; - WebGUI::Macro::process($self->session, \( $param{defaultValue} )); + WebGUI::Macro::process($session, \( $param{defaultValue} )); - my $type = "\u$data->{type}"; + my $type = ucfirst $data->{type}; my $class = "WebGUI::Form::$type"; - eval { - WebGUI::Pluggable::load("WebGUI::Form::$type"); - } || return undef; + if (! eval { WebGUI::Pluggable::load("WebGUI::Form::$type"); } ) { + $session->log->error( "Unable to load form control - $type" ); + return undef; + } if ($type eq "Checkbox") { $param{defaultValue} = ($param{defaultValue} =~ /checked/i); } @@ -76,7 +78,7 @@ sub _createForm { elsif ( $type eq 'HTMLArea' && $data->{htmlAreaRichEditor} ne '**Use_Default_Editor**') { $param{richEditId} = $data->{htmlAreaRichEditor} ; } - return $class->new($self->session, \%param); + return $class->new($session, \%param); } #------------------------------------------------------------------- diff --git a/t/Asset/Wobject/DataForm.t b/t/Asset/Wobject/DataForm.t new file mode 100644 index 000000000..e268db0b5 --- /dev/null +++ b/t/Asset/Wobject/DataForm.t @@ -0,0 +1,63 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------ +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------ + +# This tests the moveField functions of the DataForm +# +# + +use FindBin; +use strict; +use lib "$FindBin::Bin/../../lib"; +use Test::More; +use Test::Deep; +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Asset; +use WebGUI::Asset::Wobject::DataForm; +use WebGUI::VersionTag; +use WebGUI::Session; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + +# Create a DataForm +my $df = WebGUI::Asset->getImportNode( $session ) + ->addChild( { + className => "WebGUI::Asset::Wobject::DataForm", + mailData => 0, + fieldConfiguration => '[]', + } ); + +my $versionTag = WebGUI::VersionTag->getWorking($session); +WebGUI::Test->tagsToRollback($versionTag); +$versionTag->commit; + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 1; # Increment this number for each test you create + +#---------------------------------------------------------------------------- +# _createForm + +WebGUI::Test->interceptLogging; + +$df->_createForm( + { + name => 'test field', + type => 'MASSIVE FORM FAILURE', + }, + 'some value' +); + +is($WebGUI::Test::logger_error, "Unable to load form control - MASSIVE FORM FAILURE", '_createForm logs when it cannot load a form type'); + +#vim:ft=perl