MDL-79863 qtype_ordering: Ordering qtype: write some Behat tests

This commit is contained in:
M Kassaei 2018-11-16 14:21:59 +00:00 committed by Mathew May
parent 2020628f6d
commit e3fd1ad067
9 changed files with 362 additions and 0 deletions

View File

@ -0,0 +1,38 @@
@qtype @qtype_ordering
Feature: Test creating an Ordering question
As a teacher
In order to test my students
I need to be able to create an Ordering question
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 am on "Course 1" course homepage
And I navigate to "Question bank" in current page administration
@javascript
Scenario: Create an Ordering question with 6 draggable items
When I add a "Ordering" question filling the form with:
| Question name | Ordering-001 |
| Question text | Put the words in correct order. |
| General feedback | One two three four five six |
| id_answer_0 | one |
| id_answer_1 | two |
| id_answer_2 | three |
| id_answer_3 | four |
| id_answer_4 | five |
| id_answer_5 | six |
| For any correct response | Your answer is correct |
| For any partially correct response | Your answer is partially correct |
| For any incorrect response | Your answer is incorrect |
| Hint 1 | This is your first hint |
| Hint 2 | This is your second hint |
Then I should see "Ordering-001"

View File

@ -0,0 +1,45 @@
@qtype @qtype_ordering
Feature: Test duplicating a quiz containing a Ordering question
As a teacher
In order to re-use my courses containing Ordering 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 | ordering | Moodle | moodle |
And the following "activities" exist:
| activity | name | course | idnumber |
| quiz | Test quiz | C1 | quiz1 |
And quiz "Test quiz" contains the following questions:
| Moodle | 1 |
And I log in as "admin"
And I am on "Course 1" course homepage
@javascript
Scenario: Backup and restore a course containing an Ordering 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" in current page administration
And I click on "Edit" "link" in the "Moodle" "table_row"
Then the following fields match these values:
| Question name | Moodle |
| Question text | Put these words in order. |
| General feedback | The correct answer is "Modular Object Oriented Dynamic Learning Environment". |
| id_answer_0 | Modular |
| id_answer_1 | Object |
| id_answer_2 | Oriented |
| id_answer_3 | Dynamic |
| id_answer_4 | Learning |
| id_answer_5 | Environment |
| 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. |

View File

@ -0,0 +1,69 @@
<?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/>.
/**
* Behat steps definitions for the ordering question type.
*
* @package qtype_ordering
* @category test
* @copyright 2018 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 ordering question type.
*
* @copyright 2018 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_qtype_ordering extends behat_base {
/**
* Get the xpath for a given item by label.
* @param string $label the text of the item to drag.
* @return string the xpath expression.
*/
protected function item_xpath_by_lable($label) {
return '//li[contains(@class, "sortableitem ") and contains(normalize-space(.), "' . $this->escape($label) . '")]';
}
/**
* Get the xpath for a given drop box.
* @param string $position the number of place to drop it.
* @return string the xpath expression.
*/
protected function item_xpath_by_position($position) {
return '//li[contains(@class, "sortableitem ")][' . $position . ']';
}
/**
* Drag the drag item with the given text to the given space.
*
* @param string $label the text of the item to drag.
* @param int $position the number of the position to drop it at.
*
* @Given /^I drag "(?P<label>[^"]*)" to space "(?P<position>\d+)" in the ordering question$/
*/
public function i_drag_to_space_in_the_drag_and_drop_into_text_question($label, $position) {
$generalcontext = behat_context_helper::get('behat_general');
$generalcontext->i_drag_and_i_drop_it_in($this->item_xpath_by_lable($label),
'xpath_element', $this->item_xpath_by_position($position), 'xpath_element');
}
}

View File

@ -0,0 +1,37 @@
@qtype @qtype_ordering
Feature: Test editing an Ordering question
As a teacher
In order to be able to update my Ordering question
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 | ordering | Ordering for editing | moodle |
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to "Question bank" in current page administration
@javascript @_switch_window
Scenario: Edit an Ordering question
When I click on "Edit" "link" in the "Ordering for editing" "table_row"
And I set the following fields to these values:
| Question name ||
And I press "id_submitbutton"
Then I should see "You must supply a value here."
When I set the following fields to these values:
| Question name | Edited Ordering |
And I press "id_submitbutton"
Then I should see "Edited Ordering"

View File

@ -0,0 +1,36 @@
@qtype @qtype_ordering
Feature: Test exporting Ordering questions
As a teacher
In order to be able to reuse my Ordering 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 | ordering | Moodle | moodle |
And I log in as "teacher1"
And I am on "Course 1" course homepage
@javascript
Scenario: Export a Matching question
When I navigate to "Question bank > Export" in current page administration
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
Then following "click here" should download between "1700" and "1950" 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

View File

@ -0,0 +1,27 @@
@qtype @qtype_ordering
Feature: Test importing Ordering questions
As a teacher
In order to reuse Ordering questions
I need to import 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 I log in as "teacher1"
And I am on "Course 1" course homepage
@javascript @_file_upload
Scenario: import Matching question.
When I navigate to "Question bank > Import" in current page administration
And I set the field "id_format_xml" to "1"
And I upload "question/type/ordering/tests/fixtures/testquestion.moodle.xml" file to "Import" filemanager
And I press "id_submitbutton"
And I press "Continue"
Then I should see "dd-ordering 1"

View File

@ -0,0 +1,48 @@
@qtype @qtype_ordering
Feature: Preview an Ordering question
As a teacher
In order to check my Ordering 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 | layouttype |
| Test questions | ordering | ordering-001 | moodle | 0 |
Given I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to "Question bank" in current page administration
@javascript @_switch_window
Scenario: Preview an Ordering question and submit a correct response.
When I click on "Preview" "link" in the "ordering-001" "table_row"
And I switch to "questionpreview" window
And I set the field "How questions behave" to "Immediate feedback"
And I press "Start again with these options"
# The test was unreliable unless if an item rendomly stared in the right place.
# So we first moved each item to the last place, before putting it into the right place.
And I drag "Modular" to space "6" in the ordering question
And I drag "Modular" to space "1" in the ordering question
And I drag "Object" to space "6" in the ordering question
And I drag "Object" to space "2" in the ordering question
And I drag "Oriented" to space "6" in the ordering question
And I drag "Oriented" to space "3" in the ordering question
And I drag "Dynamic" to space "6" in the ordering question
And I drag "Dynamic" to space "4" in the ordering question
And I drag "Learning" to space "6" in the ordering question
And I drag "Learning" to space "5" in the ordering question
And I press "Submit and finish"
Then the state of "Put these words in order." question is shown as "Correct"
And I should see "Mark 1.00 out of 1.00"
And I switch to the main window

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<quiz>
<!-- question: 0 -->
<question type="category">
<category>
<text>$course$/Test questions</text>
</category>
</question>
<!-- question: 1357 -->
<question type="ordering">
<name>
<text>dd-ordering 1</text>
</name>
<questiontext format="html">
<text>Put these words in order.</text>
</questiontext>
<generalfeedback format="html">
<text><![CDATA[<p>The correct answer is "Modular Object Oriented Dynamic Learning Environment".</p>]]></text>
</generalfeedback>
<defaultgrade>1.0000000</defaultgrade>
<penalty>0.3333333</penalty>
<hidden>0</hidden>
<idnumber>dd1</idnumber>
<layouttype>HORIZONTAL</layouttype>
<selecttype>ALL</selecttype>
<selectcount>0</selectcount>
<gradingtype>ABSOLUTE_POSITION</gradingtype>
<showgrading>SHOW</showgrading>
<correctfeedback format="html">
<text>Your answer is correct.</text>
</correctfeedback>
<partiallycorrectfeedback format="html">
<text>Your answer is partially correct.</text>
</partiallycorrectfeedback>
<incorrectfeedback format="html">
<text>Your answer is incorrect.</text>
</incorrectfeedback>
<answer fraction="1.0000000" format="moodle_auto_format">
<text>Modular</text>
</answer>
<answer fraction="2.0000000" format="moodle_auto_format">
<text>Object</text>
</answer>
<answer fraction="3.0000000" format="moodle_auto_format">
<text>Oriented</text>
</answer>
<answer fraction="4.0000000" format="moodle_auto_format">
<text>Dynamic</text>
</answer>
<answer fraction="5.0000000" format="moodle_auto_format">
<text>Learning</text>
</answer>
<answer fraction="6.0000000" format="moodle_auto_format">
<text>Environment</text>
</answer>
</question>
</quiz>

View File

@ -24,6 +24,9 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/question/type/ordering/question.php');
/**
* Test helper for the ordering question type.