Add a mutator for questionsAnswered, with tests.
Correct POD for recordResponses. Begin recordResponses answer processing tests.
This commit is contained in:
parent
14ebe05e68
commit
941240370b
2 changed files with 98 additions and 6 deletions
|
|
@ -206,6 +206,30 @@ sub lastResponse {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 questionsAnswered ([ $questionsAnswered ])
|
||||
|
||||
Mutator for the number of questions answered. With no arguments,
|
||||
does a set.
|
||||
|
||||
=head3 $questionsAnswered.
|
||||
|
||||
If defined, increments the number of questions by $questionsAnswered
|
||||
|
||||
=cut
|
||||
|
||||
sub questionsAnswered {
|
||||
my $self = shift;
|
||||
my $answered = shift;
|
||||
if ( defined $answered ) {
|
||||
$self->{questionsAnswered} += $answered;
|
||||
}
|
||||
else {
|
||||
return $self->{questionsAnswered};
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 startTime ([ $newStartTime ])
|
||||
|
||||
Mutator for the time the user began the survey. With no arguments,
|
||||
|
|
@ -322,10 +346,11 @@ answer id, also described there.
|
|||
|
||||
=head3 terminal processing
|
||||
|
||||
Terminal processing for a section and its question are handled in order. The terminalUrl
|
||||
setting in a question overrides the terminalUrl setting for its section. Similarly, with
|
||||
questions, the last terminalUrl setting of the set of questions is what is returned for
|
||||
the page.
|
||||
Terminal processing for a section and its questions and answers are handled in
|
||||
order. The terminalUrl setting in a question overrides the terminalUrl setting
|
||||
for its section. Similarly, with questions and answers, the last terminalUrl
|
||||
setting of the set of questions is what is returned for the page, with the questions
|
||||
and answers being answered in surveyOrder.
|
||||
|
||||
=head3 goto processing
|
||||
|
||||
|
|
@ -422,7 +447,9 @@ sub recordResponses {
|
|||
} ## end if ( defined( $responses...
|
||||
} ## end for my $answer ( @{ $question...
|
||||
$qAnswered = 0 if ( !$aAnswered and $question->{required} );
|
||||
$self->{questionsAnswered}++ if($aAnswered);
|
||||
if ($aAnswered) {
|
||||
$self->questionsAnswered( +1 );
|
||||
}
|
||||
} ## end for my $question (@$questions)
|
||||
|
||||
#if all responses completed, move the lastResponse index to the last question shown
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ my $session = WebGUI::Test->session;
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
my $tests = 44;
|
||||
my $tests = 52;
|
||||
plan tests => $tests + 1;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -343,6 +343,71 @@ cmp_deeply(
|
|||
[ 1, '/terminal' ],
|
||||
'recordResponses, if section has no questions, returns terminal info in the section.',
|
||||
);
|
||||
is($rJSON->questionsAnswered, 0, 'questionsAnswered=0, no questions answered');
|
||||
|
||||
$rJSON->survey->question([1,0])->{terminal} = 1;
|
||||
$rJSON->survey->question([1,0])->{terminalUrl} = 'question 1-0 terminal';
|
||||
|
||||
$rJSON->lastResponse(2);
|
||||
cmp_deeply(
|
||||
$rJSON->recordResponses($session, {
|
||||
'1-0comment' => 'Section 1, question 0 comment',
|
||||
'1-0-0' => 'First answer',
|
||||
'1-0-0comment' => 'Section 1, question 0, answer 0 comment',
|
||||
}),
|
||||
[ 1, 'question 1-0 terminal' ],
|
||||
'recordResponses: question terminal overrides section terminal',
|
||||
);
|
||||
is($rJSON->lastResponse(), 4, 'lastResponse advanced to next page of questions');
|
||||
is($rJSON->questionsAnswered, 1, 'questionsAnswered=1, answered one question');
|
||||
|
||||
cmp_deeply(
|
||||
$rJSON->responses,
|
||||
{
|
||||
'1-0' => {
|
||||
comment => 'Section 1, question 0 comment',
|
||||
},
|
||||
'1-0-0' => {
|
||||
comment => 'Section 1, question 0, answer 0 comment',
|
||||
'time' => num(time(), 3),
|
||||
value => 1,
|
||||
},
|
||||
'1-1' => {
|
||||
comment => undef,
|
||||
}
|
||||
},
|
||||
'recordResponses: recorded responses correctly, two questions, one answer, comments, values and time'
|
||||
);
|
||||
|
||||
$rJSON->survey->question([1,0,0])->{terminal} = 1;
|
||||
$rJSON->survey->question([1,0,0])->{terminalUrl} = 'answer 1-0-0 terminal';
|
||||
$rJSON->{responses} = {};
|
||||
$rJSON->lastResponse(2);
|
||||
$rJSON->questionsAnswered(-1 * $rJSON->questionsAnswered);
|
||||
|
||||
cmp_deeply(
|
||||
$rJSON->recordResponses($session, {
|
||||
'1-0comment' => 'Section 1, question 0 comment',
|
||||
'1-0-0' => "\t\t\t\n\n\n\t\t\t", #SOS in whitespace
|
||||
'1-0-0comment' => 'Section 1, question 0, answer 0 comment',
|
||||
}),
|
||||
[ 1, 'answer 1-0-0 terminal' ],
|
||||
'recordResponses: answer terminal overrides question and section terminals',
|
||||
);
|
||||
|
||||
cmp_deeply(
|
||||
$rJSON->responses,
|
||||
{
|
||||
'1-0' => {
|
||||
comment => 'Section 1, question 0 comment',
|
||||
},
|
||||
'1-1' => {
|
||||
comment => undef,
|
||||
}
|
||||
},
|
||||
'recordResponses: if the answer is all whitespace, it is skipped over'
|
||||
);
|
||||
is($rJSON->questionsAnswered, 0, 'question was all whitespace, not answered');
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue