MDL-47494 ddmarker: Improve the drag-drop question Behat tests.
* Added tests for previewing the question, to make sure it works when attempted. * Added Moodle XML export tests. * Reorganised the tests to follow the 'Test one thing per scenario' best practice. This commit requires MDL-49154 to work.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
@ou @ou_vle @qtype @qtype_ddmarker
|
||||
Feature: Test creating a drag and drop markers question
|
||||
As a teacher
|
||||
In order to test my students
|
||||
I need to be able to create drag and drop markers questions
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | T1 | Teacher1 | teacher1@moodle.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I navigate to "Question bank" node in "Course administration"
|
||||
|
||||
@javascript
|
||||
Scenario: Create a drag and drop markers question
|
||||
When I press "Create a new question ..."
|
||||
And I set the field "Drag and drop markers" to "1"
|
||||
And I press "Add"
|
||||
And I set the field "Question name" to "Drag and drop markers"
|
||||
And I set the field "Question text" to "Please place the markers on the map of Milton Keynes and be aware that there is more than one railway station."
|
||||
And I set the field "General feedback" to "The Open University is at the junction of Brickhill Street and Groveway. There are three railway stations, Wolverton, Milton Keynes Central and Bletchley."
|
||||
And I upload "question/type/ddmarker/tests/fixtures/mkmap.png" file to "Background image" filemanager
|
||||
|
||||
# Markers.
|
||||
And I follow "Markers"
|
||||
And I set the field "id_drags_0_label" to "OU"
|
||||
And I set the field "id_drags_0_noofdrags" to "1"
|
||||
And I set the field "id_drags_1_label" to "Railway station"
|
||||
And I set the field "id_drags_1_noofdrags" to "3"
|
||||
|
||||
# Drop zones.
|
||||
And I follow "Drop zones"
|
||||
And I set the field "id_drops_0_shape" to "Circle"
|
||||
And I set the field "id_drops_0_coords" to "322,213;10"
|
||||
And I set the field "id_drops_0_choice" to "1"
|
||||
And I set the field "id_drops_1_shape" to "Circle"
|
||||
And I set the field "id_drops_1_coords" to "144,84;10"
|
||||
And I set the field "id_drops_1_choice" to "2"
|
||||
And I set the field "id_drops_2_shape" to "Circle"
|
||||
And I set the field "id_drops_2_coords" to "195,180;10"
|
||||
And I set the field "id_drops_2_choice" to "2"
|
||||
And I set the field "id_drops_3_shape" to "Circle"
|
||||
And I set the field "id_drops_3_coords" to "267,302;10"
|
||||
|
||||
# Try to submit without setting the last marker.
|
||||
And I press "id_submitbutton"
|
||||
Then I should see "You have specified a drop zone but not chosen a marker that must be dragged to the zone"
|
||||
|
||||
# Set the last marker and submit again.
|
||||
And I set the field "id_drops_3_choice" to "2"
|
||||
And I press "id_submitbutton"
|
||||
And I should see "Drag and drop markers"
|
||||
@@ -0,0 +1,67 @@
|
||||
@ou @ou_vle @qtype @qtype_ddmarker
|
||||
Feature: Test duplicating a quiz containing a drag and drop markers question
|
||||
As a teacher
|
||||
In order re-use my courses containing drag and drop markers 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 | ddmarker | Drag markers | mkmap |
|
||||
And the following "activities" exist:
|
||||
| activity | name | course | idnumber |
|
||||
| quiz | Test quiz | C1 | quiz1 |
|
||||
And quiz "Test quiz" contains the following questions:
|
||||
| Drag markers | 1 |
|
||||
And I log in as "admin"
|
||||
And I follow "Course 1"
|
||||
|
||||
@javascript
|
||||
Scenario: Backup and restore a course containing a drag and drop markers question
|
||||
When I backup "Course 1" course using this options:
|
||||
| Confirmation | Filename | test_backup.mbz |
|
||||
And I restore "test_backup.mbz" backup into a new course using this options:
|
||||
| Schema | Course name | Course 2 |
|
||||
And I navigate to "Question bank" node in "Course administration"
|
||||
And I click on "Edit" "link" in the "Drag markers" "table_row"
|
||||
Then the following fields match these values:
|
||||
| Question name | Drag markers |
|
||||
| Question text | Please place the markers on the map of Milton Keynes and be aware that there is more than one railway station. |
|
||||
| General feedback | The Open University is at the junction of Brickhill Street and Groveway. There are three railway stations, Wolverton, Milton Keynes Central and Bletchley. |
|
||||
| Default mark | 1 |
|
||||
| id_shuffleanswers | 0 |
|
||||
| id_drags_0_label | OU |
|
||||
| id_drags_0_noofdrags | 1 |
|
||||
| id_drags_1_label | Railway station |
|
||||
| id_drags_1_noofdrags | 3 |
|
||||
| id_drops_0_shape | Circle |
|
||||
| id_drops_0_coords | 322,213;10 |
|
||||
| id_drops_0_choice | OU |
|
||||
| id_drops_1_shape | Circle |
|
||||
| id_drops_1_coords | 144,84;10 |
|
||||
| id_drops_1_choice | Railway station |
|
||||
| id_drops_2_shape | Circle |
|
||||
| id_drops_2_coords | 195,180;10 |
|
||||
| id_drops_2_choice | Railway station |
|
||||
| id_drops_3_shape | Circle |
|
||||
| id_drops_3_coords | 267,302;10 |
|
||||
| id_drops_3_choice | Railway station |
|
||||
| For any correct response | Well done! |
|
||||
| For any partially correct response | Parts, but only parts, of your response are correct. |
|
||||
| id_shownumcorrect | 1 |
|
||||
| For any incorrect response | That is not right at all. |
|
||||
| Penalty for each incorrect try | 0.3333333 |
|
||||
| Hint 1 | You are trying to place four markers on the map. |
|
||||
| id_hintshownumcorrect_0 | 1 |
|
||||
| id_hintclearwrong_0 | 0 |
|
||||
| id_hintoptions_0 | 0 |
|
||||
| Hint 2 | You are trying to mark three railway stations. |
|
||||
| id_hintshownumcorrect_1 | 1 |
|
||||
| id_hintclearwrong_1 | 1 |
|
||||
| id_hintoptions_1 | 1 |
|
||||
@@ -1,128 +0,0 @@
|
||||
@ou @ou_vle @qtype @qtype_ddmarker
|
||||
Feature: Test all the basic functionality of this question type
|
||||
In order to evaluate students responses, As a teacher I need to
|
||||
create and preview ddmarkers (Drag and drop markers) questions.
|
||||
|
||||
# Due to complexity and since the javascript code needs to be converted at some stage,
|
||||
# we are not going to test attempting this qtype. However, we will do all other
|
||||
# possible testings, such as creating the question preview it and seeing the
|
||||
# correct information on the preview string as well as backing-up and restoring
|
||||
# the course containing this qtype.
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | T1 | Teacher1 | teacher1@moodle.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
|
||||
@javascript
|
||||
Scenario: Create, edit then preview a ddmarker question.
|
||||
Given I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I navigate to "Question bank" node in "Course administration"
|
||||
Then I should see "Question bank"
|
||||
|
||||
# Create a new question
|
||||
# We have to set the fields individually, because of the step for uploading the background image.
|
||||
Given I press "Create a new question ..."
|
||||
And I set the field "Drag and drop markers" to "1"
|
||||
Then I press "Add"
|
||||
And I should see "Adding drag and drop markers"
|
||||
Then I set the field "Question name" to "Drag and drop markers 001"
|
||||
And I set the field "Question text" to "Please place the markers on the map of Milton Keynes and be aware that there is more than one railway station."
|
||||
And I set the field "General feedback" to "The Open University is at the junction of Brickhill Street and Groveway. There are three railway stations, Wolverton, Milton Keynes Central and Bletchley."
|
||||
Given I upload "question/type/ddmarker/tests/fixtures/mkmap.png" file to "Background image" filemanager
|
||||
|
||||
# Markers
|
||||
Given I follow "Markers"
|
||||
|
||||
And I set the field "id_drags_0_label" to "OU"
|
||||
And I set the field "id_drags_0_noofdrags" to "1"
|
||||
|
||||
And I set the field "id_drags_1_label" to "Railway station"
|
||||
And I set the field "id_drags_1_noofdrags" to "3"
|
||||
|
||||
# Drop zones
|
||||
Given I follow "Drop zones"
|
||||
And I set the field "id_drops_0_shape" to "Circle"
|
||||
And I set the field "id_drops_0_coords" to "322,213;10"
|
||||
And I set the field "id_drops_0_choice" to "1"
|
||||
|
||||
And I set the field "id_drops_1_shape" to "Circle"
|
||||
And I set the field "id_drops_1_coords" to "144,84;10"
|
||||
And I set the field "id_drops_1_choice" to "2"
|
||||
|
||||
And I set the field "id_drops_2_shape" to "Circle"
|
||||
And I set the field "id_drops_2_coords" to "195,180;10"
|
||||
And I set the field "id_drops_2_choice" to "2"
|
||||
|
||||
And I set the field "id_drops_3_shape" to "Circle"
|
||||
And I set the field "id_drops_3_coords" to "267,302;10"
|
||||
|
||||
# forget setting the last merker and press Save changes
|
||||
When I press "id_submitbutton"
|
||||
Then I should see "You have specified a drop zone but not chosen a marker that must be dragged to the zone"
|
||||
|
||||
# Set the last marker and press Save changes again
|
||||
And I set the field "id_drops_3_choice" to "2"
|
||||
|
||||
And I press "id_submitbutton"
|
||||
Then I should see "Drag and drop markers 001"
|
||||
|
||||
# Preview it.
|
||||
When I click on "Preview" "link" in the "Drag and drop markers 001" "table_row"
|
||||
And I switch to "questionpreview" window
|
||||
Then I should see "Preview question: Drag and drop markers 001"
|
||||
And I switch to the main window
|
||||
|
||||
# Backup the course and restore it.
|
||||
When I log out
|
||||
And I log in as "admin"
|
||||
When 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 |
|
||||
Then I should see "Course 2"
|
||||
When I navigate to "Question bank" node in "Course administration"
|
||||
Then I should see "Drag and drop markers 001"
|
||||
|
||||
# Edit the copy and verify the form field contents.
|
||||
When I click on "Edit" "link" in the "Drag and drop markers 001" "table_row"
|
||||
Then the following fields match these values:
|
||||
| Question name | Drag and drop markers 001 |
|
||||
| Question text | Please place the markers on the map of Milton Keynes and be aware that there is more than one railway station. |
|
||||
| General feedback | The Open University is at the junction of Brickhill Street and Groveway. There are three railway stations, Wolverton, Milton Keynes Central and Bletchley. |
|
||||
|
||||
# Drop zones
|
||||
| id_drops_0_shape | Circle |
|
||||
| id_drops_0_coords | 322,213;10 |
|
||||
| id_drops_0_choice | 1 |
|
||||
|
||||
| id_drops_1_shape | Circle |
|
||||
| id_drops_1_coords | 144,84;10 |
|
||||
| id_drops_1_choice | 2 |
|
||||
|
||||
| id_drops_2_shape | Circle |
|
||||
| id_drops_2_coords | 195,180;10 |
|
||||
| id_drops_2_choice | 2 |
|
||||
|
||||
| id_drops_3_shape | Circle |
|
||||
| id_drops_3_coords | 267,302;10 |
|
||||
| id_drops_3_choice | 2 |
|
||||
|
||||
# Markers
|
||||
| id_drags_0_label | OU |
|
||||
| id_drags_0_noofdrags | 1 |
|
||||
|
||||
| id_drags_1_label | Railway station |
|
||||
| id_drags_1_noofdrags | 3 |
|
||||
|
||||
And I set the following fields to these values:
|
||||
| Question name | Edited question name |
|
||||
And I press "id_submitbutton"
|
||||
Then I should see "Edited question name"
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
// This file is part of Stack - http://stack.bham.ac.uk/
|
||||
//
|
||||
// Stack 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.
|
||||
//
|
||||
// Stack 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 Stack. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Behat steps definitions for drag and drop markers.
|
||||
*
|
||||
* @package qtype_ddmarker
|
||||
* @category test
|
||||
* @copyright 2015 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
|
||||
|
||||
require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
|
||||
|
||||
/**
|
||||
* Steps definitions related with the drag and drop markers question type.
|
||||
*
|
||||
* @copyright 2015 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class behat_qtype_ddmarker extends behat_base {
|
||||
|
||||
/**
|
||||
* Get the xpath for a given drag item.
|
||||
* @param string $dragitem the text of the item to drag.
|
||||
* @return string the xpath expression.
|
||||
*/
|
||||
protected function marker_xpath($marker, $item = 0) {
|
||||
return '//span[contains(@class, " dragitem ") and contains(@class, " item' . $item .
|
||||
'") and span[@class = "markertext" and contains(normalize-space(.), "' .
|
||||
$this->escape($marker) . '")]]';
|
||||
}
|
||||
|
||||
protected function parse_marker_name($marker) {
|
||||
$item = 0;
|
||||
if (preg_match('~,(\d+)$~', $marker, $matches)) {
|
||||
$item = $matches[1];
|
||||
$marker = substr($marker, 0, -1 - strlen($item));
|
||||
}
|
||||
return array($marker, $item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drag the drag item with the given text to the given space.
|
||||
*
|
||||
* @param string $marker the marker to drag. The label, optionally followed by ,<instance number> (int) if relevant.
|
||||
* @param string $coordinates the position to drag the marker to, 'x,y'.
|
||||
*
|
||||
* @Given /^I drag "(?P<marker>[^"]*)" to "(?P<coordinates>\d+,\d+)" in the drag and drop markers question$/
|
||||
*/
|
||||
public function i_drag_to_in_the_drag_and_drop_markers_question($marker, $coordinates) {
|
||||
list($marker, $item) = $this->parse_marker_name($marker);
|
||||
list($x, $y) = explode(',', $coordinates);
|
||||
|
||||
// This is a bit nasty, but Behat (indeed Selenium) will only drag on
|
||||
// DOM node so that its centre is over the centre of anothe DOM node.
|
||||
// Therefore to make it drag to the specified place, we have to add
|
||||
// a target div.
|
||||
$style =
|
||||
$session = $this->getSession();
|
||||
$session->evaluateScript("
|
||||
(function() {
|
||||
if (document.getElementById('target-{$x}-{$y}')) {
|
||||
return;
|
||||
}
|
||||
var image = document.querySelector('.dropbackground');
|
||||
var target = document.createElement('div');
|
||||
target.setAttribute('id', 'target-{$x}-{$y}');
|
||||
var container = document.querySelector('.droparea');
|
||||
container.style.setProperty('position', 'relative');
|
||||
container.insertBefore(target, image);
|
||||
var xadjusted = {$x} + (container.offsetWidth - image.offsetWidth) / 2
|
||||
target.style.setProperty('position', 'absolute');
|
||||
target.style.setProperty('left', xadjusted + 'px');
|
||||
target.style.setProperty('top', '{$y}px');
|
||||
target.style.setProperty('width', '0');
|
||||
target.style.setProperty('height', '0');
|
||||
}())");
|
||||
|
||||
$generalcontext = behat_context_helper::get('behat_general');
|
||||
$generalcontext->i_drag_and_i_drop_it_in($this->marker_xpath($marker, $item),
|
||||
'xpath_element', "#target-{$x}-{$y}", 'css_element');
|
||||
}
|
||||
|
||||
/**
|
||||
* Type some characters while focussed on a given drop box.
|
||||
*
|
||||
* @param string $direction the direction key to press.
|
||||
* @param int $
|
||||
* @param string $marker the marker to drag. The label, optionally followed by ,<instance number> (int) if relevant.
|
||||
*
|
||||
* @Given /^I type "(?P<direction>up|down|left|right)" "(?P<repeats>\d+)" times on marker "(?P<marker>[^"]*)" in the drag and drop markers question$/
|
||||
*/
|
||||
public function i_type_on_marker_in_the_drag_and_drop_markers_question($direction, $repeats, $marker) {
|
||||
$keycodes = array(
|
||||
'up' => chr(38),
|
||||
'down' => chr(40),
|
||||
'left' => chr(37),
|
||||
'right' => chr(39),
|
||||
);
|
||||
$keys = str_repeat($keycodes[$direction], $repeats);
|
||||
list($marker, $item) = $this->parse_marker_name($marker);
|
||||
$generalcontext = behat_context_helper::get('behat_general');
|
||||
$generalcontext->i_type_into_the($keys, $this->marker_xpath($marker, $item), 'xpath_element');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
@ou @ou_vle @qtype @qtype_ddmarker
|
||||
Feature: Test editing a drag and drop markers questions
|
||||
As a teacher
|
||||
In order to be able to update my drag and drop markers questions
|
||||
I need to edit them
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | T1 | Teacher1 | teacher1@example.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And the following "question categories" exist:
|
||||
| contextlevel | reference | name |
|
||||
| Course | C1 | Test questions |
|
||||
And the following "questions" exist:
|
||||
| questioncategory | qtype | name | template |
|
||||
| Test questions | ddmarker | Drag markers | mkmap |
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I navigate to "Question bank" node in "Course administration"
|
||||
|
||||
@javascript
|
||||
Scenario: Edit a drag and drop markers question
|
||||
When I click on "Edit" "link" in the "Drag markers" "table_row"
|
||||
And I set the following fields to these values:
|
||||
| Question name | Edited question name |
|
||||
And I press "id_submitbutton"
|
||||
Then I should see "Edited question name"
|
||||
@@ -0,0 +1,37 @@
|
||||
@ou @ou_vle @qtype @qtype_ddmarker
|
||||
Feature: Test exporting drag and drop markers questions
|
||||
As a teacher
|
||||
In order to be able to reuse my drag and drop markers questions
|
||||
I need to export them
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | T1 | Teacher1 | teacher1@example.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And the following "question categories" exist:
|
||||
| contextlevel | reference | name |
|
||||
| Course | C1 | Test questions |
|
||||
And the following "questions" exist:
|
||||
| questioncategory | qtype | name | template |
|
||||
| Test questions | ddmarker | Drag markers | mkmap |
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
|
||||
@javascript
|
||||
Scenario: Export a drag and drop markers question
|
||||
# Import sample file.
|
||||
When I navigate to "Export" node in "Course administration > Question bank"
|
||||
And I set the field "id_format_xml" to "1"
|
||||
And I press "Export questions to file"
|
||||
And following "click here" should download between "297500" and "297700" bytes
|
||||
# If the download step is the last in the scenario then we can sometimes run
|
||||
# into the situation where the download page causes a http redirect but behat
|
||||
# has already conducted its reset (generating an error). By putting a logout
|
||||
# step we avoid behat doing the reset until we are off that page.
|
||||
And I log out
|
||||
+9
-9
@@ -1,24 +1,24 @@
|
||||
@ou @ou_vle @qtype @qtype_ddmarker
|
||||
Feature: Test the import functionality of this question type.
|
||||
As a manager/teacher I should be able to import questions from other courses to this course
|
||||
Feature: Test importing drag and drop markers questions
|
||||
As a teacher
|
||||
In order to reuse drag and drop markers questions
|
||||
I need to import them
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | T1 | Teacher1 | teacher1@moodle.com |
|
||||
| manager1 | M1 | Manager1 | manager11@moodle.com |
|
||||
| teacher1 | T1 | Teacher1 | teacher1@example.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| manager1 | C1 | manager |
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
|
||||
@javascript
|
||||
Scenario: import a ddmarker (Drag and drop markers) question.
|
||||
@javascript @_file_upload
|
||||
Scenario: import drag and drop markers question.
|
||||
When I navigate to "Import" node in "Course administration > Question bank"
|
||||
And I set the field "id_format_xml" to "1"
|
||||
And I upload "question/type/ddmarker/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
|
||||
@@ -27,4 +27,4 @@ Feature: Test the import functionality of this question type.
|
||||
And I should see "Importing 1 questions from file"
|
||||
And I should see "Please place the markers on the map of Milton Keynes and be aware that there is more than one railway station."
|
||||
And I press "Continue"
|
||||
And I should see "Imported Drag and drop markers 001"
|
||||
And I should see "Milton Keynes landmarks"
|
||||
@@ -0,0 +1,50 @@
|
||||
@ou @ou_vle @qtype @qtype_ddmarker
|
||||
Feature: Preview a drag-drop onto image question
|
||||
As a teacher
|
||||
In order to check my drag-drop onto image questions will work for students
|
||||
I need to preview them
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | T1 | Teacher1 | teacher1@moodle.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And the following "question categories" exist:
|
||||
| contextlevel | reference | name |
|
||||
| Course | C1 | Test questions |
|
||||
And the following "questions" exist:
|
||||
| questioncategory | qtype | name | template |
|
||||
| Test questions | ddmarker | Drag markers | mkmap |
|
||||
Given I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I navigate to "Question bank" node in "Course administration"
|
||||
|
||||
@javascript
|
||||
Scenario: Preview a question using the mouse.
|
||||
When I click on "Preview" "link" in the "Drag markers" "table_row"
|
||||
And I switch to "questionpreview" window
|
||||
And I wait "2" seconds
|
||||
# Odd, but the <br>s go to nothing, not a space.
|
||||
And I drag "OU" to "340,228" in the drag and drop markers question
|
||||
And I drag "Railway station" to "252,195" in the drag and drop markers question
|
||||
And I drag "Railway station,1" to "324,317" in the drag and drop markers question
|
||||
And I drag "Railway station,2" to "201,99" in the drag and drop markers question
|
||||
And I press "Submit and finish"
|
||||
Then the state of "Please place the markers on the map of Milton Keynes" question is shown as "Correct"
|
||||
And I should see "Mark 1.00 out of 1.00"
|
||||
|
||||
@javascript
|
||||
Scenario: Preview a question using the keyboard.
|
||||
When I click on "Preview" "link" in the "Drag markers" "table_row"
|
||||
And I switch to "questionpreview" window
|
||||
And I wait "1" seconds
|
||||
And I type "up" "89" times on marker "Railway station" in the drag and drop markers question
|
||||
And I type "right" "21" times on marker "Railway station" in the drag and drop markers question
|
||||
And I press "Submit and finish"
|
||||
Then the state of "Please place the markers on the map of Milton Keynes" question is shown as "Partially correct"
|
||||
And I should see "Mark 0.25 out of 1.00"
|
||||
@@ -11,7 +11,7 @@
|
||||
<!-- question: 1 -->
|
||||
<question type="ddmarker">
|
||||
<name>
|
||||
<text>Imported Drag and drop markers 001</text>
|
||||
<text>Milton Keynes landmarks</text>
|
||||
</name>
|
||||
<questiontext format="html">
|
||||
<text>Please place the markers on the map of Milton Keynes and be aware that there is more than one railway station.</text>
|
||||
|
||||
@@ -36,7 +36,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
*/
|
||||
class qtype_ddmarker_test_helper extends question_test_helper {
|
||||
public function get_test_questions() {
|
||||
return array('fox', 'maths');
|
||||
return array('fox', 'maths', 'mkmap');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,4 +129,69 @@ class qtype_ddmarker_test_helper extends question_test_helper {
|
||||
|
||||
return $dd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return stdClass date to create a ddmarkers question.
|
||||
*/
|
||||
public function get_ddmarker_question_form_data_mkmap() {
|
||||
global $CFG, $USER;
|
||||
$fromform = new stdClass();
|
||||
|
||||
$bgdraftitemid = 0;
|
||||
file_prepare_draft_area($bgdraftitemid, null, null, null, null);
|
||||
$fs = get_file_storage();
|
||||
$filerecord = new stdClass();
|
||||
$filerecord->contextid = context_user::instance($USER->id)->id;
|
||||
$filerecord->component = 'user';
|
||||
$filerecord->filearea = 'draft';
|
||||
$filerecord->itemid = $bgdraftitemid;
|
||||
$filerecord->filepath = '/';
|
||||
$filerecord->filename = 'mkmap.png';
|
||||
$fs->create_file_from_pathname($filerecord, $CFG->dirroot .
|
||||
'/question/type/ddmarker/tests/fixtures/mkmap.png');
|
||||
|
||||
$fromform->name = 'Milton Keynes landmarks';
|
||||
$fromform->questiontext = array(
|
||||
'text' => 'Please place the markers on the map of Milton Keynes and be aware that there is more than one railway station.',
|
||||
'format' => FORMAT_HTML,
|
||||
);
|
||||
$fromform->defaultmark = 1;
|
||||
$fromform->generalfeedback = array(
|
||||
'text' => 'The Open University is at the junction of Brickhill Street and Groveway. There are three railway stations, Wolverton, Milton Keynes Central and Bletchley.',
|
||||
'format' => FORMAT_HTML,
|
||||
);
|
||||
$fromform->bgimage = $bgdraftitemid;
|
||||
$fromform->shuffleanswers = 0;
|
||||
|
||||
$fromform->drags = array(
|
||||
array('label' => 'OU', 'noofdrags' => 1),
|
||||
array('label' => 'Railway station', 'noofdrags' => 3),
|
||||
);
|
||||
|
||||
$fromform->drops = array(
|
||||
array('shape' => 'Circle', 'coords' => '322,213;10', 'choice' => 1),
|
||||
array('shape' => 'Circle', 'coords' => '144,84;10', 'choice' => 2),
|
||||
array('shape' => 'Circle', 'coords' => '195,180;10', 'choice' => 2),
|
||||
array('shape' => 'Circle', 'coords' => '267,302;10', 'choice' => 2),
|
||||
);
|
||||
|
||||
test_question_maker::set_standard_combined_feedback_form_data($fromform);
|
||||
|
||||
$fromform->penalty ='0.3333333';
|
||||
$fromform->hint = array(
|
||||
array(
|
||||
'text' => 'You are trying to place four markers on the map.',
|
||||
'format' => FORMAT_HTML,
|
||||
),
|
||||
array(
|
||||
'text' => 'You are trying to mark three railway stations.',
|
||||
'format' => FORMAT_HTML,
|
||||
),
|
||||
);
|
||||
$fromform->hintshownumcorrect = array(1, 1);
|
||||
$fromform->hintclearwrong = array(0, 1);
|
||||
$fromform->hintoptions = array(0, 1);
|
||||
|
||||
return $fromform;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user