-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
phpunit and behat for backup and restore #520123
- Loading branch information
Showing
6 changed files
with
171 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
namespace qtype_drawlines; | ||
|
||
use question_bank; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
global $CFG; | ||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php'); | ||
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php'); | ||
require_once($CFG->dirroot . '/course/externallib.php'); | ||
require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php"); | ||
|
||
/** | ||
* Tests for drawlines question type backup and restore. | ||
* | ||
* @package qtype_drawlines | ||
* @copyright 2024 The Open University | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. | ||
*/ | ||
class backup_and_restore_test extends \restore_date_testcase { | ||
|
||
/** | ||
* Backup and restore the course containing an drawlines question for testing drawlines backup and restore. | ||
* @covers \restore_qtype_drawlines_plugin | ||
*/ | ||
public function test_restore_create_qtype_drawlines_mkmap_twolines(): void { | ||
global $DB; | ||
|
||
// Create a course with one drawlines question in its question bank. | ||
$generator = $this->getDataGenerator(); | ||
$course = $generator->create_course(); | ||
$contexts = new \core_question\local\bank\question_edit_contexts(\context_course::instance($course->id)); | ||
$category = question_make_default_categories($contexts->all()); | ||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); | ||
$drawlines = $questiongenerator->create_question('drawlines', 'mkmap_twolines', ['category' => $category->id]); | ||
|
||
// Do backup and restore the course. | ||
$newcourseid = $this->backup_and_restore($course); | ||
|
||
// Verify that the restored question has the extra data such as options, lines. | ||
$contexts = new \core_question\local\bank\question_edit_contexts(\context_course::instance($newcourseid)); | ||
$newcategory = question_make_default_categories($contexts->all()); | ||
$newdrawlines = $DB->get_record_sql('SELECT q.* | ||
FROM {question} q | ||
JOIN {question_versions} qv ON qv.questionid = q.id | ||
JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid | ||
WHERE qbe.questioncategoryid = ? | ||
AND q.qtype = ?', [$newcategory->id, 'drawlines']); | ||
|
||
$newdrawlines->options = $DB->get_record('qtype_drawlines_options', ['questionid' => $newdrawlines->id]); | ||
$newdrawlines->lines = $DB->get_records('qtype_drawlines_lines', ['questionid' => $newdrawlines->id]); | ||
|
||
$this->assertSame($newcourseid, $course->id + 1); | ||
$this->assertSame((int)$newdrawlines->id, $drawlines->id + 1); | ||
|
||
$this->assertTrue($DB->record_exists('question', ['id' => $newdrawlines->id])); | ||
$this->assertTrue($DB->record_exists('qtype_drawlines_options', ['questionid' => $newdrawlines->id])); | ||
$this->assertTrue($DB->record_exists('qtype_drawlines_lines', ['questionid' => $newdrawlines->id])); | ||
|
||
$questionata = question_bank::load_question_data($newdrawlines->id); | ||
|
||
$this->assertSame('partial', $questionata->options->grademethod); | ||
|
||
$questionlines = array_values((array) $questionata->lines); | ||
$this->assertSame($newdrawlines->id, $questionlines[0]->questionid); | ||
$this->assertSame('1', $questionlines[0]->number); | ||
$this->assertSame(line::TYPE_LINE_SEGMENT, $questionlines[0]->type); | ||
$this->assertSame('Start 1', $questionlines[0]->labelstart); | ||
$this->assertSame('Mid 1', $questionlines[0]->labelmiddle); | ||
$this->assertSame('', $questionlines[0]->labelend); | ||
$this->assertSame('10,10;12', $questionlines[0]->zonestart); | ||
$this->assertSame('300,10;12', $questionlines[0]->zoneend); | ||
|
||
$this->assertSame($newdrawlines->id, $questionlines[1]->questionid); | ||
$this->assertSame('2', $questionlines[1]->number); | ||
$this->assertSame(line::TYPE_LINE_SEGMENT, $questionlines[1]->type); | ||
$this->assertSame('Start 2', $questionlines[1]->labelstart); | ||
$this->assertSame('Mid 2', $questionlines[1]->labelmiddle); | ||
$this->assertSame('End 2', $questionlines[1]->labelend); | ||
$this->assertSame('10,100;12', $questionlines[1]->zonestart); | ||
$this->assertSame('300,100;12', $questionlines[1]->zoneend); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
@qtype @qtype_drawlines | ||
Feature: Test duplicating a course containing a DrawLines question | ||
As a teacher | ||
In order re-use my courses containing DrawLines questions | ||
I need to be able to backup and restore them | ||
|
||
Background: | ||
And the following "courses" exist: | ||
| fullname | shortname | category | | ||
| Course 1 | C1 | 0 | | ||
And the following "question categories" exist: | ||
| contextlevel | reference | name | | ||
| Course | C1 | Test questions | | ||
And the following "questions" exist: | ||
| questioncategory | qtype | name | template | | ||
| Test questions | drawlines | Draw lines 01 | mkmap_twolines | | ||
And the following "activities" exist: | ||
| activity | name | course | idnumber | | ||
| quiz | Test quiz | C1 | quiz1 | | ||
And quiz "Test quiz" contains the following questions: | ||
| Draw lines 01 | 1 | | ||
And I log in as "admin" | ||
And I am on "Course 1" course homepage | ||
|
||
@javascript | ||
Scenario: Backup and restore a course containing a DrawLines question | ||
Given I backup "Course 1" course using this options: | ||
| Confirmation | Filename | test_backup.mbz | | ||
When I restore "test_backup.mbz" backup into a new course using this options: | ||
| Schema | Course name | Course 2 | | ||
| Schema | Course short name | C2 | | ||
And I am on the "Course 2" "core_question > course question bank" page | ||
And I choose "Edit question" action for "Draw lines 01" in the question bank | ||
Then the following fields match these values: | ||
| id_name | Draw lines 01 | | ||
| id_questiontext | <P>Draw 2 lines on the map. A line segment from A (line starting point) to B (line Ending point), and another one from C to D. A is ..., B is ..., C is ... and D is ...</P> | | ||
| id_status | Ready | | ||
| id_defaultmark | 1 | | ||
| id_generalfeedback | <p>We draw lines from a starting to an end point.</p> | | ||
| id_grademethod | partial | | ||
And I click on "Line 1" "link" | ||
And the following fields match these values: | ||
| id_type_0 | linesegment | | ||
| id_labelstart_0 | Start 1 | | ||
| id_labelmiddle_0 | Mid 1 | | ||
| id_labelend_0 | | | ||
| id_zonestart_0 | 10,10;12 | | ||
| id_zoneend_0 | 300,10;12 | | ||
And I click on "Line 2" "link" | ||
And the following fields match these values: | ||
| id_type_1 | linesegment | | ||
| id_labelstart_1 | Start 2 | | ||
| id_labelmiddle_1 | Mid 2 | | ||
| id_labelend_1 | End 2 | | ||
| id_zonestart_1 | 10,100;12 | | ||
| id_zoneend_1 | 300,100;12 | | ||
And I click on "Combined feedback" "link" | ||
And the following fields match these values: | ||
| For any correct response | Well done! | | ||
| For any partially correct response | Parts, but only parts, of your response are correct. | | ||
| For any incorrect response | That is not right at all. | | ||
And I click on "Multiple tries" "link" | ||
And the following fields match these values: | ||
| Hint 1 | You are trying to draw 2 lines by placing the start and end markers for each line on the map. | | ||
| Hint 2 | You have to find the positins for start and end of each line as described in the question text. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters