weekly release 4.5dev
[moodle.git] / question / tests / behat / edit_questions.feature
blob0414ff30d3439c564569ec498cd225d4103acbf8
1 @core @core_question @javascript
2 Feature: A teacher can edit questions in the question bank
3   In order to improve my questions
4   As a teacher
5   I need to be able to edit questions
7   Background:
8     Given the following "users" exist:
9       | username | firstname | lastname | email |
10       | teacher1 | Teacher | 1 | teacher1@example.com |
11     And the following "courses" exist:
12       | fullname | shortname | format |
13       | Course 1 | C1 | weeks |
14     And the following "course enrolments" exist:
15       | user | course | role |
16       | teacher1 | C1 | editingteacher |
17     And the following "question categories" exist:
18       | contextlevel | reference | name           |
19       | Course       | C1        | Test questions |
20     And the following "questions" exist:
21       | questioncategory | qtype | name                       | questiontext                  |
22       | Test questions   | essay | Test question to be edited | Write about whatever you want |
23     And I am on the "Course 1" "core_question > course question bank" page logged in as "teacher1"
25   @javascript
26   Scenario: Edit a previously created question
27     When I am on the "Test question to be edited" "core_question > edit" page logged in as "teacher1"
28     And I set the following fields to these values:
29       | Question name | Edited question name |
30       | Question text | Write a lot about what you want |
31     And I press "id_submitbutton"
32     Then I should see "Edited question name"
33     And I should not see "Test question to be edited"
34     And I should see "Teacher 1"
36   Scenario: Edit a previously created question without permission 'moodle/question:moveall' and 'moodle/question:movemine'
37     Given I log in as "admin"
38     And the following "permission overrides" exist:
39       | capability               | permission | role           | contextlevel | reference |
40       | moodle/question:movemine | Prevent    | editingteacher | System       |           |
41       | moodle/question:moveall  | Prevent    | editingteacher | System       |           |
42     When I am on the "Test question to be edited" "core_question > edit" page logged in as "teacher1"
43     And I set the following fields to these values:
44       | Question name | Edited question name            |
45       | Question text | Write a lot about what you want |
46     And I press "id_submitbutton"
47     Then I should see "Edited question name"
48     And I should not see "Test question to be edited"
49     And I should see "Teacher 1"
51   Scenario: Edit a previously created question without permission 'moodle/question:editall' and 'moodle/question:editmine'
52     Given I log in as "admin"
53     And the following "permission overrides" exist:
54       | capability               | permission | role           | contextlevel | reference |
55       | moodle/question:editmine | Prevent    | editingteacher | System       |           |
56       | moodle/question:editall  | Prevent    | editingteacher | System       |           |
57     When I am on the "Test question to be edited" "core_question > edit" page logged in as "teacher1"
58     And I set the following fields to these values:
59       | Question name | Edited question name            |
60       | Question text | Write a lot about what you want |
61     And I press "id_submitbutton"
62     Then I should see "You don't have permission to edit questions from here."
64   Scenario: Editing a question can be cancelled
65     When I am on the "Test question to be edited" "core_question > edit" page logged in as "teacher1"
66     And I set the field "Question name" to "Edited question name"
67     And I press "Cancel"
68     Then I should see "Test question to be edited"
69     And I should see "Admin User"
71   Scenario: A question can have its idnumber removed
72     Given the following "questions" exist:
73       | questioncategory | qtype | name                   | idnumber |
74       | Test questions   | essay | Question with idnumber | frog     |
75     When I am on the "Course 1" "core_question > course question bank" page logged in as "teacher1"
76     Then I should see "frog" in the "Question with idnumber" "table_row"
77     When I choose "Edit question" action for "Question with idnumber" in the question bank
78     And I set the field "ID number" to ""
79     And I press "id_submitbutton"
80     Then I should not see "frog" in the "Question with idnumber" "table_row"
82   Scenario: If the question type is no longer installed, then most edit actions are not present
83     Given the following "questions" exist:
84       | questioncategory | qtype       | name            | questiontext    |
85       | Test questions   | missingtype | Broken question | Write something |
86     When I am on the "Course 1" "core_question > course question bank" page logged in as "teacher1"
87     Then the "Edit question" item should not exist in the "Edit" action menu of the "Broken question" "table_row"
88     And the "Duplicate" item should not exist in the "Edit" action menu of the "Broken question" "table_row"
89     And the "Preview" item should not exist in the "Edit" action menu of the "Broken question" "table_row"
90     And the "Export as XML" item should not exist in the "Edit" action menu of the "Broken question" "table_row"
91     And the "Manage tags" item should exist in the "Edit" action menu of the "Broken question" "table_row"
92     And the "Delete" item should exist in the "Edit" action menu of the "Broken question" "table_row"