| Línea 14... |
Línea 14... |
| 14 |
// You should have received a copy of the GNU General Public License
|
14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
| Línea 16... |
Línea 16... |
| 16 |
|
16 |
|
| Línea -... |
Línea 17... |
| - |
|
17 |
namespace mod_quiz;
|
| - |
|
18 |
|
| - |
|
19 |
use core\exception\coding_exception;
|
| 17 |
namespace mod_quiz;
|
20 |
use question_bank;
|
| Línea 18... |
Línea 21... |
| 18 |
|
21 |
|
| 19 |
defined('MOODLE_INTERNAL') || die();
|
22 |
defined('MOODLE_INTERNAL') || die();
|
| Línea 28... |
Línea 31... |
| 28 |
* @category test
|
31 |
* @category test
|
| 29 |
* @copyright 2013 Adrian Greeve
|
32 |
* @copyright 2013 Adrian Greeve
|
| 30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 31 |
* @covers \mod_quiz\structure
|
34 |
* @covers \mod_quiz\structure
|
| 32 |
*/
|
35 |
*/
|
| 33 |
class structure_test extends \advanced_testcase {
|
36 |
final class structure_test extends \advanced_testcase {
|
| Línea 34... |
Línea 37... |
| 34 |
|
37 |
|
| Línea 35... |
Línea 38... |
| 35 |
use \quiz_question_helper_test_trait;
|
38 |
use \quiz_question_helper_test_trait;
|
| 36 |
|
39 |
|
| Línea 902... |
Línea 905... |
| 902 |
// Having done an update, we need to reload $structure.
|
905 |
// Having done an update, we need to reload $structure.
|
| 903 |
$structure = structure::create_for_quiz($quizobj);
|
906 |
$structure = structure::create_for_quiz($quizobj);
|
| 904 |
$this->assertEquals(0, $structure->is_question_dependent_on_previous_slot(2));
|
907 |
$this->assertEquals(0, $structure->is_question_dependent_on_previous_slot(2));
|
| 905 |
}
|
908 |
}
|
| Línea -... |
Línea 909... |
| - |
|
909 |
|
| - |
|
910 |
public function test_update_slot_version(): void {
|
| - |
|
911 |
$this->resetAfterTest();
|
| - |
|
912 |
|
| - |
|
913 |
$course = $this->getDataGenerator()->create_course();
|
| - |
|
914 |
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
|
| - |
|
915 |
$quiz = $quizgenerator->create_instance(['course' => $course->id, 'questionsperpage' => 0,
|
| - |
|
916 |
'grade' => 100.0, 'sumgrades' => 2]);
|
| - |
|
917 |
|
| - |
|
918 |
get_coursemodule_from_instance('quiz', $quiz->id, $course->id);
|
| - |
|
919 |
|
| - |
|
920 |
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
| - |
|
921 |
$cat = $questiongenerator->create_question_category();
|
| - |
|
922 |
$numq = $questiongenerator->create_question('numerical', null, ['category' => $cat->id]);
|
| - |
|
923 |
$questiongenerator->update_question($numq, null, ['name' => 'Second version of numq']);
|
| - |
|
924 |
quiz_add_quiz_question($numq->id, $quiz);
|
| - |
|
925 |
|
| - |
|
926 |
$quizobj = quiz_settings::create($quiz->id);
|
| - |
|
927 |
$quizobj->preload_questions();
|
| - |
|
928 |
[$question] = array_values($quizobj->get_questions(null, false));
|
| - |
|
929 |
$structure = $quizobj->get_structure();
|
| - |
|
930 |
|
| - |
|
931 |
// Updating to a version which exists, should succeed.
|
| - |
|
932 |
$this->assertTrue($structure->update_slot_version($question->slotid, 2));
|
| - |
|
933 |
|
| - |
|
934 |
// Updating to the same version as the current version should return false.
|
| - |
|
935 |
$this->assertFalse($structure->update_slot_version($question->slotid, 2));
|
| - |
|
936 |
|
| - |
|
937 |
// Updating to a version which does not exists, should throw exception.
|
| - |
|
938 |
$this->expectException(coding_exception::class);
|
| - |
|
939 |
$this->expectExceptionMessage('Version: 3 does not exist for question bank entry: ' . $question->questionbankentryid);
|
| - |
|
940 |
$structure->update_slot_version($question->slotid, 3);
|
| - |
|
941 |
|
| - |
|
942 |
}
|
| 906 |
|
943 |
|
| 907 |
public function test_update_slot_grade_item(): void {
|
944 |
public function test_update_slot_grade_item(): void {
|
| 908 |
$quizobj = $this->create_test_quiz([
|
945 |
$quizobj = $this->create_test_quiz([
|
| 909 |
['TF1', 1, 'truefalse'],
|
946 |
['TF1', 1, 'truefalse'],
|
| 910 |
['TF2', 1, 'truefalse'],
|
947 |
['TF2', 1, 'truefalse'],
|
| Línea 947... |
Línea 984... |
| 947 |
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
|
984 |
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
|
| 948 |
$gradeitem = $quizgenerator->create_grade_item(
|
985 |
$gradeitem = $quizgenerator->create_grade_item(
|
| 949 |
['quizid' => $quizobj->get_quizid(), 'name' => 'Awesomeness!']);
|
986 |
['quizid' => $quizobj->get_quizid(), 'name' => 'Awesomeness!']);
|
| 950 |
$structure = structure::create_for_quiz($quizobj);
|
987 |
$structure = structure::create_for_quiz($quizobj);
|
| Línea 951... |
Línea 988... |
| 951 |
|
988 |
|
| 952 |
$this->expectException(\coding_exception::class);
|
989 |
$this->expectException(coding_exception::class);
|
| 953 |
$structure->update_slot_grade_item($structure->get_slot_by_number(1), $gradeitem->id);
|
990 |
$structure->update_slot_grade_item($structure->get_slot_by_number(1), $gradeitem->id);
|
| Línea 954... |
Línea 991... |
| 954 |
}
|
991 |
}
|
| 955 |
|
992 |
|
| Línea 962... |
Línea 999... |
| 962 |
$quiz = $this->create_test_quiz([]);
|
999 |
$quiz = $this->create_test_quiz([]);
|
| 963 |
$course = $quiz->get_course();
|
1000 |
$course = $quiz->get_course();
|
| Línea 964... |
Línea 1001... |
| 964 |
|
1001 |
|
| 965 |
$generator = $this->getDataGenerator();
|
1002 |
$generator = $this->getDataGenerator();
|
| 966 |
$teacher = $generator->create_and_enrol($course, 'editingteacher');
|
1003 |
$teacher = $generator->create_and_enrol($course, 'editingteacher');
|
| Línea 967... |
Línea 1004... |
| 967 |
$noneditingteacher = $generator->create_and_enrol($course, 'teacher');
|
1004 |
$nonteacher = $generator->create_and_enrol($course, 'student');
|
| 968 |
|
1005 |
|
| 969 |
$this->setUser($teacher);
|
1006 |
$this->setUser($teacher);
|
| Línea 970... |
Línea 1007... |
| 970 |
$structure = structure::create_for_quiz($quiz);
|
1007 |
$structure = structure::create_for_quiz($quiz);
|
| 971 |
$this->assertTrue($structure->can_add_random_questions());
|
1008 |
$this->assertTrue($structure->can_add_random_questions());
|
| 972 |
|
1009 |
|
| 973 |
$this->setUser($noneditingteacher);
|
1010 |
$this->setUser($nonteacher);
|
| Línea 974... |
Línea 1011... |
| 974 |
$structure = structure::create_for_quiz($quiz);
|
1011 |
$structure = structure::create_for_quiz($quiz);
|