From c14ce14e3cb80b2d4cb4efea163635e88424b53f Mon Sep 17 00:00:00 2001 From: Tim Lock Date: Mon, 19 Sep 2016 10:14:07 +0930 Subject: [PATCH] MDL-55979 quiz: Fix error moving question from last page When moving the last question from the last page to the last slot of the previous page would show the error in the error log but move successfully. --- mod/quiz/classes/structure.php | 3 ++- mod/quiz/tests/structure_test.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mod/quiz/classes/structure.php b/mod/quiz/classes/structure.php index ba7f3a337fa..aae5c245ac4 100644 --- a/mod/quiz/classes/structure.php +++ b/mod/quiz/classes/structure.php @@ -715,7 +715,8 @@ class structure { } $followingslotnumber = $moveafterslotnumber + 1; - if ($followingslotnumber == $movingslotnumber) { + // Prevent checking against non-existance slot when already at the last slot. + if ($followingslotnumber == $movingslotnumber && !$this->is_last_slot_in_quiz($followingslotnumber)) { $followingslotnumber += 1; } diff --git a/mod/quiz/tests/structure_test.php b/mod/quiz/tests/structure_test.php index dd13daad623..9874635ee70 100644 --- a/mod/quiz/tests/structure_test.php +++ b/mod/quiz/tests/structure_test.php @@ -315,6 +315,24 @@ class mod_quiz_structure_testcase extends advanced_testcase { ), $structure); } + public function test_move_last_slot_to_previous_page_emptying_the_last_page() { + $quizobj = $this->create_test_quiz(array( + array('TF1', 1, 'truefalse'), + array('TF2', 2, 'truefalse'), + )); + $structure = \mod_quiz\structure::create_for_quiz($quizobj); + + $idtomove = $structure->get_question_in_slot(2)->slotid; + $idmoveafter = $structure->get_question_in_slot(1)->slotid; + $structure->move_slot($idtomove, $idmoveafter, '1'); + + $structure = \mod_quiz\structure::create_for_quiz($quizobj); + $this->assert_quiz_layout(array( + array('TF1', 1, 'truefalse'), + array('TF2', 1, 'truefalse'), + ), $structure); + } + public function test_end_of_one_section_to_start_of_next() { $quizobj = $this->create_test_quiz(array( array('TF1', 1, 'truefalse'),