Fixed Survey section-level branch precedence bug
For Sections with questions spread out over multiple pages, branch expressions should only happen on the last page of the Section. Added explicit test.
This commit is contained in:
parent
da595da89e
commit
9702ffcaac
2 changed files with 44 additions and 23 deletions
|
|
@ -545,6 +545,8 @@ the precedence order is inside-out, in order of questions displayed, e.g.
|
||||||
|
|
||||||
The first to trigger a jump short-circuits the process, meaning that subsequent items are not attempted.
|
The first to trigger a jump short-circuits the process, meaning that subsequent items are not attempted.
|
||||||
|
|
||||||
|
For Sections with questions spread out over several pages, Section-level actions are only performed on the final page of the Section.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub recordResponses {
|
sub recordResponses {
|
||||||
|
|
@ -557,6 +559,7 @@ sub recordResponses {
|
||||||
# We want to record responses against the "next" response section and questions, since these are
|
# We want to record responses against the "next" response section and questions, since these are
|
||||||
# the items that have just been displayed to the user.
|
# the items that have just been displayed to the user.
|
||||||
my $section = $self->nextResponseSection();
|
my $section = $self->nextResponseSection();
|
||||||
|
my $sId = $self->nextResponseSectionIndex(); # make note of the section id prior to recording any responses
|
||||||
|
|
||||||
# Process responses by looping over expected questions in survey order
|
# Process responses by looping over expected questions in survey order
|
||||||
my @questions = $self->nextQuestions();
|
my @questions = $self->nextQuestions();
|
||||||
|
|
@ -628,9 +631,10 @@ sub recordResponses {
|
||||||
time => time,
|
time => time,
|
||||||
};
|
};
|
||||||
|
|
||||||
# Only record verbatim if this is a verbatim answer
|
# Only record verbatim if answer is marked verbatim
|
||||||
if ($answer->{verbatim}) {
|
my $verbatim = $responses->{ "${aId}verbatim" };
|
||||||
$newResponse{ $aId }{verbatim} = $responses->{ "${aId}verbatim" };
|
if ($answer->{verbatim} && defined $verbatim && length $verbatim) {
|
||||||
|
$newResponse{ $aId }{verbatim} = $verbatim;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -720,22 +724,24 @@ sub recordResponses {
|
||||||
# N.B. Questions don't have terminalUrls
|
# N.B. Questions don't have terminalUrls
|
||||||
}
|
}
|
||||||
|
|
||||||
# Then Sections..
|
# Then Sections.. (but if this is the last page of the Section)
|
||||||
|
my $newSectionIndex = $self->nextResponseSectionIndex;
|
||||||
# Section goto
|
if ($newSectionIndex != $sId) {
|
||||||
if (my $action = $section->{goto} && $self->processGoto($section->{goto})) {
|
# Section goto
|
||||||
$self->session->log->debug("Branching on Section goto: $section->{goto}");
|
if (my $action = $section->{goto} && $self->processGoto($section->{goto})) {
|
||||||
return $action;
|
$self->session->log->debug("Branching on Section goto: $section->{goto}");
|
||||||
}
|
return $action;
|
||||||
# Then section gotoExpression
|
}
|
||||||
if (my $action = $section->{gotoExpression} && $self->processExpression($section->{gotoExpression})) {
|
# Then section gotoExpression
|
||||||
$self->session->log->debug("Branching on Section gotoExpression: $section->{gotoExpression}");
|
if (my $action = $section->{gotoExpression} && $self->processExpression($section->{gotoExpression})) {
|
||||||
return $action;
|
$self->session->log->debug("Branching on Section gotoExpression: $section->{gotoExpression}");
|
||||||
}
|
return $action;
|
||||||
# Then section terminal
|
}
|
||||||
if ($section->{terminal} && $self->nextResponseSectionIndex != $self->lastResponseSectionIndex) {
|
# Then section terminal
|
||||||
$self->session->log->debug("Section terminal: $section->{terminalUrl}");
|
if ($section->{terminal} && $self->nextResponseSectionIndex != $self->lastResponseSectionIndex) {
|
||||||
return { terminal => $section->{terminalUrl} };
|
$self->session->log->debug("Section terminal: $section->{terminalUrl}");
|
||||||
|
return { terminal => $section->{terminalUrl} };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# The above goto and gotoExpression checks will have already called $self->checkForLogicalSection after
|
# The above goto and gotoExpression checks will have already called $self->checkForLogicalSection after
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
my $tests = 113;
|
my $tests = 115;
|
||||||
plan tests => $tests + 1;
|
plan tests => $tests + 1;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -506,8 +506,23 @@ cmp_deeply($rJSON->processExpression(q{restart()}), { restart => 1 }, 'restart w
|
||||||
cmp_deeply($rJSON->processExpression(q{exitUrl(blah)}), { exitUrl => 'blah' }, 'explicit exitUrl works');
|
cmp_deeply($rJSON->processExpression(q{exitUrl(blah)}), { exitUrl => 'blah' }, 'explicit exitUrl works');
|
||||||
cmp_deeply($rJSON->processExpression(q{exitUrl()}), { exitUrl => undef }, 'unspecified exitUrl works too');
|
cmp_deeply($rJSON->processExpression(q{exitUrl()}), { exitUrl => undef }, 'unspecified exitUrl works too');
|
||||||
|
|
||||||
|
# Section branching should not happen until all questions in a section have been completed
|
||||||
|
$rJSON->survey->section([0])->{questionsPerPage} = 2; # Has 3 questions, so first submit will not trigger section-branching
|
||||||
|
$rJSON->survey->section([0])->{gotoExpression} = q{ tag('not so fast'); };
|
||||||
|
$rJSON->reset;
|
||||||
|
$rJSON->recordResponses({
|
||||||
|
'0-0-0' => 1,
|
||||||
|
'0-1-0' => '13 11 66',
|
||||||
|
});
|
||||||
|
cmp_deeply($rJSON->tags, {}, 'No tags yet, section branching should not run yet');
|
||||||
|
$rJSON->recordResponses({
|
||||||
|
'0-2-1' => 1,
|
||||||
|
});
|
||||||
|
cmp_deeply($rJSON->tags, { 'not so fast' => 1 }, 'Section branching has now run');
|
||||||
|
|
||||||
# Clean up after this set of tests
|
# Clean up after this set of tests
|
||||||
$rJSON->responses({});
|
$rJSON->reset;
|
||||||
|
$rJSON->survey->section([0])->{gotoExpression} = undef;
|
||||||
$rJSON->questionsAnswered(-1 * $rJSON->questionsAnswered);
|
$rJSON->questionsAnswered(-1 * $rJSON->questionsAnswered);
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
|
|
@ -851,7 +866,7 @@ $rJSON->recordResponses( {
|
||||||
'1-0-0' => 1, # Multi-choice answers are submitted like this,
|
'1-0-0' => 1, # Multi-choice answers are submitted like this,
|
||||||
'1-0-0verbatim' => 'insert witty comment',
|
'1-0-0verbatim' => 'insert witty comment',
|
||||||
'1-1-1' => 1, # with the selected answer set to 1
|
'1-1-1' => 1, # with the selected answer set to 1
|
||||||
'1-1-1verbatim' => '',
|
'1-1-1verbatim' => ' ',
|
||||||
});
|
});
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
$rJSON->responses->{'1-0-0'},
|
$rJSON->responses->{'1-0-0'},
|
||||||
|
|
@ -865,7 +880,7 @@ cmp_deeply(
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
$rJSON->responses->{'1-1-1'},
|
$rJSON->responses->{'1-1-1'},
|
||||||
{
|
{
|
||||||
'verbatim' => '',
|
'verbatim' => ' ',
|
||||||
'time' => num(time(), 3),
|
'time' => num(time(), 3),
|
||||||
'value' => 'No'
|
'value' => 'No'
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue