Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
028cbda0
Commit
028cbda0
authored
Jun 30, 2022
by
jun
Browse files
Merge branch 'MDL-75048-master' of
https://github.com/jleyva/moodle
parents
3af7eee0
a3201673
Changes
2
Hide whitespace changes
Inline
Side-by-side
mod/quiz/attemptlib.php
View file @
028cbda0
...
...
@@ -547,8 +547,9 @@ class quiz {
if
(
!
isset
(
$qcategories
[
$questiondata
->
category
]))
{
$qcategories
[
$questiondata
->
category
]
=
false
;
}
if
(
$questiondata
->
includingsubcategories
)
{
$qcategories
[
$questiondata
->
category
]
=
true
;
if
(
!
empty
(
$questiondata
->
filtercondition
))
{
$filtercondition
=
json_decode
(
$questiondata
->
filtercondition
);
$qcategories
[
$questiondata
->
category
]
=
!
empty
(
$filtercondition
->
includingsubcategories
);
}
}
else
{
if
(
!
in_array
(
$questiondata
->
qtype
,
$questiontypes
))
{
...
...
mod/quiz/tests/external/external_test.php
View file @
028cbda0
...
...
@@ -1960,4 +1960,55 @@ class external_test extends externallib_advanced_testcase {
$this
->
assertEquals
(
$expected
,
$result
);
}
/**
* Test get_quiz_required_qtypes for quiz with random questions
*/
public
function
test_get_quiz_required_qtypes_random
()
{
$this
->
setAdminUser
();
// Create a new quiz.
$quizgenerator
=
$this
->
getDataGenerator
()
->
get_plugin_generator
(
'mod_quiz'
);
$quiz
=
$quizgenerator
->
create_instance
([
'course'
=>
$this
->
course
->
id
]);
// Create some questions.
$questiongenerator
=
$this
->
getDataGenerator
()
->
get_plugin_generator
(
'core_question'
);
$cat
=
$questiongenerator
->
create_question_category
();
$anothercat
=
$questiongenerator
->
create_question_category
();
$question
=
$questiongenerator
->
create_question
(
'numerical'
,
null
,
[
'category'
=>
$cat
->
id
]);
$question
=
$questiongenerator
->
create_question
(
'shortanswer'
,
null
,
[
'category'
=>
$cat
->
id
]);
$question
=
$questiongenerator
->
create_question
(
'truefalse'
,
null
,
[
'category'
=>
$cat
->
id
]);
// Question in a different category.
$question
=
$questiongenerator
->
create_question
(
'essay'
,
null
,
[
'category'
=>
$anothercat
->
id
]);
// Add a couple of random questions from the same category.
quiz_add_random_questions
(
$quiz
,
0
,
$cat
->
id
,
1
,
false
);
quiz_add_random_questions
(
$quiz
,
0
,
$cat
->
id
,
1
,
false
);
$this
->
setUser
(
$this
->
student
);
$result
=
mod_quiz_external
::
get_quiz_required_qtypes
(
$quiz
->
id
);
$result
=
\
external_api
::
clean_returnvalue
(
mod_quiz_external
::
get_quiz_required_qtypes_returns
(),
$result
);
$expected
=
[
'numerical'
,
'shortanswer'
,
'truefalse'
];
ksort
(
$result
[
'questiontypes'
]);
$this
->
assertEquals
(
$expected
,
$result
[
'questiontypes'
]);
// Add more questions to the quiz, this time from the other category.
$this
->
setAdminUser
();
quiz_add_random_questions
(
$quiz
,
0
,
$anothercat
->
id
,
1
,
false
);
$this
->
setUser
(
$this
->
student
);
$result
=
mod_quiz_external
::
get_quiz_required_qtypes
(
$quiz
->
id
);
$result
=
\
external_api
::
clean_returnvalue
(
mod_quiz_external
::
get_quiz_required_qtypes_returns
(),
$result
);
// The new question from the new category is returned as a potential random question for the quiz.
$expected
=
[
'essay'
,
'numerical'
,
'shortanswer'
,
'truefalse'
];
ksort
(
$result
[
'questiontypes'
]);
$this
->
assertEquals
(
$expected
,
$result
[
'questiontypes'
]);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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