Fix multiple Date and DateTime bugs. bug #11079 and bug #11071

This commit is contained in:
Colin Kuskie 2009-09-30 16:50:08 -07:00
parent ddc33b76bb
commit 25b4a0b139
6 changed files with 202 additions and 113 deletions

View file

@ -36,15 +36,21 @@ my $testBlock = [
},
{
key => 'Date2',
testValue => "2008-08-01 16:34:26",
expected => $session->datetime->setToEpoch("2008-08-01 16:34:26"),#must call this so that value is appropriate for testers timezone
testValue => "2008-08-01",
expected => $session->datetime->setToEpoch("2008-08-01"),#must call this so that value is appropriate for testers timezone
comment => 'MySQL formatted to epoch',
},
{
key => 'Date3',
testValue => '-1',
expected => '-1',
comment => 'negative epoch to negative epoch',
},
];
my $formType = 'date';
my $numTests = 16 + scalar @{ $testBlock } ;
my $numTests = 26 + scalar @{ $testBlock } ;
plan tests => $numTests;
@ -110,13 +116,50 @@ WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
#Dates to MySQL
my $date2 = WebGUI::Form::Date->new($session, {'defaultValue' => '2008-08-01 16:34:26'});
is($date2->getValue(1217608466), '2008-08-01 11:34:26', "Epoch to MySQL");
is($date2->getValue('2008-08-01 11:34:26'), '2008-08-01 11:34:26', "MySQL to MySQL");
my $date2;
$date2 = WebGUI::Form::Date->new($session, {'defaultValue' => '2008-08-01 16:34:26'});
is($date2->getValue(1217608466), '2008-08-01 11:34:26', "getValue, defaultValue MySQL format: Epoch to MySQL");
is($date2->getValue('2008-08-01'), '2008-08-01', "... MySQL to MySQL");
is($date2->getValue(-1), '1969-12-31 17:59:59', "... Negative epoch to MySQL");
my $date2 = WebGUI::Form::Date->new($session);
is($date2->getValue(1217608466), 1217608466, "Default Epoch to Epoch");
is($date2->getValue('2008-08-01 11:34:26'), 1217608466, "Default MySQL to Epoch");
$date2 = WebGUI::Form::Date->new($session);
is($date2->getValue(1217608466), 1217608466, "getValue, no default: Default Epoch to Epoch");
is($date2->getValue('2008-08-01'), 1217566800, "... Default MySQL to Epoch");
is($date2->getValue(-1), -1, "... Default negative epoch to negative epoch");
__END__
my $bday = WebGUI::Test->webguiBirthday;
$date2 = WebGUI::Form::Date->new($session);
is($date2->getValueAsHtml(), $session->datetime->epochToSet($date2->getDefaultValue), "getValueAsHtml: no defaultValue set, no value set, returns now in user's format");
$date2 = WebGUI::Form::Date->new($session, {defaultValue => 1217608466});
is($date2->getValueAsHtml(), '2008-08-01', "getValueAsHtml: defaultValue in epoch format, returns now in mysql format");
is(
getValueFromForm($session, $date2->toHtmlAsHidden),
'2008-08-01',
"toHtmlAsHidden: defaultValue in epoch format, returns date in mysql format"
);
is(
getValueFromForm($session, $date2->toHtml),
'2008-08-01',
"toHtml: defaultValue in epoch format, returns date in mysql format"
);
$date2 = WebGUI::Form::Date->new($session, {defaultValue => -1});
is($date2->getValueAsHtml(), '1969-12-31', "getValueAsHtml: defaultValue as negative epoch, returns in mysql format");
$date2 = WebGUI::Form::Date->new($session, {defaultValue => '2008-08-01'});
is($date2->getValueAsHtml(), '2008-08-01', "getValueAsHtml: defaultValue in mysql format, returns default value in mysql format");
$date2 = WebGUI::Form::Date->new($session, {defaultValue => '2008-08-01', value => $bday, });
is($date2->getValueAsHtml(), '2001-08-16', "getValueAsHtml: defaultValue in mysql format, value as epoch returns value in user's format");
$date2 = WebGUI::Form::Date->new($session, {defaultValue => '2008-08-01', value => '2001-08-16', });
is($date2->getValueAsHtml(), '2001-08-16', "getValueAsHtml: defaultValue in mysql format, value as mysql returns value in mysql format");
sub getValueFromForm {
my ($session, $textForm) = @_;
my ($header, $footer) = (WebGUI::Form::formHeader($session), WebGUI::Form::formFooter($session));
my @forms = HTML::Form->parse($header.$textForm.$footer, 'http://www.webgui.org');
my @inputs = $forms[0]->inputs;
return $inputs[1]->{value};
}

View file

@ -29,7 +29,7 @@ my $session = WebGUI::Test->session;
my $formType = 'datetime';
my $numTests = 15;
my $numTests = 34;
plan tests => $numTests;
@ -82,23 +82,111 @@ is($input->name, 'preDateValue', 'Checking input name');
is($input->{size}, 19, 'Checking size param, set');
is($input->{maxlength}, 19, 'Checking maxlength param, set');
##Test Form Output parsing
#Dates to Epoch
#WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);
#########################################
#
# getValue
#
#########################################
my $date1 = WebGUI::Form::DateTime->new($session, {'defaultValue' => time()});
$session->user->profileField( 'timeZone' , 'America/Chicago');
is($date1->getValue(1217608466), 1217608466, "Epoch to Epch");
is($date1->getValue('2008-08-01 16:34:26'), $session->datetime->setToEpoch("2008-08-01 16:34:26"), "MySQL to Epoch");
is($date1->getValue(1217608466), 1217608466, "getValue, defaultValue epoch: Epoch to Epch");
is($date1->getValue('2008-08-01 16:34:26'), 1217626466, "... MySQL to Epoch");
is($date1->getValue(-1), -1, "... negative epoch to epoch");
my $date2 = WebGUI::Form::DateTime->new($session);
is($date2->getValue(1217608466), 1217608466, "Default Epoch to Epch");
is($date2->getValue('2008-08-01 16:34:26'), $session->datetime->setToEpoch("2008-08-01 16:34:26"), "Default MySQL to Epoch");
is($date2->getValue(1217608466), 1217608466, "getValue, no default: Default Epoch to Epch");
is($date2->getValue('2008-08-01 16:34:26'), 1217626466, "... Default MySQL to Epoch");
is($date2->getValue(-1), -1, "... negative epoch to epoch");
#Dates to MySQL
my $date3 = WebGUI::Form::DateTime->new($session, {'defaultValue' => '2008-08-01 16:34:26'});
is($date3->getValue(1217608466), '2008-08-01 11:34:26', "Epoch to MySQL");
is($date3->getValue('2008-08-01 11:34:26'), '2008-08-01 16:34:26', "MySQL to MySQL");#UTC is 5 hours ahead of Chicago
is($date3->getValue(1217608466), '2008-08-01 11:34:26', "getValue, defaultValue is mysql, epoch to mySQL");
is($date3->getValue('2008-08-01 11:34:26'), '2008-08-01 16:34:26', "... MySQL to MySQL");#UTC is 5 hours ahead of Chicago
is($date3->getValue(-1), '1969-12-31 17:59:59', "... negative epoch to mysql");
__END__
#########################################
#
# getValueAsHtml
#
#########################################
my $bday = WebGUI::Test->webguiBirthday;
$date2 = WebGUI::Form::DateTime->new($session);
is($date2->getValueAsHtml(), $session->datetime->epochToHuman($date2->getDefaultValue,'%z %Z'), "getValueAsHtml: no defaultValue set, no value set, returns now in user's format");
$date2 = WebGUI::Form::DateTime->new($session, {defaultValue => 1217608466});
is($date2->getValueAsHtml(), '8/1/2008 11:34 am', "getValueAsHtml: defaultValue in epoch format, returns now in user's format");
is(
getValueFromForm($session, $date2->toHtmlAsHidden),
'2008-08-01 11:34:26',
"toHtmlAsHidden: defaultValue in mysql format, returns date in mysql format"
);
is(
getValueFromForm($session, $date2->toHtml),
'2008-08-01 11:34:26',
"toHtml: defaultValue in mysql format, returns date in mysql format"
);
$date2 = WebGUI::Form::DateTime->new($session, {defaultValue => -1});
is($date2->getValueAsHtml(), '12/31/1969 5:59 pm', "getValueAsHtml: defaultValue as negative epoch, returns as user's format");
is(
getValueFromForm($session, $date2->toHtmlAsHidden),
'1969-12-31 17:59:59',
"toHtmlAsHidden: defaultValue as negative epoch, returns date/time in mysql format"
);
is(
getValueFromForm($session, $date2->toHtml),
'1969-12-31 17:59:59',
"toHtml: defaultValue in mysql format, returns date in mysql format"
);
$date2 = WebGUI::Form::DateTime->new($session, {defaultValue => '2008-08-01 11:34:26'});
is($date2->getValueAsHtml(), '2008-08-01 06:34:26', "getValueAsHtml: defaultValue in mysql format, returns default value in mysql format");
is(
getValueFromForm($session, $date2->toHtmlAsHidden),
'2008-08-01 06:34:26',
"toHtmlAsHidden: defaultValue in mysql format, returns date in mysql format"
);
is(
getValueFromForm($session, $date2->toHtml),
'2008-08-01 06:34:26',
"toHtml: defaultValue in mysql format, returns date in mysql format"
);
$date2 = WebGUI::Form::DateTime->new($session, {defaultValue => '2008-08-01 11:34:26', value => $bday, });
is($date2->getValueAsHtml(), '8/16/2001 8:00 am', "getValueAsHtml: defaultValue in mysql format, value as epoch returns value in user's format");
is(
getValueFromForm($session, $date2->toHtmlAsHidden),
'2001-08-16 08:00:00',
"toHtmlAsHidden: defaultValue in mysql format, value as epoch returns date in mysql format"
);
is(
getValueFromForm($session, $date2->toHtml),
'2001-08-16 08:00:00',
"toHtml: defaultValue in mysql format, value as epoch returns date in mysql format"
);
$date2 = WebGUI::Form::DateTime->new($session, {defaultValue => '2008-08-01 11:34:26', value => '2001-08-16 13:00:00', });
is($date2->getValueAsHtml(), '2001-08-16 08:00:00', "getValueAsHtml: defaultValue in mysql format, value as mysql returns value in mysql format");
is(
getValueFromForm($session, $date2->toHtmlAsHidden),
'2001-08-16 08:00:00',
"toHtmlAsHidden: defaultValue in mysql format, value as mysql returns date in mysql format, adjusted for time zone"
);
is(
getValueFromForm($session, $date2->toHtml),
'2001-08-16 08:00:00',
"toHtml: defaultValue in mysql format, value as mysql returns date in mysql format, adjusted for time zone"
);
sub getValueFromForm {
my ($session, $textForm) = @_;
my ($header, $footer) = (WebGUI::Form::formHeader($session), WebGUI::Form::formFooter($session));
my @forms = HTML::Form->parse($header.$textForm.$footer, 'http://www.webgui.org');
my @inputs = $forms[0]->inputs;
return $inputs[1]->{value};
}