diff --git a/question/engine/tests/helpers.php b/question/engine/tests/helpers.php index 551633823e7..f596ab037de 100644 --- a/question/engine/tests/helpers.php +++ b/question/engine/tests/helpers.php @@ -27,7 +27,8 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; -require_once(dirname(__FILE__) . '/../lib.php'); +require_once(__DIR__ . '/../lib.php'); +require_once($CFG->dirroot . '/lib/phpunit/lib.php'); /** diff --git a/question/tests/behat/copy_questions.feature b/question/tests/behat/copy_questions.feature index 8dd7d10c3a0..b83f6396aab 100644 --- a/question/tests/behat/copy_questions.feature +++ b/question/tests/behat/copy_questions.feature @@ -1,11 +1,10 @@ @core @core_question Feature: A teacher can duplicate questions in the question bank - In order to reuse questions and modify duplicated questions + In order to reuse questions As a teacher - I need to duplicate questions + I need to duplicate questions and make small changes - @javascript - Scenario: copy a previously created question + Background: Given the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@asd.com | @@ -15,15 +14,18 @@ Feature: A teacher can duplicate questions in the question bank And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | - And I log in as "admin" - And I follow "Course 1" - And I add a "Essay" question filling the form with: - | Question name | Test question to be copied | - | Question text | Write about whatever you want | - And I log out + And the following "question categories" exist: + | contextlevel | reference | name | + | Course | C1 | Test questions | + And the following "questions" exist: + | questioncategory | qtype | name | questiontext | + | Test questions | essay | Test question to be copied | Write about whatever you want | And I log in as "teacher1" And I follow "Course 1" - And I follow "Question bank" + And I navigate to "Questions" node in "Course administration > Question bank" + + @javascript + Scenario: Duplicating a previously created question When I click on "Duplicate" "link" in the "Test question to be copied" "table_row" And I set the following fields to these values: | Question name | Duplicated question name | @@ -31,10 +33,18 @@ Feature: A teacher can duplicate questions in the question bank And I press "id_submitbutton" Then I should see "Duplicated question name" And I should see "Test question to be copied" - And I should see "Teacher 1" in the ".categoryquestionscontainer tbody tr.r0 .creatorname" "css_element" - And I should see "Admin User" in the ".categoryquestionscontainer tbody tr.r1 .creatorname" "css_element" - And I click on "Duplicate" "link" in the "Duplicated question name" "table_row" - And the field "Question name" matches value "Duplicated question name (copy)" + And "Duplicated question name" row "Last modified by" column of "categoryquestions" table should contain "Teacher 1" + And "Test question to be copied" row "Created by" column of "categoryquestions" table should contain "Admin User" + + @javascript + Scenario: Duplicated questions automatically get a new name suggested + When I click on "Duplicate" "link" in the "Test question to be copied" "table_row" + Then the field "Question name" matches value "Test question to be copied (copy)" + + @javascript + Scenario: The duplicate operation can be cancelled + When I click on "Duplicate" "link" in the "Test question to be copied" "table_row" And I press "Cancel" - Then I should see "Duplicated question name" - And I should see "Test question to be copied" + Then I should see "Test question to be copied" + And the field "Select a category" matches value "Test questions (1)" + diff --git a/question/tests/behat/delete_questions.feature b/question/tests/behat/delete_questions.feature index 3b1765af076..5f5874212aa 100644 --- a/question/tests/behat/delete_questions.feature +++ b/question/tests/behat/delete_questions.feature @@ -14,33 +14,44 @@ Feature: A teacher can delete questions in the question bank 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 | questiontext | + | Test questions | essay | Test question to be deleted | Write about whatever you want | And I log in as "teacher1" And I follow "Course 1" + And I navigate to "Questions" node in "Course administration > Question bank" @javascript - Scenario: Delete a question not used in a quiz - And I navigate to "Questions" node in "Course administration > Question bank" - And I add a "Essay" question filling the form with: - | Question name | Test question to be deleted | - | Question text | Write about whatever you want | - And I click on "Delete" "link" in the "Test question to be deleted" "table_row" - When I press "Continue" + Scenario: A question not used anywhere can really be deleted + When I click on "Delete" "link" in the "Test question to be deleted" "table_row" + And I press "Continue" + And I click on "Also show old questions" "checkbox" Then I should not see "Test question to be deleted" + @javascript + Scenario: Deleting a question can be cancelled + When I click on "Delete" "link" in the "Test question to be deleted" "table_row" + And I press "Cancel" + Then I should see "Test question to be deleted" + @javascript Scenario: Delete a question used in a quiz - Given I turn editing mode on + Given I follow "Course 1" + And I turn editing mode on And I add a "Quiz" to section "1" and I fill the form with: | Name | Test quiz | And I add a "True/False" question to the "Test quiz" quiz with: - | Question name | Test question to be deleted | - | Question text | Write about whatever you want | + | Question name | Test used question to be deleted | + | Question text | Write about whatever you want | And I navigate to "Questions" node in "Course administration > Question bank" - And I click on "Delete" "link" in the "Test question to be deleted" "table_row" - When I press "Continue" - Then I should not see "Test question to be deleted" + When I click on "Delete" "link" in the "Test used question to be deleted" "table_row" + And I press "Continue" + Then I should not see "Test used question to be deleted" And I click on "Also show old questions" "checkbox" - And I should see "Test question to be deleted" + And I should see "Test used question to be deleted" And I follow "Course 1" And I follow "Test quiz" And I click on "Preview quiz now" "button" diff --git a/question/tests/behat/edit_questions.feature b/question/tests/behat/edit_questions.feature index b5269bd802c..74ade58e584 100644 --- a/question/tests/behat/edit_questions.feature +++ b/question/tests/behat/edit_questions.feature @@ -1,11 +1,10 @@ @core @core_question Feature: A teacher can edit questions in the question bank - In order to refine questions contents + In order to improve my questions As a teacher - I need to edit questions + I need to be able to edit questions - @javascript @_switch_window - Scenario: Edit a previously created question + Background: Given the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@asd.com | @@ -15,15 +14,18 @@ Feature: A teacher can edit questions in the question bank And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | - And I log in as "admin" - And I follow "Course 1" - And I add a "Essay" question filling the form with: - | Question name | Test question to be edited | - | Question text | Write about whatever you want | - And I log out + And the following "question categories" exist: + | contextlevel | reference | name | + | Course | C1 | Test questions | + And the following "questions" exist: + | questioncategory | qtype | name | questiontext | + | Test questions | essay | Test question to be edited | Write about whatever you want | And I log in as "teacher1" And I follow "Course 1" - And I follow "Question bank" + And I navigate to "Questions" node in "Course administration > Question bank" + + @javascript + Scenario: Edit a previously created question When I click on "Edit" "link" in the "Test question to be edited" "table_row" And I set the following fields to these values: | Question name | Edited question name | @@ -31,13 +33,14 @@ Feature: A teacher can edit questions in the question bank And I press "id_submitbutton" Then I should see "Edited question name" And I should not see "Test question to be edited" - And I should see "Admin User" in the ".categoryquestionscontainer tbody .creatorname" "css_element" - And I should see "Teacher 1" in the ".categoryquestionscontainer tbody .modifiername" "css_element" - And I click on "Edit" "link" in the "Edited question name" "table_row" - And the field "Question name" matches value "Edited question name" + And "Edited question name" row "Created by" column of "categoryquestions" table should contain "Admin User" + And "Edited question name" row "Last modified by" column of "categoryquestions" table should contain "Teacher 1" + + @javascript + Scenario: Editing a question can be cancelled + When I click on "Edit" "link" in the "Test question to be edited" "table_row" + And I set the field "Question name" to "Edited question name" And I press "Cancel" - And I click on "Preview" "link" in the "Edited question name" "table_row" - And I switch to "questionpreview" window - And I should see "Edited question name" - And I should see "Write a lot about what you want" - And I switch to the main window + Then I should see "Test question to be edited" + And "Test question to be edited" row "Created by" column of "categoryquestions" table should contain "Admin User" + And "Test question to be edited" row "Last modified by" column of "categoryquestions" table should contain "Admin User" diff --git a/question/tests/behat/preview_question.feature b/question/tests/behat/preview_question.feature index f453e2e8b40..52dfe29683e 100644 --- a/question/tests/behat/preview_question.feature +++ b/question/tests/behat/preview_question.feature @@ -1,11 +1,10 @@ -@core @core_question @_switch_window +@core @core_question Feature: A teacher can preview questions in the question bank In order to ensure the questions are properly created As a teacher I need to preview the questions - @javascript - Scenario: Preview a previously created question + Background: Given the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@asd.com | @@ -15,47 +14,67 @@ Feature: A teacher can preview questions in the question bank 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 | + | Test questions | numerical | Test question to be previewed | And I log in as "teacher1" And I follow "Course 1" - And I add a "Numerical" question filling the form with: - | Question name | Test question to be previewed | - | Question text | How much is 1 + 1 | - | answer[0] | 2 | - | fraction[0] | 100% | - | answer[1] | * | - | fraction[1] | None | - + And I navigate to "Questions" node in "Course administration > Question bank" When I click on "Preview" "link" in the "Test question to be previewed" "table_row" And I switch to "questionpreview" window - And I set the following fields to these values: - | Whether correct | Shown | - | How questions behave | Deferred feedback | - And I press "Start again with these options" - Then I should see "How much is 1 + 1" + @javascript @_switch_window + Scenario: Question preview shows the question and other information + Then the state of "What is pi to two d.p.?" question is shown as "Not yet answered" + And I should see "Marked out of 1.00" And I should see "Technical information" And I should see "Attempt options" And I should see "Display options" - And I set the field "Answer:" to "1" + @javascript @_switch_window + Scenario: Preview lets the teacher see what happens when an answer is saved + When I set the field "Answer:" to "1" And I press "Save" - And the state of "How much is 1 + 1" question is shown as "Answer saved" + Then the state of "What is pi to two d.p.?" question is shown as "Answer saved" + @javascript @_switch_window + Scenario: Preview lets the teacher see what happens when an answer is submitted + When I set the field "Answer:" to "3.14" And I press "Submit and finish" - And the state of "How much is 1 + 1" question is shown as "Incorrect" + Then the state of "What is pi to two d.p.?" question is shown as "Correct" - And I press "Start again" - And the state of "How much is 1 + 1" question is shown as "Not yet answered" - - And I press "Fill in correct responses" - And the field "Answer:" matches value "2" - And the state of "How much is 1 + 1" question is shown as "Answer saved" - - And I set the field "Whether correct" to "Not shown" + @javascript @_switch_window + Scenario: Preview lets the teacher see what happens with different review options + Given I set the field "Answer:" to "3.14" + And I press "Submit and finish" + When I set the field "Whether correct" to "Not shown" + And I set the field "Decimal places in grades" to "5" And I press "Update display options" - And the state of "How much is 1 + 1" question is shown as "Answer saved" + Then the state of "What is pi to two d.p.?" question is shown as "Complete" + And I should see "1.00000" + @javascript @_switch_window + Scenario: Preview lets the teacher see what happens with different behaviours + When I set the field "How questions behave" to "Immediate feedback" + And I set the field "Marked out of" to "3" + And I press "Start again with these options" + And I set the field "Answer:" to "3.1" + And I press "Check" + Then the state of "What is pi to two d.p.?" question is shown as "Incorrect" + And I should see "Mark 0.00 out of 3.00" + And I should see "Not accurate enough." + + @javascript @_switch_window + Scenario: Preview lets the teacher "Start again" while previewing + Given I set the field "Answer:" to "1" And I press "Submit and finish" - And the state of "How much is 1 + 1" question is shown as "Complete" + When I press "Start again" + Then the state of "What is pi to two d.p.?" question is shown as "Not yet answered" - And I switch to the main window + @javascript @_switch_window + Scenario: Preview lets the teacher "Fill in correct response" while previewing + When I press "Fill in correct responses" + Then the field "Answer:" matches value "3.14" diff --git a/question/tests/behat/question_categories.feature b/question/tests/behat/question_categories.feature index 3d2f26fe92d..4bf4b839405 100644 --- a/question/tests/behat/question_categories.feature +++ b/question/tests/behat/question_categories.feature @@ -1,8 +1,8 @@ @core @core_question Feature: A teacher can put questions in categories in the question bank - In order to organize their questions + In order to organize my questions As a teacher - I need to put questions in categories + I create and edit categories and move questions between them Background: Given the following "users" exist: @@ -14,50 +14,75 @@ Feature: A teacher can put questions in categories in the question bank And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | + And the following "question categories" exist: + | contextlevel | reference | questioncategory | name | + | Course | C1 | Top | Default for C1 | + | Course | C1 | Default for C1 | Subcategory | + | Course | C1 | Top | Used category | + And the following "questions" exist: + | questioncategory | qtype | name | questiontext | + | Used category | essay | Test question to be moved | Write about whatever you want | And I log in as "teacher1" And I follow "Course 1" - # Add 2 test categories. - And I follow "Question bank" - And I follow "Categories" + + @javascript + Scenario: A new question category can be created + When I navigate to "Categories" node in "Course administration > Question bank" And I set the following fields to these values: - | Name | New Category 1 | - | Parent category | Top | - And I press "id_submitbutton" + | Name | New Category 1 | + | Parent category | Top | + | Category info | Created as a test | + And I press "submitbutton" + Then I should see "New Category 1 (0)" + And I should see "Created as a test" in the "New Category 1" "list_item" + + @javascript + Scenario: A question category can be edited + When I navigate to "Categories" node in "Course administration > Question bank" + And I click on "Edit" "link" in the "Subcategory" "list_item" And I set the following fields to these values: - | Name | New Category 2 | - | Parent category | Top | - And I press "id_submitbutton" - # Add test question. - And I add a "Essay" question filling the form with: - | Question name | my test question | - | Question text | my test question | - | Category | New Category 1 | + | Name | New name | + | Category info | I was edited | + And I press "Save changes" + Then I should see "New name" + And I should see "I was edited" in the "New name" "list_item" + + @javascript + Scenario: An empty question category can be deleted + When I navigate to "Categories" node in "Course administration > Question bank" + And I click on "Delete" "link" in the "Subcategory" "list_item" + Then I should not see "Subcategory" + + @javascript + Scenario: An non-empty question category can be deleted if you move the contents elsewhere + When I navigate to "Categories" node in "Course administration > Question bank" + And I click on "Delete" "link" in the "Used category" "list_item" + And I should see "The category 'Used category' contains 1 questions" + And I press "Save in category" + Then I should not see "Used category" + And I should see "Default for C1 (1)" @javascript Scenario: Move a question between categories via the question page - When I set the field "Select a category" to "New Category 1 (1)" - And I click on "my test question" "checkbox" in the "my test question" "table_row" - And I set the field "Question category" to "New Category 2" + When I navigate to "Questions" node in "Course administration > Question bank" + And I set the field "Select a category" to "Used category" + And I click on "Test question to be moved" "checkbox" in the "Test question to be moved" "table_row" + And I set the field "Question category" to "Subcategory" And I press "Move to >>" - Then I should see "my test question" - And the "Select a category" select box should contain "New Category 2 (1)" - And the "Select a category" select box should contain "New Category 1" - And the "Select a category" select box should not contain "New Category 1 (1)" + Then I should see "Test question to be moved" + And the field "Select a category" matches value "Subcategory (1)" + And the "Select a category" select box should contain "Used category" + And the "Select a category" select box should not contain "Used category (1)" @javascript Scenario: Move a question between categories via the question settings page - When I click on "Edit" "link" in the "my test question" "table_row" + When I navigate to "Questions" node in "Course administration > Question bank" + And I set the field "Select a category" to "Used category" + And I click on "Edit" "link" in the "Test question to be moved" "table_row" And I click on "Use this category" "checkbox" - And I set the field "Save in category" to "New Category 2" + And I set the field "Save in category" to "Subcategory" And I press "id_submitbutton" - Then I should see "my test question" - And the "Select a category" select box should contain "New Category 2 (1)" - And the "Select a category" select box should not contain "New Category 1 (1)" - - @javascript - Scenario: Delete a question category - When I follow "Categories" - And I click on "Delete" "link" in the "//a[text()='New Category 1']/parent::b/parent::li" "xpath_element" - Then I should see "The category 'New Category 1' contains 1 questions" - And I press "Save in category" - And I should not see "New Category 1" + Then I should see "Test question to be moved" + And the field "Select a category" matches value "Subcategory (1)" + And the "Select a category" select box should contain "Used category" + And the "Select a category" select box should not contain "Used category (1)" diff --git a/question/tests/behat/sort_questions.feature b/question/tests/behat/sort_questions.feature index bbecb555a9d..4b0b7cb1ae0 100644 --- a/question/tests/behat/sort_questions.feature +++ b/question/tests/behat/sort_questions.feature @@ -1,11 +1,10 @@ @core @core_question -Feature: A teacher can sort questions in the question bank - In order to order the question bank's questions +Feature: The questions in the question bank can be sorted in various ways + In order to see what questions I have As a teacher - I need to sort the questions list using different sort orders + I want to view them in different orders - @javascript - Scenario: Sort using question name, question type and created by sort order links + Background: Given the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@asd.com | @@ -15,39 +14,54 @@ Feature: A teacher can sort questions in the question bank And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | - And I log in as "admin" - And I follow "Course 1" - And I add a "Essay" question filling the form with: - | Question name | A question 1 name | - | Question text | A question 1 text | - And I log out + And the following "question categories" exist: + | contextlevel | reference | name | + | Course | C1 | Test questions | + And the following "questions" exist: + | questioncategory | qtype | name | user | questiontext | + | Test questions | essay | A question 1 name | admin | Question 1 text | + | Test questions | essay | B question 2 name | teacher1 | Question 2 text | + | Test questions | numerical | C question 3 name | teacher1 | Question 3 text | And I log in as "teacher1" And I follow "Course 1" - And I add a "Essay" question filling the form with: - | Question name | B question 2 name | - | Question text | B question 2 text | - And I add a "Numerical" question filling the form with: - | Question name | C question 3 name | - | Question text | C question 3 text | - | answer[0] | 2 | - | fraction[0] | 100% | - | answer[1] | 1 | - | fraction[1] | None | + And I navigate to "Questions" node in "Course administration > Question bank" + + @javascript + Scenario: The questions are sorted by type by default + Then "A question 1 name" "checkbox" should appear before "C question 3 name" "checkbox" + + @javascript + Scenario: The questions can be sorted in reverse order by type + When I follow "Sort by Question type descending" + Then "C question 3 name" "checkbox" should appear before "A question 1 name" "checkbox" + + @javascript + Scenario: The questions can be sorted by name When I follow "Sort by Question ascending" Then "A question 1 name" "checkbox" should appear before "B question 2 name" "checkbox" And "B question 2 name" "checkbox" should appear before "C question 3 name" "checkbox" + + @javascript + Scenario: The questions can be sorted in reverse order by name + When I follow "Sort by Question ascending" And I follow "Sort by Question descending" - And "C question 3 name" "checkbox" should appear before "B question 2 name" "checkbox" + Then "C question 3 name" "checkbox" should appear before "B question 2 name" "checkbox" And "B question 2 name" "checkbox" should appear before "A question 1 name" "checkbox" - And I follow "Sort by Question type ascending" - And "A question 1 name" "checkbox" should appear before "C question 3 name" "checkbox" - And I follow "Sort by Question type descending" - And "C question 3 name" "checkbox" should appear before "A question 1 name" "checkbox" - And I follow "Sort by First name ascending" - And "A question 1 name" "checkbox" should appear before "B question 2 name" "checkbox" + + @javascript + Scenario: The questions can be sorted by creator name + When I follow "Sort by First name ascending" + Then "A question 1 name" "checkbox" should appear before "B question 2 name" "checkbox" + + @javascript + Scenario: The questions can be sorted in reverse order by creator name + When I follow "Sort by First name ascending" And I follow "Sort by First name descending" - And "B question 2 name" "checkbox" should appear before "A question 1 name" "checkbox" - And I click on "Show question text in the question list" "checkbox" - And I should see "A question 1 text" - And I should see "B question 2 text" - And I should see "C question 3 text" + Then "B question 2 name" "checkbox" should appear before "A question 1 name" "checkbox" + + @javascript + Scenario: The question text can be shown in the list of questions + When I click on "Show question text in the question list" "checkbox" + Then I should see "Question 1 text" + And I should see "Question 2 text" + And I should see "Question 3 text"