Handle bad dates in datetime related form plugins. Fixes bug #11128
Also, better date parsing by _splitMysql and reformat Thingy.
This commit is contained in:
parent
c327630771
commit
7866120459
8 changed files with 100 additions and 72 deletions
11
t/DateTime.t
11
t/DateTime.t
|
|
@ -26,7 +26,7 @@ my $session = WebGUI::Test->session;
|
|||
|
||||
# put your tests here
|
||||
|
||||
plan tests => 25;
|
||||
plan tests => 28;
|
||||
|
||||
my $timeZoneUser = addUser($session);
|
||||
|
||||
|
|
@ -84,6 +84,13 @@ is(
|
|||
'... has correct epoch'
|
||||
);
|
||||
|
||||
my $badday = eval { WebGUI::DateTime->new($session, '2001-08-161'); };
|
||||
ok($@, 'new croaks on a bad date');
|
||||
my $badday = eval { WebGUI::DateTime->new($session, '2001-08-16 99:99:99'); };
|
||||
ok($@, 'new croaks on an out of range time');
|
||||
my $badday = eval { WebGUI::DateTime->new($session, '2001-08-16 99:199:99'); };
|
||||
ok($@, 'new croaks on an illegal time');
|
||||
|
||||
sub addUser {
|
||||
my $session = shift;
|
||||
my $user = WebGUI::User->new($session, "new");
|
||||
|
|
@ -92,6 +99,6 @@ sub addUser {
|
|||
##so the test will not fail in the summer
|
||||
$user->profileField("timeZone","America/Hermosillo");
|
||||
$user->username("Time Zone");
|
||||
WebGUI::Test->usersToDelete($user);
|
||||
addToCleanup($user);
|
||||
return $user;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ my $testBlock = [
|
|||
|
||||
my $formType = 'date';
|
||||
|
||||
my $numTests = 25 + scalar @{ $testBlock } ;
|
||||
my $numTests = 26 + scalar @{ $testBlock } ;
|
||||
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -141,6 +141,14 @@ is(
|
|||
'2008-08-01',
|
||||
"toHtml: defaultValue in epoch format, returns date in mysql format"
|
||||
);
|
||||
|
||||
$date2 = WebGUI::Form::Date->new($session, {defaultValue => '2008-008-001'});
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtml),
|
||||
'1970-01-01',
|
||||
"toHtml: defaultValue in bad mysql format returns date from epoch 0"
|
||||
);
|
||||
|
||||
$date2 = WebGUI::Form::Date->new($session, {defaultValue => -1});
|
||||
is($date2->getValueAsHtml(), '12/31/1969', "getValueAsHtml: defaultValue as negative epoch, returns in users's format");
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ my $session = WebGUI::Test->session;
|
|||
|
||||
my $formType = 'datetime';
|
||||
|
||||
my $numTests = 34;
|
||||
my $numTests = 35;
|
||||
|
||||
plan tests => $numTests;
|
||||
|
||||
|
|
@ -182,6 +182,12 @@ is(
|
|||
'2001-08-16 08:00:00',
|
||||
"toHtml: defaultValue in mysql format, value as mysql returns date in mysql format, adjusted for time zone"
|
||||
);
|
||||
$date2 = WebGUI::Form::DateTime->new($session, {defaultValue => '2008-081-01 11:34:26',});
|
||||
is(
|
||||
getValueFromForm($session, $date2->toHtml),
|
||||
'1969-12-31 18:00:00',
|
||||
"toHtml: defaultValue in bad mysql format, returns value from epoch 0, adjusted for user time zone"
|
||||
);
|
||||
|
||||
sub getValueFromForm {
|
||||
my ($session, $textForm) = @_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue