Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
integration
prechecker
Commits
38e0d68f
Commit
38e0d68f
authored
Sep 15, 2015
by
David Monllaó
Browse files
Merge branch 'MDL-51147_28' of
git://github.com/timhunt/moodle
into MOODLE_28_STABLE
parents
6c974ef3
d881f12c
Changes
2
Hide whitespace changes
Inline
Side-by-side
question/type/match/question.php
View file @
38e0d68f
...
...
@@ -134,25 +134,34 @@ class qtype_match_question extends question_graded_automatically_with_countback
}
public
function
classify_response
(
array
$response
)
{
$selectedchoices
=
array
();
$selectedchoice
key
s
=
array
();
foreach
(
$this
->
stemorder
as
$key
=>
$stemid
)
{
if
(
array_key_exists
(
$this
->
field
(
$key
),
$response
)
&&
$response
[
$this
->
field
(
$key
)])
{
$selectedchoices
[
$stemid
]
=
$this
->
choiceorder
[
$response
[
$this
->
field
(
$key
)]];
$selectedchoice
key
s
[
$stemid
]
=
$this
->
choiceorder
[
$response
[
$this
->
field
(
$key
)]];
}
else
{
$selectedchoices
[
$stemid
]
=
0
;
$selectedchoice
key
s
[
$stemid
]
=
0
;
}
}
$parts
=
array
();
foreach
(
$this
->
stems
as
$stemid
=>
$stem
)
{
if
(
empty
(
$selectedchoices
[
$stemid
]))
{
if
(
$this
->
right
[
$stemid
]
==
0
||
!
isset
(
$selectedchoicekeys
[
$stemid
]))
{
// Choice for a deleted subquestion, ignore. (See apply_attempt_state.)
continue
;
}
$selectedchoicekey
=
$selectedchoicekeys
[
$stemid
];
if
(
empty
(
$selectedchoicekey
))
{
$parts
[
$stemid
]
=
question_classified_response
::
no_response
();
continue
;
}
$choice
=
$this
->
choices
[
$selectedchoices
[
$stemid
]];
$choice
=
$this
->
choices
[
$selectedchoicekey
];
if
(
$choice
==
get_string
(
'deletedchoice'
,
'qtype_match'
))
{
// Deleted choice, ignore. (See apply_attempt_state.)
continue
;
}
$parts
[
$stemid
]
=
new
question_classified_response
(
$selectedchoice
s
[
$stemid
]
,
$choice
,
(
$selectedchoice
s
[
$stemid
]
==
$this
->
right
[
$stemid
])
/
count
(
$this
->
stems
));
$selectedchoice
key
,
$choice
,
(
$selectedchoice
key
==
$this
->
right
[
$stemid
])
/
count
(
$this
->
stems
));
}
return
$parts
;
}
...
...
question/type/match/tests/question_test.php
View file @
38e0d68f
...
...
@@ -181,6 +181,50 @@ class qtype_match_question_test extends advanced_testcase {
),
$match
->
classify_response
(
$response
));
}
public
function
test_classify_response_choice_deleted_after_attempt
()
{
$match
=
test_question_maker
::
make_a_matching_question
();
$firststep
=
new
question_attempt_step
();
$match
->
start_attempt
(
$firststep
,
1
);
$response
=
$match
->
prepare_simulated_post_data
(
array
(
'Dog'
=>
'Amphibian'
,
'Frog'
=>
'Insect'
,
'Toad'
=>
''
,
'Cat'
=>
'Mammal'
));
$match
=
test_question_maker
::
make_a_matching_question
();
unset
(
$match
->
stems
[
4
]);
unset
(
$match
->
stemsformat
[
4
]);
unset
(
$match
->
right
[
4
]);
$match
->
apply_attempt_state
(
$firststep
);
$this
->
assertEquals
(
array
(
1
=>
new
question_classified_response
(
2
,
'Amphibian'
,
0
),
2
=>
new
question_classified_response
(
3
,
'Insect'
,
0
),
3
=>
question_classified_response
::
no_response
(),
),
$match
->
classify_response
(
$response
));
}
public
function
test_classify_response_choice_added_after_attempt
()
{
$match
=
test_question_maker
::
make_a_matching_question
();
$firststep
=
new
question_attempt_step
();
$match
->
start_attempt
(
$firststep
,
1
);
$response
=
$match
->
prepare_simulated_post_data
(
array
(
'Dog'
=>
'Amphibian'
,
'Frog'
=>
'Insect'
,
'Toad'
=>
''
,
'Cat'
=>
'Mammal'
));
$match
=
test_question_maker
::
make_a_matching_question
();
$match
->
stems
[
5
]
=
"Snake"
;
$match
->
stemsformat
[
5
]
=
FORMAT_HTML
;
$match
->
choices
[
5
]
=
"Reptile"
;
$match
->
right
[
5
]
=
5
;
$match
->
apply_attempt_state
(
$firststep
);
$this
->
assertEquals
(
array
(
1
=>
new
question_classified_response
(
2
,
'Amphibian'
,
0
),
2
=>
new
question_classified_response
(
3
,
'Insect'
,
0
),
3
=>
question_classified_response
::
no_response
(),
4
=>
new
question_classified_response
(
1
,
'Mammal'
,
0.20
),
),
$match
->
classify_response
(
$response
));
}
public
function
test_prepare_simulated_post_data
()
{
$m
=
test_question_maker
::
make_a_matching_question
();
$m
->
start_attempt
(
new
question_attempt_step
(),
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment