From e3fd1ad067fe4ecb64baf421db633858f7a33470 Mon Sep 17 00:00:00 2001 From: M Kassaei Date: Fri, 16 Nov 2018 14:21:59 +0000 Subject: [PATCH] MDL-79863 qtype_ordering: Ordering qtype: write some Behat tests --- question/type/ordering/tests/behat/add.feature | 38 ++++++++++++ .../tests/behat/backup_and_restore.feature | 45 ++++++++++++++ .../ordering/tests/behat/behat_qtype_ordering.php | 69 ++++++++++++++++++++++ question/type/ordering/tests/behat/edit.feature | 37 ++++++++++++ question/type/ordering/tests/behat/export.feature | 36 +++++++++++ question/type/ordering/tests/behat/import.feature | 27 +++++++++ question/type/ordering/tests/behat/preview.feature | 48 +++++++++++++++ .../tests/fixtures/testquestion.moodle.xml | 59 ++++++++++++++++++ question/type/ordering/tests/helper.php | 3 + 9 files changed, 362 insertions(+) create mode 100644 question/type/ordering/tests/behat/add.feature create mode 100644 question/type/ordering/tests/behat/backup_and_restore.feature create mode 100644 question/type/ordering/tests/behat/behat_qtype_ordering.php create mode 100644 question/type/ordering/tests/behat/edit.feature create mode 100644 question/type/ordering/tests/behat/export.feature create mode 100644 question/type/ordering/tests/behat/import.feature create mode 100644 question/type/ordering/tests/behat/preview.feature create mode 100644 question/type/ordering/tests/fixtures/testquestion.moodle.xml diff --git a/question/type/ordering/tests/behat/add.feature b/question/type/ordering/tests/behat/add.feature new file mode 100644 index 00000000000..17322e03f05 --- /dev/null +++ b/question/type/ordering/tests/behat/add.feature @@ -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" diff --git a/question/type/ordering/tests/behat/backup_and_restore.feature b/question/type/ordering/tests/behat/backup_and_restore.feature new file mode 100644 index 00000000000..d97a5c3e87e --- /dev/null +++ b/question/type/ordering/tests/behat/backup_and_restore.feature @@ -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. | diff --git a/question/type/ordering/tests/behat/behat_qtype_ordering.php b/question/type/ordering/tests/behat/behat_qtype_ordering.php new file mode 100644 index 00000000000..d1deda37293 --- /dev/null +++ b/question/type/ordering/tests/behat/behat_qtype_ordering.php @@ -0,0 +1,69 @@ +. + +/** + * 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