Fixed SurveyJSON->questions which was short-changing getGotoTargets
This commit is contained in:
parent
57dae409c7
commit
c1ac5b9761
2 changed files with 34 additions and 5 deletions
|
|
@ -1339,9 +1339,9 @@ sub session {
|
|||
|
||||
Returns a reference to all the questions from a particular section.
|
||||
|
||||
=head3 $address
|
||||
=head3 $address (optional)
|
||||
|
||||
See L<"Address Parameter">.
|
||||
See L<"Address Parameter">. If not defined, returns all questions.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -1349,7 +1349,13 @@ sub questions {
|
|||
my $self = shift;
|
||||
my ($address) = validate_pos(@_, { type => ARRAYREF, optional => 1});
|
||||
|
||||
return $self->sections->[ $address->[0] ]->{questions};
|
||||
if ($address) {
|
||||
return $self->sections->[ $address->[0] ]->{questions};
|
||||
} else {
|
||||
my $questions;
|
||||
push @$questions, @{$_->{questions} || []} for @{$self->sections};
|
||||
return $questions;
|
||||
}
|
||||
}
|
||||
|
||||
=head2 question ($address)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ my $session = WebGUI::Test->session;
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
my $tests = 132;
|
||||
my $tests = 139;
|
||||
plan tests => $tests + 1 + 3;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -2002,7 +2002,30 @@ cmp_deeply(
|
|||
|
||||
####################################################
|
||||
#
|
||||
# totalSections
|
||||
# questions
|
||||
#
|
||||
####################################################
|
||||
{
|
||||
my $s = WebGUI::Asset::Wobject::Survey::SurveyJSON->new($session, '{}');
|
||||
# Add a new section
|
||||
my $address = $s->newObject([]);
|
||||
cmp_deeply($s->questions, [], 'Initially no questions');
|
||||
# Add a question to first section
|
||||
$address = $s->newObject([0]);
|
||||
is(scalar @{$s->questions}, 1, '..now 1 question');
|
||||
is(scalar @{$s->questions([0])}, 1, '..in the first section');
|
||||
is($s->questions([2]), undef, '..and none in the second section (which doesnt even exist)');
|
||||
|
||||
# Add a question to second section
|
||||
$address = $s->newObject([1]);
|
||||
is(scalar @{$s->questions}, 2, '..now 2 question2');
|
||||
is(scalar @{$s->questions([0])}, 1, '..1 in the first section');
|
||||
is(scalar @{$s->questions([1])}, 1, '..1 in the second section');
|
||||
}
|
||||
|
||||
####################################################
|
||||
#
|
||||
# totalSections, totalQuestions, totalAnswers
|
||||
#
|
||||
####################################################
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue