Add tests for nextSectionid, nextSection, currentSection.
Add more POD to ResponseJSON
This commit is contained in:
parent
c60393e44a
commit
98294e4e78
2 changed files with 108 additions and 4 deletions
|
|
@ -217,21 +217,57 @@ sub startTime {
|
||||||
}
|
}
|
||||||
|
|
||||||
#array of addresses in which the survey should be presented
|
#array of addresses in which the survey should be presented
|
||||||
|
|
||||||
|
=head2 surveyOrder
|
||||||
|
|
||||||
|
Accessor for the survey order data structure. It is a deep set of arrays, similar in
|
||||||
|
structure to a WebGUI::Asset::Wobject::Survey::SurveyJSON address.
|
||||||
|
|
||||||
|
[ $sectionIndex, $questionIndex, [ $answerIndex1, $answerIndex2, ....]
|
||||||
|
|
||||||
|
There is one array element for every section and address in the survey.
|
||||||
|
|
||||||
|
If there are no questions, or no addresses, those array elements will not be present.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
sub surveyOrder {
|
sub surveyOrder {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return $self->{surveyOrder};
|
return $self->{surveyOrder};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=head2 nextSectionId
|
||||||
|
|
||||||
|
Relative to the surveyOrder and the lastResponse index, get the index of the
|
||||||
|
next section. Note, based on the number of questions in an section, this can
|
||||||
|
be the same as the current section index.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
sub nextSectionId {
|
sub nextSectionId {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return $self->surveyOrder->[ $self->lastResponse + 1 ]->[0];
|
return $self->surveyOrder->[ $self->lastResponse + 1 ]->[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=head2 nextSection
|
||||||
|
|
||||||
|
Relative to the surveyOrder and the lastResponse index, gets the next section.
|
||||||
|
Note, based on the number of questions in a section, this can be the same as
|
||||||
|
the current section.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
sub nextSection {
|
sub nextSection {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return $self->survey->section( [ $self->surveyOrder->[ $self->lastResponse + 1 ]->[0] ] );
|
return $self->survey->section( [ $self->surveyOrder->[ $self->lastResponse + 1 ]->[0] ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=head2 currentSection
|
||||||
|
|
||||||
|
Relative to the surveyOrder and the lastResponse index, get the current section.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
sub currentSection {
|
sub currentSection {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return $self->survey->section( [ $self->surveyOrder->[ $self->lastResponse ]->[0] ] );
|
return $self->survey->section( [ $self->surveyOrder->[ $self->lastResponse ]->[0] ] );
|
||||||
|
|
@ -363,9 +399,7 @@ sub getPreviousAnswer {
|
||||||
sub nextQuestions {
|
sub nextQuestions {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
if ( $self->lastResponse >= $#{ $self->surveyOrder } ) {
|
return [] if $self->surveyEnd;
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
my $nextSectionId = $self->nextSectionId;
|
my $nextSectionId = $self->nextSectionId;
|
||||||
|
|
||||||
|
|
@ -400,6 +434,13 @@ sub nextQuestions {
|
||||||
return $questions;
|
return $questions;
|
||||||
} ## end sub nextQuestions
|
} ## end sub nextQuestions
|
||||||
|
|
||||||
|
=head2 surveyEnd
|
||||||
|
|
||||||
|
Returns true if the current index stored in lastResponse is greater than or
|
||||||
|
equal to the number of sections in the survey order.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
sub surveyEnd {
|
sub surveyEnd {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return 1 if ( $self->lastResponse >= $#{ $self->surveyOrder } );
|
return 1 if ( $self->lastResponse >= $#{ $self->surveyOrder } );
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
my $tests = 18;
|
my $tests = 32;
|
||||||
plan tests => $tests + 1;
|
plan tests => $tests + 1;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -152,6 +152,69 @@ cmp_deeply(
|
||||||
*$shuffleName = &$shuffleRef;
|
*$shuffleName = &$shuffleRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
#
|
||||||
|
# surveyEnd
|
||||||
|
#
|
||||||
|
####################################################
|
||||||
|
|
||||||
|
$rJSON->lastResponse(2);
|
||||||
|
ok( ! $rJSON->surveyEnd(), 'surveyEnd, with 9 elements, 2 != end of survey');
|
||||||
|
$rJSON->lastResponse(7);
|
||||||
|
ok( ! $rJSON->surveyEnd(), 'surveyEnd, with 9 elements, 7 != end of survey');
|
||||||
|
$rJSON->lastResponse(8);
|
||||||
|
ok( $rJSON->surveyEnd(), 'surveyEnd, with 9 elements, 8 == end of survey');
|
||||||
|
$rJSON->lastResponse(20);
|
||||||
|
ok( $rJSON->surveyEnd(), 'surveyEnd, with 9 elements, 20 >= end of survey');
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
#
|
||||||
|
# nextSectionId, nextSection
|
||||||
|
#
|
||||||
|
####################################################
|
||||||
|
|
||||||
|
$rJSON->lastResponse(0);
|
||||||
|
is($rJSON->nextSectionId(), 0, 'nextSectionId, lastResponse=0, nextSectionId=0');
|
||||||
|
cmp_deeply(
|
||||||
|
$rJSON->nextSection,
|
||||||
|
$rJSON->survey->section([0]),
|
||||||
|
'lastResponse=0, nextSection = section 0'
|
||||||
|
);
|
||||||
|
cmp_deeply(
|
||||||
|
$rJSON->currentSection,
|
||||||
|
$rJSON->survey->section([0]),
|
||||||
|
'lastResponse=0, currentSection = section 0'
|
||||||
|
);
|
||||||
|
|
||||||
|
$rJSON->lastResponse(2);
|
||||||
|
is($rJSON->nextSectionId(), 1, 'nextSectionId, lastResponse=2, nextSectionId=1');
|
||||||
|
cmp_deeply(
|
||||||
|
$rJSON->nextSection,
|
||||||
|
$rJSON->survey->section([1]),
|
||||||
|
'lastResponse=2, nextSection = section 1'
|
||||||
|
);
|
||||||
|
cmp_deeply(
|
||||||
|
$rJSON->currentSection,
|
||||||
|
$rJSON->survey->section([0]),
|
||||||
|
'lastResponse=2, currentSection = section 0'
|
||||||
|
);
|
||||||
|
|
||||||
|
$rJSON->lastResponse(6);
|
||||||
|
is($rJSON->nextSectionId(), 3, 'nextSectionId, lastResponse=6, nextSectionId=3');
|
||||||
|
cmp_deeply(
|
||||||
|
$rJSON->nextSection,
|
||||||
|
$rJSON->survey->section([3]),
|
||||||
|
'lastResponse=0, nextSection = section 3'
|
||||||
|
);
|
||||||
|
cmp_deeply(
|
||||||
|
$rJSON->currentSection,
|
||||||
|
$rJSON->survey->section([3]),
|
||||||
|
'lastResponse=6, currentSection = section 3'
|
||||||
|
);
|
||||||
|
|
||||||
|
$rJSON->lastResponse(20);
|
||||||
|
is($rJSON->nextSectionId(), undef, 'nextSectionId, lastResponse > surveyEnd, nextSectionId=undef');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue