From 4cc810faf362dcf4b205df9cffabc5bd22d7e4de Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 9 Apr 2007 18:01:26 +0000 Subject: [PATCH] Added tests for mailToEpoch. Removed the default setting for mailToEpoch that would have assigned the epoch to the mail field and automatically caused the method to fail, returning undef. --- lib/WebGUI/Session/DateTime.pm | 2 +- t/Session/DateTime.t | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/Session/DateTime.pm b/lib/WebGUI/Session/DateTime.pm index 40e0cd30b..3f7bff0d8 100644 --- a/lib/WebGUI/Session/DateTime.pm +++ b/lib/WebGUI/Session/DateTime.pm @@ -723,7 +723,7 @@ A date formatted according to RFC2822/822. sub mailToEpoch { my $self = shift; - my $date = shift || time(); + my $date = shift; my $parser = DateTime::Format::Mail->new->loose; my $dt = eval {$parser->parse_datetime($date)}; if ($@) { diff --git a/t/Session/DateTime.t b/t/Session/DateTime.t index 15fddbb0d..5817501a8 100644 --- a/t/Session/DateTime.t +++ b/t/Session/DateTime.t @@ -15,7 +15,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; -use Test::More tests => 40; # increment this value for each test you create +use Test::More tests => 43; # increment this value for each test you create my $session = WebGUI::Test->session; @@ -105,6 +105,18 @@ $dude->profileField('timeZone', 'Australia/Perth'); $session->user({user => $dude}); is ($session->datetime->getTimeZone(), 'Australia/Perth', 'getTimeZone: valid time zones are allowed'); +#################################################### +# +# mailToEpoch +# +#################################################### + +my $wgBdayMail = 'Thu, 16 Aug 2001 08:00:00 -0500'; +is ($session->datetime->mailToEpoch($wgBdayMail), $wgbday, 'mailToEpoch'); + +is ($session->datetime->mailToEpoch(750), undef, 'mailToEpoch returns undef on failure to parse'); +like($WebGUI::Test::logger_warns, qr{750 is not a valid date for email}, "DateTime logs a warning on failure to parse"); + END { foreach my $account ($buster, $dude) { (defined $account and ref $account eq 'WebGUI::User') and $account->delete;