MDL-47494 ddwtos: 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,34 @@
|
||||
@ou @ou_vle @qtype @qtype_ddwtos
|
||||
Feature: Test creating a drag and drop into text question
|
||||
As a teacher
|
||||
In order to test my students
|
||||
I need to be able to create drag and drop into text 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 into text question
|
||||
When I add a "Drag and drop into text" question filling the form with:
|
||||
| Question name | Drag and drop into text 001 |
|
||||
| Question text | The [[1]] [[2]] on the [[3]]. |
|
||||
| General feedback | The cat sat on the mat. |
|
||||
| id_choices_0_answer | cat |
|
||||
| id_choices_1_answer | sat |
|
||||
| id_choices_2_answer | mat |
|
||||
| id_choices_3_answer | dog |
|
||||
| id_choices_4_answer | table |
|
||||
| Hint 1 | First hint |
|
||||
| Hint 2 | Second hint |
|
||||
Then I should see "Drag and drop into text 001"
|
||||
@@ -0,0 +1,54 @@
|
||||
@ou @ou_vle @qtype @qtype_ddwtos
|
||||
Feature: Test duplicating a quiz containing a drag and drop into text question
|
||||
As a teacher
|
||||
In order re-use my courses containing drag and drop into text 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 | ddwtos | Drag to text | fox |
|
||||
And the following "activities" exist:
|
||||
| activity | name | course | idnumber |
|
||||
| quiz | Test quiz | C1 | quiz1 |
|
||||
And quiz "Test quiz" contains the following questions:
|
||||
| Drag to text | 1 |
|
||||
And I log in as "admin"
|
||||
And I follow "Course 1"
|
||||
|
||||
@javascript
|
||||
Scenario: Backup and restore a course containing a drag and drop into text 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 to text" "table_row"
|
||||
Then the following fields match these values:
|
||||
| Question name | Drag to text |
|
||||
| Question text | The [[1]] brown [[2]] jumped over the [[3]] dog. |
|
||||
| General feedback | This sentence uses each letter of the alphabet. |
|
||||
| Default mark | 1 |
|
||||
| Shuffle | 0 |
|
||||
| id_choices_0_answer | quick |
|
||||
| id_choices_0_choicegroup | 1 |
|
||||
| id_choices_1_answer | fox |
|
||||
| id_choices_1_choicegroup | 2 |
|
||||
| id_choices_2_answer | lazy |
|
||||
| id_choices_2_choicegroup | 3 |
|
||||
| id_choices_3_answer | slow |
|
||||
| id_choices_3_choicegroup | 1 |
|
||||
| id_choices_4_answer | dog |
|
||||
| id_choices_4_choicegroup | 2 |
|
||||
| id_choices_5_answer | assiduous |
|
||||
| id_choices_5_choicegroup | 3 |
|
||||
| For any correct response | Well done! |
|
||||
| For any partially correct response | Parts, but only parts, of your response are correct. |
|
||||
| id_shownumcorrect | 0 |
|
||||
| For any incorrect response | That is not right at all. |
|
||||
@@ -1,80 +0,0 @@
|
||||
@ou @ou_vle @qtype @qtype_ddwtos
|
||||
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 ddwtos (Drag and drop into text) 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
|
||||
# functionality, 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.
|
||||
|
||||
# Another way to test attempting this qtype while previewing it, is to write a
|
||||
# customised step for tabbing through place-holders and another customised
|
||||
# step for making use of arrow keys in order to go through the list of choices.
|
||||
|
||||
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 gapselect question.
|
||||
Given I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I navigate to "Question bank" node in "Course administration"
|
||||
|
||||
# Create a new question.
|
||||
And I add a "Drag and drop into text" question filling the form with:
|
||||
| Question name | Drag and drop into text 001 |
|
||||
| Question text | The [[1]] [[2]] on the [[3]]. |
|
||||
| General feedback | The cat sat on the mat. |
|
||||
| id_choices_0_answer | cat |
|
||||
| id_choices_1_answer | sat |
|
||||
| id_choices_2_answer | mat |
|
||||
| id_choices_3_answer | dog |
|
||||
| id_choices_4_answer | table |
|
||||
| Hint 1 | First hint |
|
||||
| Hint 2 | Second hint |
|
||||
Then I should see "Drag and drop into text 001"
|
||||
|
||||
# Preview it.
|
||||
When I click on "Preview" "link" in the "Drag and drop into text 001" "table_row"
|
||||
And I switch to "questionpreview" window
|
||||
Then I should see "Preview question: Drag and drop into text 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 into text 001"
|
||||
|
||||
# Edit the copy and verify the form field contents.
|
||||
When I click on "Edit" "link" in the "Drag and drop into text 001" "table_row"
|
||||
Then the following fields match these values:
|
||||
| Question name | Drag and drop into text 001 |
|
||||
| Question text | The [[1]] [[2]] on the [[3]]. |
|
||||
| General feedback | The cat sat on the mat. |
|
||||
| id_choices_0_answer | cat |
|
||||
| id_choices_1_answer | sat |
|
||||
| id_choices_2_answer | mat |
|
||||
| id_choices_3_answer | dog |
|
||||
| id_choices_4_answer | table |
|
||||
| Hint 1 | First hint |
|
||||
| Hint 2 | Second hint |
|
||||
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,82 @@
|
||||
<?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 into text.
|
||||
*
|
||||
* @package qtype_ddwtos
|
||||
* @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 into text question type.
|
||||
*
|
||||
* @copyright 2015 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class behat_qtype_ddwtos 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 drag_xpath($dragitem) {
|
||||
return '//span[contains(@class, " drag ") and contains(., "' . $this->escape($dragitem) . '")]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the xpath for a given drop box.
|
||||
* @param string $dragitem the number of the drop box.
|
||||
* @return string the xpath expression.
|
||||
*/
|
||||
protected function drop_xpath($spacenumber) {
|
||||
return '//span[contains(@class, " drop ") and contains(@class, "place' . $spacenumber . ' ")]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Drag the drag item with the given text to the given space.
|
||||
*
|
||||
* @param string $dragitem the text of the item to drag.
|
||||
* @param int $spacenumber the number of the gap to drop into.
|
||||
*
|
||||
* @Given /^I drag "(?P<drag_item>[^"]*)" to space "(?P<space_number>\d+)" in the drag and drop into text question$/
|
||||
*/
|
||||
public function i_drag_to_space_in_the_drag_and_drop_into_text_question($dragitem, $spacenumber) {
|
||||
$generalcontext = behat_context_helper::get('behat_general');
|
||||
$generalcontext->i_drag_and_i_drop_it_in($this->drag_xpath($dragitem),
|
||||
'xpath_element', $this->drop_xpath($spacenumber), 'xpath_element');
|
||||
}
|
||||
|
||||
/**
|
||||
* Type some characters while focussed on a given space.
|
||||
*
|
||||
* @param string $keys the characters to type.
|
||||
* @param int $spacenumber the number of the space to type into.
|
||||
*
|
||||
* @Given /^I type "(?P<keys>[^"]*)" into space "(?P<space_number>\d+)" in the drag and drop onto image question$/
|
||||
*/
|
||||
public function i_type_into_space_in_the_drag_and_drop_into_text_question($keys, $spacenumber) {
|
||||
$generalcontext = behat_context_helper::get('behat_general');
|
||||
$generalcontext->i_type_into_the($keys, $this->drop_xpath($spacenumber), 'xpath_element');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
@ou @ou_vle @qtype @qtype_ddwtos
|
||||
Feature: Test editing a drag and drop into text questions
|
||||
As a teacher
|
||||
In order to be able to update my drag and drop into text 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 | ddwtos | Drag to text | fox |
|
||||
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 into text question
|
||||
When I click on "Edit" "link" in the "Drag to text" "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_ddwtos
|
||||
Feature: Test exporting drag and drop into text questions
|
||||
As a teacher
|
||||
In order to be able to reuse my drag and drop into text 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 | ddwtos | Drag to text | fox |
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
|
||||
@javascript
|
||||
Scenario: Export a drag and drop into text 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 "1450" and "1550" 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
|
||||
+8
-8
@@ -1,12 +1,13 @@
|
||||
@ou @ou_vle @qtype @qtype_ddwtos
|
||||
Feature: Test importing questions of this type
|
||||
As a manager/teacher I should be able to import questions from other courses
|
||||
to this course
|
||||
Feature: Test importing drag and drop into text questions
|
||||
As a teacher
|
||||
In order to reuse drag and drop into text 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 |
|
||||
| teacher1 | T1 | Teacher1 | teacher1@example.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
@@ -16,9 +17,8 @@ Feature: Test importing questions of this type
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
|
||||
@javascript
|
||||
Scenario: import a variable numeric sets question.
|
||||
# Import sample file.
|
||||
@javascript @_file_upload
|
||||
Scenario: import drag and drop into text 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/ddwtos/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
|
||||
@@ -0,0 +1,61 @@
|
||||
@ou @ou_vle @qtype @qtype_ddwtos
|
||||
Feature: Preview a drag-drop into text question
|
||||
As a teacher
|
||||
In order to check my drag-drop into text 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 | ddwtos | Drag to text | fox |
|
||||
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 to text" "table_row"
|
||||
And I switch to "questionpreview" window
|
||||
And I wait "1" seconds
|
||||
And I drag "quick" to space "1" in the drag and drop into text question
|
||||
And I drag "fox" to space "2" in the drag and drop into text question
|
||||
And I drag "assiduous" to space "3" in the drag and drop into text question
|
||||
And I press "Submit and finish"
|
||||
Then the state of "The" question is shown as "Partially correct"
|
||||
And I should see "Mark 0.67 out of 1.00"
|
||||
|
||||
@javascript
|
||||
Scenario: Preview a question using the keyboard & submit incomplete.
|
||||
When I click on "Preview" "link" in the "Drag to text" "table_row"
|
||||
And I switch to "questionpreview" window
|
||||
And I wait "1" seconds
|
||||
And I type " " into space "1" in the drag and drop onto image question
|
||||
And I type " " into space "2" in the drag and drop onto image question
|
||||
And I type " " into space "3" in the drag and drop onto image question
|
||||
And I press "Save"
|
||||
Then the state of "The" question is shown as "Incomplete answer"
|
||||
And I should see "Please put an answer in each box."
|
||||
|
||||
@javascript
|
||||
Scenario: Preview a question using the keyboard.
|
||||
When I click on "Preview" "link" in the "Drag to text" "table_row"
|
||||
And I switch to "questionpreview" window
|
||||
And I wait "1" seconds
|
||||
And I type " " into space "1" in the drag and drop onto image question
|
||||
And I type " " into space "2" in the drag and drop onto image question
|
||||
And I type " " into space "3" in the drag and drop onto image question
|
||||
And I press "Submit and finish"
|
||||
Then the state of "The" question is shown as "Incorrect"
|
||||
And I should see "Mark 0.00 out of 1.00"
|
||||
@@ -75,6 +75,31 @@ class qtype_ddwtos_test_helper extends question_test_helper {
|
||||
return $dd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return stdClass date to create a ddwtos question.
|
||||
*/
|
||||
public function get_ddwtos_question_form_data_fox() {
|
||||
$fromform = new stdClass();
|
||||
|
||||
$fromform->name = 'Drag-and-drop words into sentences question';
|
||||
$fromform->questiontext = array('text' => 'The [[1]] brown [[2]] jumped over the [[3]] dog.', 'format' => FORMAT_HTML);
|
||||
$fromform->defaultmark = 1.0;
|
||||
$fromform->generalfeedback = array('text' => 'This sentence uses each letter of the alphabet.', 'format' => FORMAT_HTML);
|
||||
$fromform->choices = array(
|
||||
array('answer' => 'quick', 'choicegroup' => '1'),
|
||||
array('answer' => 'fox', 'choicegroup' => '2'),
|
||||
array('answer' => 'lazy', 'choicegroup' => '3'),
|
||||
array('answer' => 'slow', 'choicegroup' => '1'),
|
||||
array('answer' => 'dog', 'choicegroup' => '2'),
|
||||
array('answer' => 'assiduous', 'choicegroup' => '3'),
|
||||
);
|
||||
test_question_maker::set_standard_combined_feedback_form_data($fromform);
|
||||
$fromform->shownumcorrect = 0;
|
||||
$fromform->penalty = 0.3333333;
|
||||
|
||||
return $fromform;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return qtype_ddwtos_question
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user