MDL-47494 ddimageortext: Improve the drag-drop question Behat tests.
authorTim Hunt <T.J.Hunt@open.ac.uk>
Fri, 13 Feb 2015 17:38:38 +0000 (17:38 +0000)
committerTim Hunt <T.J.Hunt@open.ac.uk>
Fri, 13 Feb 2015 17:38:38 +0000 (17:38 +0000)
* 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.

question/type/ddimageortext/tests/behat/add.feature [new file with mode: 0644]
question/type/ddimageortext/tests/behat/backup_and_restore.feature [new file with mode: 0644]
question/type/ddimageortext/tests/behat/basic_test.feature [deleted file]
question/type/ddimageortext/tests/behat/behat_qtype_ddimageortext.php [new file with mode: 0644]
question/type/ddimageortext/tests/behat/edit.feature [new file with mode: 0644]
question/type/ddimageortext/tests/behat/export.feature [new file with mode: 0644]
question/type/ddimageortext/tests/behat/import.feature [moved from question/type/ddimageortext/tests/behat/import_test.feature with 70% similarity]
question/type/ddimageortext/tests/behat/preview.feature [new file with mode: 0644]
question/type/ddimageortext/tests/helper.php

diff --git a/question/type/ddimageortext/tests/behat/add.feature b/question/type/ddimageortext/tests/behat/add.feature
new file mode 100644 (file)
index 0000000..f1aa2dc
--- /dev/null
@@ -0,0 +1,96 @@
+@ou @ou_vle @qtype @qtype_ddimageortext
+Feature: Test creating a drag and drop onto image question
+  As a teacher
+  In order to test my students
+  I need to be able to create drag and drop onto image 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 onto image question
+    When I press "Create a new question ..."
+    And I set the field "Drag and drop onto image" to "1"
+    And I press "Add"
+    And I set the field "Question name" to "Drag and drop onto image 001"
+    And I set the field "Question text" to "Identify the features in this cross-section."
+    And I set the field "General feedback" to "The locations are now labelled on the diagram below."
+    And I upload "question/type/ddimageortext/tests/fixtures/oceanfloorbase.jpg" file to "Background image" filemanager
+
+    # Draggable items
+    And I follow "Draggable items"
+    And I press "Blanks for 3 more draggable items"
+
+    And I set the field "id_drags_0_dragitemtype" to "Draggable text"
+    And I set the field "id_draglabel_0" to "island<br/>arc"
+
+    And I set the field "id_drags_1_dragitemtype" to "Draggable text"
+    And I set the field "id_draglabel_1" to "mid-ocean<br/>ridge"
+
+    And I set the field "id_drags_2_dragitemtype" to "Draggable text"
+    And I set the field "id_draglabel_2" to "abyssal<br/>plain"
+
+    And I set the field "id_drags_3_dragitemtype" to "Draggable text"
+    And I set the field "id_draglabel_3" to "continental<br/>rise"
+
+    And I set the field "id_drags_4_dragitemtype" to "Draggable text"
+    And I set the field "id_draglabel_4" to "ocean<br/>trench"
+
+    And I set the field "id_drags_5_dragitemtype" to "Draggable text"
+    And I set the field "id_draglabel_5" to "continental<br/>slope"
+
+    And I set the field "id_drags_6_dragitemtype" to "Draggable text"
+    And I set the field "id_draglabel_6" to "mountain<br/>belt"
+
+    And I set the field "id_drags_7_dragitemtype" to "Draggable text"
+    And I set the field "id_draglabel_7" to "continental<br/>shelf"
+
+    # Drop zones
+    And I follow "Drop zones"
+    And I press "Blanks for 3 more drop zones"
+
+    And I set the field "id_drops_0_xleft" to "53"
+    And I set the field "id_drops_0_ytop" to "17"
+    And I set the field "id_drops_0_choice" to "7"
+
+    And I set the field "id_drops_1_xleft" to "172"
+    And I set the field "id_drops_1_ytop" to "2"
+    And I set the field "id_drops_1_choice" to "8"
+
+    And I set the field "id_drops_2_xleft" to "363"
+    And I set the field "id_drops_2_ytop" to "31"
+    And I set the field "id_drops_2_choice" to "5"
+
+    And I set the field "id_drops_3_xleft" to "440"
+    And I set the field "id_drops_3_ytop" to "13"
+    And I set the field "id_drops_3_choice" to "3"
+
+    And I set the field "id_drops_4_xleft" to "115"
+    And I set the field "id_drops_4_ytop" to "74"
+    And I set the field "id_drops_4_choice" to "6"
+
+    And I set the field "id_drops_5_xleft" to "210"
+    And I set the field "id_drops_5_ytop" to "94"
+    And I set the field "id_drops_5_choice" to "4"
+
+    And I set the field "id_drops_6_xleft" to "310"
+    And I set the field "id_drops_6_ytop" to "87"
+    And I set the field "id_drops_6_choice" to "1"
+
+    And I set the field "id_drops_7_xleft" to "479"
+    And I set the field "id_drops_7_ytop" to "84"
+    And I set the field "id_drops_7_choice" to "2"
+
+    And I press "id_submitbutton"
+    Then I should see "Drag and drop onto image 001"
diff --git a/question/type/ddimageortext/tests/behat/backup_and_restore.feature b/question/type/ddimageortext/tests/behat/backup_and_restore.feature
new file mode 100644 (file)
index 0000000..8384e97
--- /dev/null
@@ -0,0 +1,100 @@
+@ou @ou_vle @qtype @qtype_ddimageortext
+Feature: Test duplicating a quiz containing a drag and drop onto image question
+  As a teacher
+  In order re-use my courses containing drag and drop onto image 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   | ddimageortext | Drag onto image | xsection |
+    And the following "activities" exist:
+      | activity   | name      | course | idnumber |
+      | quiz       | Test quiz | C1     | quiz1    |
+    And quiz "Test quiz" contains the following questions:
+      | Drag onto image | 1 |
+    And I log in as "admin"
+    And I follow "Course 1"
+
+  @javascript
+  Scenario: Backup and restore a course containing a drag and drop onto image 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 onto image" "table_row"
+    Then the following fields match these values:
+      | Question name                       | Drag onto image                                      |
+      | General feedback                    | <p>More information about the major features of the Earth's surface can be found in Block 3, Section 6.2.</p> |
+      | Default mark                        | 1                                                    |
+      | Shuffle                             | 0                                                    |
+      | id_drags_0_dragitemtype             | Draggable text                                       |
+      | id_drags_0_draggroup                | 1                                                    |
+      | id_draglabel_0                      | island<br/>arc                                       |
+      | id_drags_1_dragitemtype             | Draggable text                                       |
+      | id_drags_1_draggroup                | 1                                                    |
+      | id_draglabel_1                      | mid-ocean<br/>ridge                                  |
+      | id_drags_2_dragitemtype             | Draggable text                                       |
+      | id_drags_2_draggroup                | 1                                                    |
+      | id_draglabel_2                      | abyssal<br/>plain                                    |
+      | id_drags_3_dragitemtype             | Draggable text                                       |
+      | id_drags_3_draggroup                | 1                                                    |
+      | id_draglabel_3                      | continental<br/>rise                                 |
+      | id_drags_4_dragitemtype             | Draggable text                                       |
+      | id_drags_4_draggroup                | 1                                                    |
+      | id_draglabel_4                      | ocean<br/>trench                                     |
+      | id_drags_5_dragitemtype             | Draggable text                                       |
+      | id_drags_5_draggroup                | 1                                                    |
+      | id_draglabel_5                      | continental<br/>slope                                |
+      | id_drags_6_dragitemtype             | Draggable text                                       |
+      | id_drags_6_draggroup                | 1                                                    |
+      | id_draglabel_6                      | mountain<br/>belt                                    |
+      | id_drags_7_dragitemtype             | Draggable text                                       |
+      | id_drags_7_draggroup                | 1                                                    |
+      | id_draglabel_7                      | continental<br/>shelf                                |
+      | id_drops_0_xleft                    | 53                                                   |
+      | id_drops_0_ytop                     | 17                                                   |
+      | id_drops_0_choice                   | 7. mountainbelt                                      |
+      | id_drops_1_xleft                    | 172                                                  |
+      | id_drops_1_ytop                     | 2                                                    |
+      | id_drops_1_choice                   | 8. continentalshelf                                  |
+      | id_drops_2_xleft                    | 363                                                  |
+      | id_drops_2_ytop                     | 31                                                   |
+      | id_drops_2_choice                   | 5. oceantrench                                       |
+      | id_drops_3_xleft                    | 440                                                  |
+      | id_drops_3_ytop                     | 13                                                   |
+      | id_drops_3_choice                   | 3. abyssalplain                                      |
+      | id_drops_4_xleft                    | 115                                                  |
+      | id_drops_4_ytop                     | 74                                                   |
+      | id_drops_4_choice                   | 6. continentalslope                                  |
+      | id_drops_5_xleft                    | 210                                                  |
+      | id_drops_5_ytop                     | 94                                                   |
+      | id_drops_5_choice                   | 4. continentalrise                                   |
+      | id_drops_6_xleft                    | 310                                                  |
+      | id_drops_6_ytop                     | 87                                                   |
+      | id_drops_6_choice                   | 1. islandarc                                         |
+      | id_drops_7_xleft                    | 479                                                  |
+      | id_drops_7_ytop                     | 84                                                   |
+      | id_drops_7_choice                   | 2. mid-oceanridge                                    |
+      | 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                              | Incorrect placements will be removed.                |
+      | id_hintclearwrong_0                 | 1                                                    |
+      | id_hintshownumcorrect_0             | 1                                                    |
+      | id_hintclearwrong_1                 | 0                                                    |
+      | id_hintshownumcorrect_1             | 1                                                    |
+      | Hint 3                              | Incorrect placements will be removed.                |
+      | id_hintclearwrong_2                 | 1                                                    |
+      | id_hintshownumcorrect_2             | 1                                                    |
+      | id_hintclearwrong_3                 | 0                                                    |
+      | id_hintshownumcorrect_3             | 1                                                    |
diff --git a/question/type/ddimageortext/tests/behat/basic_test.feature b/question/type/ddimageortext/tests/behat/basic_test.feature
deleted file mode 100644 (file)
index 65e2019..0000000
+++ /dev/null
@@ -1,198 +0,0 @@
-@ou @ou_vle @qtype @qtype_ddimageortext
-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 ddimageortext (Drag and drop onto image) 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.
-
-    # Another way to test attempting this qtype while previewing it, it 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 ddimageortext 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 onto image" to "1"
-    Then I press "Add"
-    And I should see "Adding drag and drop onto image"
-    Then I set the field "Question name" to "Drag and drop onto image 001"
-    And I set the field "Question text" to "Identify the features in this cross-section."
-    And I set the field "General feedback" to "The locations are now labelled on the diagram below."
-    Given I upload "question/type/ddimageortext/tests/fixtures/oceanfloorbase.jpg" file to "Background image" filemanager
-
-    # Draggable items
-    Given I follow "Draggable items"
-    Then I press "Blanks for 3 more draggable items"
-
-    And I set the field "id_drags_0_dragitemtype" to "Draggable text"
-    And I set the field "id_draglabel_0" to "island<br/>arc"
-
-    And I set the field "id_drags_1_dragitemtype" to "Draggable text"
-    And I set the field "id_draglabel_1" to "mid-ocean<br/>ridge"
-
-    And I set the field "id_drags_2_dragitemtype" to "Draggable text"
-    And I set the field "id_draglabel_2" to "abyssal<br/>plain"
-
-    And I set the field "id_drags_3_dragitemtype" to "Draggable text"
-    And I set the field "id_draglabel_3" to "continental<br/>rise"
-
-    And I set the field "id_drags_4_dragitemtype" to "Draggable text"
-    And I set the field "id_draglabel_4" to "ocean<br/>trench"
-
-    And I set the field "id_drags_5_dragitemtype" to "Draggable text"
-    And I set the field "id_draglabel_5" to "continental<br/>slope"
-
-    And I set the field "id_drags_6_dragitemtype" to "Draggable text"
-    And I set the field "id_draglabel_6" to "mountain<br/>belt"
-
-    And I set the field "id_drags_7_dragitemtype" to "Draggable text"
-    And I set the field "id_draglabel_7" to "continental<br/>shelf"
-
-    # Drop zones
-    Given I follow "Drop zones"
-    Then I press "Blanks for 3 more drop zones"
-
-    And I set the field "id_drops_0_xleft" to "53"
-    And I set the field "id_drops_0_ytop" to "17"
-    And I set the field "id_drops_0_choice" to "7"
-
-    And I set the field "id_drops_1_xleft" to "172"
-    And I set the field "id_drops_1_ytop" to "2"
-    And I set the field "id_drops_1_choice" to "8"
-
-    And I set the field "id_drops_2_xleft" to "363"
-    And I set the field "id_drops_2_ytop" to "31"
-    And I set the field "id_drops_2_choice" to "5"
-
-    And I set the field "id_drops_3_xleft" to "440"
-    And I set the field "id_drops_3_ytop" to "13"
-    And I set the field "id_drops_3_choice" to "3"
-
-    And I set the field "id_drops_4_xleft" to "115"
-    And I set the field "id_drops_4_ytop" to "74"
-    And I set the field "id_drops_4_choice" to "6"
-
-    And I set the field "id_drops_5_xleft" to "210"
-    And I set the field "id_drops_5_ytop" to "94"
-    And I set the field "id_drops_5_choice" to "4"
-
-    And I set the field "id_drops_6_xleft" to "310"
-    And I set the field "id_drops_6_ytop" to "87"
-    And I set the field "id_drops_6_choice" to "1"
-
-    And I set the field "id_drops_7_xleft" to "479"
-    And I set the field "id_drops_7_ytop" to "84"
-    And I set the field "id_drops_7_choice" to "2"
-
-
-    And I press "id_submitbutton"
-    Then I should see "Drag and drop onto image 001"
-
-    # Preview it.
-    When I click on "Preview" "link" in the "Drag and drop onto image 001" "table_row"
-    And I switch to "questionpreview" window
-    Then I should see "Preview question: Drag and drop onto image 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 onto image 001"
-
-    # Edit the copy and verify the form field contents.
-    When I click on "Edit" "link" in the "Drag and drop onto image 001" "table_row"
-    Then the following fields match these values:
-      | Question name             | Drag and drop onto image 001                         |
-      | Question text             | Identify the features in this cross-section.         |
-      | General feedback          | The locations are now labelled on the diagram below. |
-
-     # Draggable items
-      | id_drags_0_dragitemtype | Draggable text        |
-      | id_draglabel_0          | island<br/>arc        |
-
-      | id_drags_1_dragitemtype | Draggable text        |
-      | id_draglabel_1          | mid-ocean<br/>ridge   |
-
-      | id_drags_2_dragitemtype | Draggable text        |
-      | id_draglabel_2          | abyssal<br/>plain     |
-
-      | id_drags_3_dragitemtype | Draggable text        |
-      | id_draglabel_3          | continental<br/>rise  |
-
-      | id_drags_4_dragitemtype | Draggable text        |
-      | id_draglabel_4          | ocean<br/>trench      |
-
-      | id_drags_5_dragitemtype | Draggable text        |
-      | id_draglabel_5          | continental<br/>slope |
-
-      | id_drags_6_dragitemtype | Draggable text        |
-      | id_draglabel_6          | mountain<br/>belt     |
-
-      | id_drags_7_dragitemtype | Draggable text        |
-      | id_draglabel_7          | continental<br/>shelf |
-
-     # Drop zones
-      | id_drops_0_xleft  | 53  |
-      | id_drops_0_ytop   | 17  |
-      | id_drops_0_choice | 7   |
-
-      | id_drops_1_xleft  | 172 |
-      | id_drops_1_ytop   | 2   |
-      | id_drops_1_choice | 8   |
-
-      | id_drops_2_xleft  | 363 |
-      | id_drops_2_ytop   | 31  |
-      | id_drops_2_choice | 5   |
-
-      | id_drops_3_xleft  | 440 |
-      | id_drops_3_ytop   | 13  |
-      | id_drops_3_choice | 3   |
-
-      | id_drops_4_xleft  | 115 |
-      | id_drops_4_ytop   | 74  |
-      | id_drops_4_choice | 6   |
-
-      | id_drops_5_xleft  | 210 |
-      | id_drops_5_ytop   | 94  |
-      | id_drops_5_choice | 4   |
-
-      | id_drops_6_xleft  | 310 |
-      | id_drops_6_ytop   | 87  |
-      | id_drops_6_choice | 1   |
-
-      | id_drops_7_xleft  | 479 |
-      | id_drops_7_ytop   | 84  |
-      | id_drops_7_choice | 2   |
-
-    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"
diff --git a/question/type/ddimageortext/tests/behat/behat_qtype_ddimageortext.php b/question/type/ddimageortext/tests/behat/behat_qtype_ddimageortext.php
new file mode 100644 (file)
index 0000000..a1a5239
--- /dev/null
@@ -0,0 +1,83 @@
+<?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 onto image.
+ *
+ * @package   qtype_ddimageortext
+ * @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 onto image question type.
+ *
+ * @copyright 2015 The Open University
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class behat_qtype_ddimageortext 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 '//div[contains(@class, " drag ") and contains(normalize-space(.), "' . $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($placenumber) {
+        return '//div[contains(@class, "dropzone ") and contains(@class, "place' . $placenumber . ' ")]';
+    }
+
+    /**
+     * Drag the drag item with the given text to the given space.
+     *
+     * @param string $dragitem the text of the item to drag.
+     * @param int $placenumber the number of the place to drop into.
+     *
+     * @Given /^I drag "(?P<drag_item>[^"]*)" to place "(?P<place_number>\d+)" in the drag and drop onto image question$/
+     * 
+     */
+    public function i_drag_to_place_in_the_drag_and_drop_onto_image_question($dragitem, $placenumber) {
+        $generalcontext = behat_context_helper::get('behat_general');
+        $generalcontext->i_drag_and_i_drop_it_in($this->drag_xpath($dragitem),
+                'xpath_element', $this->drop_xpath($placenumber), 'xpath_element');
+    }
+
+    /**
+     * Type some characters while focussed on a given drop box.
+     *
+     * @param string $keys the characters to type.
+     * @param int $placenumber the number of the place to drop into.
+     *
+     * @Given /^I type "(?P<keys>[^"]*)" on place "(?P<place_number>\d+)" in the drag and drop onto image question$/
+     */
+    public function i_type_on_place_in_the_drag_and_drop_onto_image_question($keys, $placenumber) {
+        $generalcontext = behat_context_helper::get('behat_general');
+        $generalcontext->i_type_into_the($keys, $this->drop_xpath($placenumber), 'xpath_element');
+    }
+}
diff --git a/question/type/ddimageortext/tests/behat/edit.feature b/question/type/ddimageortext/tests/behat/edit.feature
new file mode 100644 (file)
index 0000000..ca18b7e
--- /dev/null
@@ -0,0 +1,33 @@
+@ou @ou_vle @qtype @qtype_ddimageortext
+Feature: Test editing a drag and drop onto image questions
+  As a teacher
+  In order to be able to update my drag and drop onto image 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   | ddimageortext | Drag onto image | xsection |
+    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 onto image question
+    When I click on "Edit" "link" in the "Drag onto image" "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"
diff --git a/question/type/ddimageortext/tests/behat/export.feature b/question/type/ddimageortext/tests/behat/export.feature
new file mode 100644 (file)
index 0000000..ee2d80b
--- /dev/null
@@ -0,0 +1,37 @@
+@ou @ou_vle @qtype @qtype_ddimageortext
+Feature: Test exporting drag and drop onto image questions
+  As a teacher
+  In order to be able to reuse my drag and drop onto image 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   | ddimageortext | Drag onto image | xsection |
+    And I log in as "teacher1"
+    And I follow "Course 1"
+
+  @javascript
+  Scenario: Export a drag and drop onto image 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 "18500" and "19000" 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
@@ -1,24 +1,24 @@
 @ou @ou_vle @qtype @qtype_ddimageortext
-Feature: Test all the basic 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 onto image questions
+  As a teacher
+  In order to reuse drag and drop onto image 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 variable numeric sets question.
+  @javascript @_file_upload
+  Scenario: import drag and drop onto image 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/ddimageortext/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
diff --git a/question/type/ddimageortext/tests/behat/preview.feature b/question/type/ddimageortext/tests/behat/preview.feature
new file mode 100644 (file)
index 0000000..7fde499
--- /dev/null
@@ -0,0 +1,60 @@
+@ou @ou_vle @qtype @qtype_ddimageortext
+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   | ddimageortext | Drag onto image | xsection |
+    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 onto image" "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 "mountainbelt" to place "1" in the drag and drop onto image question
+    And I drag "continentalshelf" to place "2" in the drag and drop onto image question
+    And I drag "oceantrench" to place "3" in the drag and drop onto image question
+    And I drag "abyssalplain" to place "4" in the drag and drop onto image question
+    And I drag "continentalslope" to place "5" in the drag and drop onto image question
+    And I drag "continentalrise" to place "6" in the drag and drop onto image question
+    And I drag "islandarc" to place "7" in the drag and drop onto image question
+    And I drag "mid-oceanridge" to place "8" in the drag and drop onto image question
+    And I press "Submit and finish"
+    Then the state of "Identify the features" 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 onto image" "table_row"
+    And I switch to "questionpreview" window
+    And I wait "1" seconds
+    And I type "       " on place "1" in the drag and drop onto image question
+    And I type "       " on place "2" in the drag and drop onto image question
+    And I type "     " on place "3" in the drag and drop onto image question
+    And I type "   " on place "4" in the drag and drop onto image question
+    And I type "    " on place "5" in the drag and drop onto image question
+    And I type "   " on place "6" in the drag and drop onto image question
+    And I type " " on place "7" in the drag and drop onto image question
+    And I type " " on place "8" in the drag and drop onto image question
+    And I press "Submit and finish"
+    Then the state of "Identify the features" question is shown as "Correct"
+    And I should see "Mark 1.00 out of 1.00"
index 2068f61..864b511 100644 (file)
@@ -34,7 +34,7 @@ defined('MOODLE_INTERNAL') || die();
  */
 class qtype_ddimageortext_test_helper extends question_test_helper {
     public function get_test_questions() {
-        return array('fox', 'maths');
+        return array('fox', 'maths', 'xsection');
     }
 
     /**
@@ -127,4 +127,115 @@ class qtype_ddimageortext_test_helper extends question_test_helper {
 
         return $dd;
     }
+
+    /**
+     * @return stdClass date to create a ddimageortext question.
+     */
+    public function get_ddimageortext_question_form_data_xsection() {
+        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 = 'oceanfloorbase.jpg';
+        $fs->create_file_from_pathname($filerecord, $CFG->dirroot .
+                '/question/type/ddimageortext/tests/fixtures/oceanfloorbase.jpg');
+
+        $fromform->name = 'Geography cross-section';
+        $fromform->questiontext = array(
+            'text' => '<p>Identify the features in this cross-section by dragging the labels into the boxes.</p>
+                       <p><em>Use the mouse to drag the boxed words into the empty boxes. Alternatively, use the tab key to select an empty box, then use the space key to cycle through the options.</em></p>',
+            'format' => FORMAT_HTML,
+        );
+        $fromform->defaultmark = 1;
+        $fromform->generalfeedback = array(
+            'text' => '<p>More information about the major features of the Earth\'s surface can be found in Block 3, Section 6.2.</p>',
+            'format' => FORMAT_HTML,
+        );
+        $fromform->bgimage = $bgdraftitemid;
+        $fromform->shuffleanswers = 0;
+        $fromform->drags = array(
+            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
+            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
+            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
+            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
+            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
+            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
+            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
+            array('dragitemtype' => 'word', 'draggroup' => '1', 'infinite' => '0'),
+        );
+        $fromform->dragitem = array(0, 0, 0, 0, 0, 0, 0, 0);
+        $fromform->draglabel =
+        array(
+            'island<br/>arc',
+            'mid-ocean<br/>ridge',
+            'abyssal<br/>plain',
+            'continental<br/>rise',
+            'ocean<br/>trench',
+            'continental<br/>slope',
+            'mountain<br/>belt',
+            'continental<br/>shelf',
+        );
+        $fromform->drops = array(
+            array('xleft' => '53', 'ytop' => '17', 'choice' => '7', 'droplabel' => ''),
+            array('xleft' => '172', 'ytop' => '2', 'choice' => '8', 'droplabel' => ''),
+            array('xleft' => '363', 'ytop' => '31', 'choice' => '5', 'droplabel' => ''),
+            array('xleft' => '440', 'ytop' => '13', 'choice' => '3', 'droplabel' => ''),
+            array('xleft' => '115', 'ytop' => '74', 'choice' => '6', 'droplabel' => ''),
+            array('xleft' => '210', 'ytop' => '94', 'choice' => '4', 'droplabel' => ''),
+            array('xleft' => '310', 'ytop' => '87', 'choice' => '1', 'droplabel' => ''),
+            array('xleft' => '479', 'ytop' => '84', 'choice' => '2', 'droplabel' => ''),
+        );
+
+        test_question_maker::set_standard_combined_feedback_form_data($fromform);
+
+        $fromform->penalty ='0.3333333';
+        $fromform->hint = array(
+            array(
+                'text' => '<p>Incorrect placements will be removed.</p>',
+                'format' => FORMAT_HTML,
+            ),
+            array(
+                'text' => '<ul>
+                           <li>The abyssal plain is a flat almost featureless expanse of ocean floor 4km to 6km below sea-level.</li>
+                           <li>The continental rise is the gently sloping part of the ocean floor beyond the continental slope.</li>
+                           <li>The continental shelf is the gently sloping ocean floor just offshore from the land.</li>
+                           <li>The continental slope is the relatively steep part of the ocean floor beyond the continental shelf.</li>
+                           <li>A mid-ocean ridge is a broad submarine ridge several kilometres high.</li>
+                           <li>A mountain belt is a long range of mountains.</li>
+                           <li>An island arc is a chain of volcanic islands.</li>
+                           <li>An oceanic trench is a deep trough in the ocean floor.</li>
+                           </ul>',
+                'format' => FORMAT_HTML,
+            ),
+            array(
+                'text' => '<p>Incorrect placements will be removed.</p>',
+                'format' => FORMAT_HTML,
+            ),
+            array(
+                'text' => '<ul>
+                           <li>The abyssal plain is a flat almost featureless expanse of ocean floor 4km to 6km below sea-level.</li>
+                           <li>The continental rise is the gently sloping part of the ocean floor beyond the continental slope.</li>
+                           <li>The continental shelf is the gently sloping ocean floor just offshore from the land.</li>
+                           <li>The continental slope is the relatively steep part of the ocean floor beyond the continental shelf.</li>
+                           <li>A mid-ocean ridge is a broad submarine ridge several kilometres high.</li>
+                           <li>A mountain belt is a long range of mountains.</li>
+                           <li>An island arc is a chain of volcanic islands.</li>
+                           <li>An oceanic trench is a deep trough in the ocean floor.</li>
+                           </ul>',
+                'format' => FORMAT_HTML,
+            ),
+        );
+        $fromform->hintclearwrong = array(1, 0, 1, 0);
+        $fromform->hintshownumcorrect = array(1, 1, 1, 1);
+
+        return $fromform;
+    }
 }