Fixed #9927 Survey - verbatim

Fixed inconsistencies between answer 'comment' and 'verbatim'.
Updated tests.
Made minor changes to reporting methods but they still need some love.
This commit is contained in:
Patrick Donelan 2009-06-03 00:29:29 +00:00
parent 5509cf4d1c
commit 216a48580a
5 changed files with 43 additions and 49 deletions

View file

@ -14,6 +14,7 @@
- fixed #9920: Survey: cannot add questions in IE
- fixed #10449: Undefined template
- fixed #10365: Head tags do not work "Use Packed Head Tags".
- fixed #9927: Survey - verbatim
7.7.8
- fixed: Basic Auth doesn't work if password contains colon (Arjan Widlak,

View file

@ -2345,7 +2345,7 @@ sub loadTempReportTable {
'insert into Survey_tempReport VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [
$self->getId(), $ref->{Survey_responseId}, $count++, $q->{section},
$q->{sectionName}, $q->{question}, $q->{questionName}, $q->{questionComment},
$a->{id}, $a->{value}, $a->{comment}, $a->{time},
$a->{id}, $a->{value}, $a->{verbatim}, $a->{time},
$a->{isCorrect}, $a->{value}, undef
]
);

View file

@ -510,7 +510,7 @@ A hash ref of submitted form param data. Each element should look like:
{
"questionId-comment" => "question comment",
"answerId" => "answer",
"answerId-comment" => "answer comment",
"answerId-verbatim" => "answer verbatim",
}
See L<"questionId"> and L<"answerId">.
@ -557,7 +557,7 @@ sub recordResponses {
my $allQsValid = 1;
my %validAnswers;
for my $question (@questions) {
my $aValid = 0; # TODO: this is flawed because we can have multi-answer quesions
my $aValid = 0;
my $qId = $question->{id};
$newResponse{ $qId }->{comment} = $responses->{ "${qId}comment" };
@ -615,10 +615,13 @@ sub recordResponses {
# Otherwise, we use the (raw) submitted response (e.g. text input, date input etc..)
$newResponse{ $aId } = {
value => $specialQTypes{ $questionType } ? $recordedAnswer : $answer->{recordedAnswer},
verbatim => $answer->{verbatim} ? $responses->{ "${aId}verbatim" } : undef,
time => time,
comment => $responses->{ "${aId}comment" },
};
};
# Only record verbatim if this is a verbatim answer
if ($answer->{verbatim}) {
$newResponse{ $aId }{verbatim} = $responses->{ "${aId}verbatim" };
}
}
# Check if a required Question was skipped
@ -1535,11 +1538,11 @@ Answer keys are constructed by hypenating the relevant L<"sIndex">, L<"qIndex">
comment => "question comment",
},
# ...
# Answers entries contain: value (the recorded value), time and comment fields.
# Answers entries contain: value (the recorded value), time and verbatim field.
'0-0-0' => {
value => "recorded answer value",
time => time(),
comment => "answer comment",
verbatim => "answer verbatim",
},
# ...
}

View file

@ -109,6 +109,7 @@ delete $s->{responseId};
$session->user( { user => $user } );
# Restart the survey
$s->update({maxResponsesPerUser => 0});
$s->submitQuestions({
'0-0-0' => 'this text ignored',
'0-1-0' => 'this text ignored',
@ -118,14 +119,10 @@ cmp_deeply(
$s->responseJSON->responses,
superhashof(
{ '0-1-0' => {
'verbatim' => undef,
'comment' => undef,
'time' => num( time, 5 ),
'value' => 1
},
'0-0-0' => {
'verbatim' => undef,
'comment' => undef,
'time' => num( time, 5 ),
'value' => 1
},
@ -144,7 +141,7 @@ use JSON;
my $surveyEnd = $s->surveyEnd( { exitUrl => 'home' } );
cmp_deeply(from_json($surveyEnd), { type => 'forward', url => '/home' }, 'exitUrl works (it adds a slash for us)');
# Test out exitUrl using survye instance exitURL property
# Test out exitUrl using survey instance exitURL property
$s->update({ exitURL => 'getting_started'});
$surveyEnd = $s->surveyEnd( { exitUrl => undef } );
cmp_deeply(from_json($surveyEnd), { type => 'forward', url => '/getting_started' }, 'exitUrl works (it adds a slash for us)');

View file

@ -551,8 +551,7 @@ $rJSON->questionsAnswered(-1 * $rJSON->questionsAnswered);
$rJSON->recordResponses({
'1-0comment' => 'Section 1, question 0 comment',
'1-0-0' => 'First answer',
'1-0-0verbatim' => 'First answer verbatim',
'1-0-0comment' => 'Section 1, question 0, answer 0 comment',
'1-0-0verbatim' => 'Section 1, question 0, answer 0 verbatim',
});
cmp_deeply(
$rJSON->responses,
@ -561,10 +560,9 @@ cmp_deeply(
comment => 'Section 1, question 0 comment',
},
'1-0-0' => {
comment => 'Section 1, question 0, answer 0 comment',
'time' => num(time(), 3),
value => 1, # 'recordedAnswer' value used because question is multi-choice
verbatim => 'First answer verbatim',
verbatim => 'Section 1, question 0, answer 0 verbatim',
},
'1-1' => {
comment => undef,
@ -572,7 +570,7 @@ cmp_deeply(
},
'recordResponses: verbatim answer recorded responses correctly'
);
$rJSON->survey->answer([1,0,0])->{verbatim} = 0; # revert change
# Repeat with non multi-choice question, to check that submitted answer value is used
# instead of recordedValue
@ -583,7 +581,7 @@ $rJSON->questionsAnswered(-1 * $rJSON->questionsAnswered);
$rJSON->recordResponses({
'1-0comment' => 'Section 1, question 0 comment',
'1-0-0' => 'First answer',
'1-0-0comment' => 'Section 1, question 0, answer 0 comment',
'1-0-0verbatim' => 'Section 1, question 0, answer 0 comment',
});
cmp_deeply(
$rJSON->responses,
@ -592,10 +590,9 @@ cmp_deeply(
comment => 'Section 1, question 0 comment',
},
'1-0-0' => {
comment => 'Section 1, question 0, answer 0 comment',
verbatim => 'Section 1, question 0, answer 0 comment',
'time' => num(time(), 3),
value => 'First answer', # submitted answer value used this time because non-mc
verbatim => undef,
},
'1-1' => {
comment => undef,
@ -604,6 +601,7 @@ cmp_deeply(
'recordResponses: recorded responses correctly, two questions, one answer, comments, values and time'
);
$rJSON->survey->question([1,0])->{questionType} = 'Multiple Choice'; # revert change
$rJSON->survey->answer([1,0,0])->{verbatim} = 0; # revert change
$rJSON->survey->answer([1,0,0])->{terminal} = 1;
$rJSON->survey->answer([1,0,0])->{terminalUrl} = 'answer 1-0-0 terminal';
@ -650,10 +648,8 @@ cmp_deeply($rJSON->responses, {}, 'initially no responses');
$rJSON->recordResponses({
'1-0comment' => 'Section 1, question 0 comment',
'1-0-0' => 'First answer',
'1-0-0comment' => 'Section 1, question 0, answer 0 comment',
'1-1comment' => 'Section 1, question 1 comment',
'1-1-0' => 'Second answer',
'1-1-0comment' => 'Section 1, question 1, answer 0 comment',
});
my $popped = $rJSON->pop;
@ -661,16 +657,12 @@ cmp_deeply($popped, {
# the first q answer
'1-0-0' => {
value => 1,
comment => 'Section 1, question 0, answer 0 comment',
time => num(time(), 3),
verbatim => undef,
},
# the second q answer
'1-1-0' => {
value => 0,
comment => 'Section 1, question 1, answer 0 comment',
time => num(time(), 3),
verbatim => undef,
},
# the first question comment
'1-0' => {
@ -701,9 +693,7 @@ cmp_deeply($rJSON->pop, {
# the second q answer
'1-1-0' => {
value => 0,
comment => 'Section 1, question 1, answer 0 comment',
time => num(time(), 3),
verbatim => undef,
},
# the second question comment
'1-1' => {
@ -714,9 +704,7 @@ cmp_deeply($rJSON->responses, {
# the first q answer
'1-0-0' => {
value => 1,
comment => 'Section 1, question 0, answer 0 comment',
time => num(time(), 3),
verbatim => undef,
},
# the first question comment
'1-0' => {
@ -727,9 +715,7 @@ cmp_deeply($rJSON->pop, {
# the first q answer
'1-0-0' => {
value => 1,
comment => 'Section 1, question 0, answer 0 comment',
time => num(time(), 3),
verbatim => undef,
},
# the first question comment
'1-0' => {
@ -753,18 +739,20 @@ $rJSON = WebGUI::Asset::Wobject::Survey::ResponseJSON->new(buildSurveyJSON($sess
for my $q (0,1) {
$rJSON->survey->updateQuestionAnswers([1,$q], 'Country');
$rJSON->survey->answer([1,$q,0])->{recordedAnswer} = '-';
$rJSON->survey->answer([1,$q,0])->{verbatim} = 1;
}
$rJSON->reset;
$rJSON->lastResponse(2);
$rJSON->recordResponses( {
'1-0-0' => 'Australia',
'1-0-0verbatim' => 'insert witty comment',
'1-1-0' => 'JTville',
'1-1-0verbatim' => '',
});
cmp_deeply(
$rJSON->responses->{'1-0-0'},
{
'verbatim' => undef,
'comment' => undef,
'verbatim' => 'insert witty comment',
'time' => num(time(), 3),
'value' => 'Australia'
},
@ -777,18 +765,19 @@ is($rJSON->responses->{'1-1-0'}, undef, 'Invalid country ignored');
for my $q (0,1) {
$rJSON->survey->updateQuestionAnswers([1,$q], 'Date');
$rJSON->survey->answer([1,$q,0])->{recordedAnswer} = '-';
$rJSON->survey->answer([1,$q,0])->{verbatim} = 1;
}
$rJSON->reset;
$rJSON->lastResponse(2);
$rJSON->recordResponses( {
'1-0-0' => '2009/05/01',
'1-0-0verbatim' => 'insert witty comment',
'1-1-0' => '12345',
});
cmp_deeply(
$rJSON->responses->{'1-0-0'},
{
'verbatim' => undef,
'comment' => undef,
'verbatim' => 'insert witty comment',
'time' => num(time(), 3),
'value' => '2009/05/01'
},
@ -801,6 +790,7 @@ is($rJSON->responses->{'1-1-0'}, undef, 'Invalid date ignored');
for my $q (0,1) {
$rJSON->survey->updateQuestionAnswers([1,$q], 'Number');
$rJSON->survey->answer([1,$q,0])->{recordedAnswer} = '-';
$rJSON->survey->answer([1,$q,0])->{verbatim} = 1;
$rJSON->survey->answer([1,$q,0])->{min} = '-5';
$rJSON->survey->answer([1,$q,0])->{max} = '10';
}
@ -808,13 +798,13 @@ $rJSON->reset;
$rJSON->lastResponse(2);
$rJSON->recordResponses( {
'1-0-0' => '-3',
'1-0-0verbatim' => 'insert witty comment',
'1-1-0' => '11',
});
cmp_deeply(
$rJSON->responses->{'1-0-0'},
{
'verbatim' => undef,
'comment' => undef,
'verbatim' => 'insert witty comment',
'time' => num(time(), 3),
'value' => '-3'
},
@ -827,6 +817,7 @@ is($rJSON->responses->{'1-1-0'}, undef, 'Invalid number ignored');
for my $q (0,1) {
$rJSON->survey->updateQuestionAnswers([1,$q], 'Slider');
$rJSON->survey->answer([1,$q,0])->{recordedAnswer} = '-';
$rJSON->survey->answer([1,$q,0])->{verbatim} = 1;
$rJSON->survey->answer([1,$q,0])->{min} = '-5';
$rJSON->survey->answer([1,$q,0])->{max} = '10';
$rJSON->survey->answer([1,$q,0])->{step} = '1';
@ -835,13 +826,13 @@ $rJSON->reset;
$rJSON->lastResponse(2);
$rJSON->recordResponses( {
'1-0-0' => '-3',
'1-0-0verbatim' => 'insert witty comment',
'1-1-0' => '11',
});
cmp_deeply(
$rJSON->responses->{'1-0-0'},
{
'verbatim' => undef,
'comment' => undef,
'verbatim' => 'insert witty comment',
'time' => num(time(), 3),
'value' => '-3'
},
@ -856,18 +847,21 @@ $rJSON->survey->updateQuestionAnswers([1,1], 'Yes/No');
for my $q (0,1) {
$rJSON->survey->answer([1,$q,0])->{recordedAnswer} = 'Yes';
$rJSON->survey->answer([1,$q,1])->{recordedAnswer} = 'No';
$rJSON->survey->answer([1,$q,0])->{verbatim} = 1;
$rJSON->survey->answer([1,$q,1])->{verbatim} = 1;
}
$rJSON->reset;
$rJSON->lastResponse(2);
$rJSON->recordResponses( {
'1-0-0' => 1, # Multi-choice answers are submitted like this,
'1-0-0verbatim' => 'insert witty comment',
'1-1-1' => 1, # with the selected answer set to 1
'1-1-1verbatim' => '',
});
cmp_deeply(
$rJSON->responses->{'1-0-0'},
{
'verbatim' => undef,
'comment' => undef,
'verbatim' => 'insert witty comment',
'time' => num(time(), 3),
'value' => 'Yes'
},
@ -876,8 +870,7 @@ cmp_deeply(
cmp_deeply(
$rJSON->responses->{'1-1-1'},
{
'verbatim' => undef,
'comment' => undef,
'verbatim' => '',
'time' => num(time(), 3),
'value' => 'No'
},
@ -891,18 +884,20 @@ $rJSON->survey->updateQuestionAnswers([1,1], 'True/False');
for my $q (0,1) {
$rJSON->survey->answer([1,$q,0])->{recordedAnswer} = 'True';
$rJSON->survey->answer([1,$q,1])->{recordedAnswer} = 'False';
$rJSON->survey->answer([1,$q,0])->{verbatim} = 0;
$rJSON->survey->answer([1,$q,1])->{verbatim} = 0;
}
$rJSON->reset;
$rJSON->lastResponse(2);
$rJSON->recordResponses( {
'1-0-0' => 1, # Multi-choice answers are submitted like this,
'1-0-0verbatim' => 'will be ignored',
'1-1-1' => 1, # with the selected answer set to 1
'1-1-1verbatim' => 'will be ignored',
});
cmp_deeply(
$rJSON->responses->{'1-0-0'},
{
'verbatim' => undef,
'comment' => undef,
'time' => num(time(), 3),
'value' => 'True'
},
@ -911,8 +906,6 @@ cmp_deeply(
cmp_deeply(
$rJSON->responses->{'1-1-1'},
{
'verbatim' => undef,
'comment' => undef,
'time' => num(time(), 3),
'value' => 'False'
},