From c1ac5b9761fb29835fa062db8931b67f8708ee47 Mon Sep 17 00:00:00 2001 From: Patrick Donelan Date: Thu, 2 Apr 2009 05:55:23 +0000 Subject: [PATCH] Fixed SurveyJSON->questions which was short-changing getGotoTargets --- lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm | 12 ++++++--- t/Asset/Wobject/Survey/SurveyJSON.t | 27 +++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm b/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm index d643ff59b..3c46095fb 100644 --- a/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm +++ b/lib/WebGUI/Asset/Wobject/Survey/SurveyJSON.pm @@ -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) diff --git a/t/Asset/Wobject/Survey/SurveyJSON.t b/t/Asset/Wobject/Survey/SurveyJSON.t index 24ba997c0..4d368681a 100644 --- a/t/Asset/Wobject/Survey/SurveyJSON.t +++ b/t/Asset/Wobject/Survey/SurveyJSON.t @@ -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 # #################################################### {