From 536ac6cdc7612d15c688dbd3e28072cc05c15004 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 1 Oct 2009 13:04:58 -0700 Subject: [PATCH] Fix bugs in how Thingy handles displaying dates to the user in view and search modes. --- lib/WebGUI/Asset/Wobject/Thingy.pm | 4 +- t/Asset/Wobject/Thingy.t | 69 ++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 25 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index 733ca8098..618294733 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -892,10 +892,10 @@ sub getFieldValue { my $processedValue = $value; my $dbh = $self->session->db->dbh; - if ($field->{fieldType} eq "date"){ + if (lc $field->{fieldType} eq "date"){ $processedValue = $self->session->datetime->epochToHuman($value,$dateFormat); } - elsif ($field->{fieldType} eq "dateTime"){ + elsif (lc $field->{fieldType} eq "datetime"){ $processedValue = $self->session->datetime->epochToHuman($value,$dateTimeFormat); } # TODO: The otherThing field type is probably also handled by getFormPlugin, so the elsif below can probably be diff --git a/t/Asset/Wobject/Thingy.t b/t/Asset/Wobject/Thingy.t index e13b38123..0844c2b77 100644 --- a/t/Asset/Wobject/Thingy.t +++ b/t/Asset/Wobject/Thingy.t @@ -16,7 +16,7 @@ use lib "$FindBin::Bin/../../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 26; # increment this value for each test you create +use Test::More tests => 28; # increment this value for each test you create use Test::Deep; use JSON; use WebGUI::Asset::Wobject::Thingy; @@ -373,28 +373,51 @@ is($table, undef, '... drops thing specific table'); # ################################################################# -%otherThingProperties = %thingProperties; -$otherThingProperties{'groupIdView'} = 3; -$otherThingId = $thingy->addThing(\%otherThingProperties, 0); -%otherFieldProperties = %fieldProperties; -$otherFieldProperties{thingId} = $otherThingId; -$otherFieldId = $thingy->addField(\%otherFieldProperties, 0); -$thingy->editThingDataSave($otherThingId, 'new', {"field_".$otherFieldId => 'value 1'} ); -$thingy->editThingDataSave($otherThingId, 'new', {"field_".$otherFieldId => 'value 2'} ); -$thingy->editThingDataSave($otherThingId, 'new', {"field_".$otherFieldId => 'value 3'} ); +{ + my %newThingProperties = %thingProperties; + $newThingProperties{'groupIdView'} = 3; + my $newThingId = $thingy->addThing(\%newThingProperties, 0); + my %newFieldProperties = %fieldProperties; + $newFieldProperties{thingId} = $newThingId; + my $newFieldId = $thingy->addField(\%newFieldProperties, 0); + $thingy->editThingDataSave($newThingId, 'new', {"field_".$newFieldId => 'value 1'} ); + $thingy->editThingDataSave($newThingId, 'new', {"field_".$newFieldId => 'value 2'} ); + $thingy->editThingDataSave($newThingId, 'new', {"field_".$newFieldId => 'value 3'} ); -my $andy = WebGUI::User->create($session); -WebGUI::Test->usersToDelete($andy); -$session->user({userId => $andy->userId}); + my $andy = WebGUI::User->create($session); + WebGUI::Test->usersToDelete($andy); + $session->user({userId => $andy->userId}); -my $form = $thingy->getFormPlugin({ - name => 'fakeFormForTesting', - fieldType => 'otherThing_'.$otherThingId, - fieldInOtherThingId => $otherFieldId, -}); + my $form = $thingy->getFormPlugin({ + name => 'fakeFormForTesting', + fieldType => 'otherThing_'.$newThingId, + fieldInOtherThingId => $newFieldId, + }); + + cmp_deeply( + $form->get('options'), + {}, + 'getFormPlugin: form has no data since the user does not have viewing privileges' + ); +} + +################################################################# +# +# getFieldValue +# +################################################################# +{ + my %newThingProperties = %thingProperties; + my $newThingId = $thingy->addThing(\%newThingProperties, 0); + my %newFieldProperties = %fieldProperties; + $newFieldProperties{thingId} = $newThingId; + $newFieldProperties{fieldType} = 'Date'; + + my $date = $thingy->getFieldValue(WebGUI::Test->webguiBirthday, \%newFieldProperties); + like($date, qr{\d+/\d+/\d+}, "getFieldValue: Date field type returns data in user's format"); + + $newFieldProperties{fieldType} = 'DateTime'; + my $datetime = $thingy->getFieldValue(WebGUI::Test->webguiBirthday, \%newFieldProperties); + like($datetime, qr{^\d+/\d+/\d+\s+\d+:\d+}, "... DateTime field also returns data in user's format"); +} -cmp_deeply( - $form->get('options'), - {}, - 'getFormPlugin: form has no data since the user does not have viewing privileges' -);