Change ResponseJSON to use a proper mutator for startTime.
Add tests for startTime. Survey uses the accessor, and no longer needs to manually set startTime.
This commit is contained in:
parent
5096352780
commit
1c1f01d473
3 changed files with 79 additions and 10 deletions
|
|
@ -19,7 +19,7 @@ my $session = WebGUI::Test->session;
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
my $tests = 1;
|
||||
my $tests = 13;
|
||||
plan tests => $tests + 1;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -38,9 +38,46 @@ skip $tests, "Unable to load ResponseJSON" unless $usedOk;
|
|||
#
|
||||
####################################################
|
||||
|
||||
my $newTime = time();
|
||||
$responseJSON = WebGUI::Asset::Wobject::Survey::ResponseJSON->new('{}', $session->log);
|
||||
isa_ok($responseJSON , 'WebGUI::Asset::Wobject::Survey::ResponseJSON');
|
||||
|
||||
is($responseJSON->lastResponse(), -1, 'new: default lastResponse is -1');
|
||||
is($responseJSON->{questionsAnswered}, 0, 'new: questionsAnswered is 0 by default');
|
||||
cmp_ok((abs$responseJSON->{startTime} - $newTime), '<=', 2, 'new: by default startTime set to time');
|
||||
is_deeply( $responseJSON->responses, {}, 'new: by default, responses is an empty hashref');
|
||||
is_deeply( $responseJSON->surveyOrder, [], 'new: by default, responses is an empty arrayref');
|
||||
|
||||
my $now = time();
|
||||
my $rJSON = WebGUI::Asset::Wobject::Survey::ResponseJSON->new(qq!{ "startTime": $now }!, $session->log);
|
||||
cmp_ok(abs($rJSON->startTime() - $now), '<=', 2, 'new: startTime set using JSON');
|
||||
|
||||
####################################################
|
||||
#
|
||||
# startTime
|
||||
#
|
||||
####################################################
|
||||
|
||||
$rJSON->startTime(780321600);
|
||||
is($rJSON->startTime, 780321600, 'startTime: set and get');
|
||||
|
||||
####################################################
|
||||
#
|
||||
# hasTimedOut
|
||||
#
|
||||
####################################################
|
||||
|
||||
##Reset for next set of tests
|
||||
$rJSON->startTime(time());
|
||||
|
||||
ok( ! $rJSON->hasTimedOut(1), 'hasTimedOut, not timed out, checked with 1 minute timeout');
|
||||
ok( ! $rJSON->hasTimedOut(0), 'hasTimedOut, not timed out, checked with 0 minute timeout');
|
||||
|
||||
$rJSON->startTime(time()-7200);
|
||||
ok( $rJSON->hasTimedOut(1), 'hasTimedOut, timed out');
|
||||
ok( ! $rJSON->hasTimedOut(0), 'hasTimedOut, bad limit');
|
||||
ok( ! $rJSON->hasTimedOut(4*60), 'hasTimedOut, limit check');
|
||||
|
||||
}
|
||||
|
||||
####################################################
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue