diff --git a/lib/form/modgrade.php b/lib/form/modgrade.php index 410bb17b9e7..479d9c8ed8d 100644 --- a/lib/form/modgrade.php +++ b/lib/form/modgrade.php @@ -240,6 +240,13 @@ class MoodleQuickForm_modgrade extends MoodleQuickForm_group { $label = html_writer::tag('label', $this->maxgradeformelement->getLabel(), array('for' => $this->maxgradeformelement->getAttribute('id'))); $this->_elements[] = $this->createFormElement('static', 'pointlabel', '', $label); + + // Check if there are grades and if so then disable maxgradeformelement. + if ($this->hasgrades) { + // If it has grades then disable it. + $this->maxgradeformelement->updateAttributes(['disabled' => 'disabled']); + } + $this->_elements[] = $this->maxgradeformelement; $this->_elements[] = $this->createFormElement('static', 'pointspacer', '', '
'); } diff --git a/lib/form/tests/behat/graderescale_for_database_pointscale.feature b/lib/form/tests/behat/graderescale_for_database_pointscale.feature new file mode 100644 index 00000000000..97b363cdbf8 --- /dev/null +++ b/lib/form/tests/behat/graderescale_for_database_pointscale.feature @@ -0,0 +1,56 @@ +@mod @mod_data @core_grades @core_form +Feature: Using the database activities which support point scale + validate if we can change the maximum grade when users are graded + As a teacher + I need to know whether I can not edit value of Maximum grade input field + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | groupmode | + | Course 1 | C1 | 0 | 1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "activities" exist: + | activity | name | intro | course | idnumber | + | data | Test database name | n | C1 | data1 | + + @javascript + Scenario: Database rescale grade should not be possible when users are graded + Given I log in as "teacher1" + And I am on "Course 1" course homepage + And I add a "Text input" field to "Test database name" database and I fill the form with: + | Field name | Test field name | + | Field description | Test field description | + And I follow "Templates" + And I wait until the page is ready + And I am on "Course 1" course homepage + And I follow "Test database name" + And I navigate to "Edit settings" in current page administration + And I expand all fieldsets + And I set the field "Ratings > Aggregate type" to "Count of ratings" + And I set the field "Ratings > Type" to "Point" + And I press "Save and return to course" + And I log out + Given I log in as "student1" + And I am on "Course 1" course homepage + And I add an entry to "Test database name" database with: + | Test field name | Student original entry | + | Test field name | Student original entry 2 | + And I press "Save and view" + And I log out + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I follow "Test database name" + And I follow "View single" + And I set the field "rating" to "51" + And I am on "Course 1" course homepage + And I follow "Test database name" + When I navigate to "Edit settings" in current page administration + And I expand all fieldsets + Then the "Maximum grade" "field" should be disabled diff --git a/lib/form/tests/behat/graderescale_for_forum_pointscale.feature b/lib/form/tests/behat/graderescale_for_forum_pointscale.feature new file mode 100644 index 00000000000..ca2f4db1ca5 --- /dev/null +++ b/lib/form/tests/behat/graderescale_for_forum_pointscale.feature @@ -0,0 +1,49 @@ +@mod @mod_forum @core_grades @core_form +Feature: Using the forum activities which support point scale + validate if we can change the maximum grade when users are graded + As a teacher + I need to know whether I can not edit value of Maximum grade input field + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | groupmode | + | Course 1 | C1 | 0 | 1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "activity" exists: + | course | C1 | + | activity | forum | + | name | Test forum name | + | description | Test forum description | + | idnumber | forum1 | + + @javascript + Scenario: Forum rescale grade should not be possible when users are graded + Given I log in as "student1" + And I am on "Course 1" course homepage + And I add a new discussion to "Test forum name" forum with: + | Subject | Discussion subject | + | Message | Test post in forum 1 | + And I log out + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I follow "Test forum name" + And I navigate to "Edit settings" in current page administration + And I expand all fieldsets + And I set the field "Ratings > Aggregate type" to "Count of ratings" + And I set the field "Ratings > Type" to "Point" + And I press "Save and return to course" + And I follow "Test forum name" + And I follow "Discussion subject" + And I set the field "rating" to "30" + And I am on "Course 1" course homepage + And I follow "Test forum name" + When I navigate to "Edit settings" in current page administration + And I expand all fieldsets + Then the "Maximum grade" "field" should be disabled diff --git a/lib/form/tests/behat/graderescale_for_glossary_pointscale.feature b/lib/form/tests/behat/graderescale_for_glossary_pointscale.feature new file mode 100644 index 00000000000..441d23373f7 --- /dev/null +++ b/lib/form/tests/behat/graderescale_for_glossary_pointscale.feature @@ -0,0 +1,51 @@ +@mod @mod_glossary @core_grades @core_form +Feature: Using the glossary activities which support point scale + validate if we can change the maximum grade when users are graded + As a teacher + I need to know whether I can not edit value of Maximum grade input field + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | groupmode | + | Course 1 | C1 | 0 | 1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "activity" exists: + | course | C1 | + | activity | glossary | + | name | Test glossary name | + | description | Test glossary description | + | idnumber | glossary1 | + + @javascript + Scenario: Glossary rescale grade should not be possible when users are graded + Given I log in as "student1" + And I am on "Course 1" course homepage + And I follow "Test glossary name" + And I press "Add a new entry" + And I set the following fields to these values: + | Concept | Testing score | + | Definition | Scoring high on tests | + And I press "Save changes" + And I log out + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I follow "Test glossary name" + And I navigate to "Edit settings" in current page administration + And I expand all fieldsets + And I set the field "Ratings > Aggregate type" to "Count of ratings" + And I set the field "Ratings > Type" to "Point" + And I press "Save and return to course" + And I follow "Test glossary name" + And I set the field "rating" to "50" + And I am on "Course 1" course homepage + And I follow "Test glossary name" + When I navigate to "Edit settings" in current page administration + And I expand all fieldsets + Then the "Maximum grade" "field" should be disabled diff --git a/lib/form/tests/behat/graderescale_for_lesson_pointscale.feature b/lib/form/tests/behat/graderescale_for_lesson_pointscale.feature new file mode 100644 index 00000000000..f791014925b --- /dev/null +++ b/lib/form/tests/behat/graderescale_for_lesson_pointscale.feature @@ -0,0 +1,54 @@ +@mod @mod_lesson @core_grades @core_form +Feature: Using the lesson activities which support point scale + validate if we can change the maximum grade when users are graded + As a teacher + I need to know whether I can not edit value of Maximum grade input field + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | groupmode | + | Course 1 | C1 | 0 | 1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "activity" exists: + | course | C1 | + | activity | lesson | + | name | Test lesson name | + | intro | Test forum description | + | idnumber | lesson1 | + + @javascript + Scenario: Lesson rescale grade should not be possible when users are graded + Given I log in as "teacher1" + And I am on "Course 1" course homepage + And I follow "Test lesson name" + And I follow "Add a question page" + And I set the field "Select a question type" to "Numerical" + And I press "Add a question page" + And I set the following fields to these values: + | Page title | Numerical question | + | Page contents | What is 1 + 2? | + | id_answer_editor_0 | 3 | + | id_jumpto_0 | End of lesson | + | id_enableotheranswers | 1 | + | id_jumpto_6 | Next page | + And I press "Save page" + And I log out + And I log in as "student1" + And I am on "Course 1" course homepage + And I follow "Test lesson name" + And I set the field "Your answer" to "5" + And I press "Submit" + And I log out + And I log in as "teacher1" + And I am on "Course 1" course homepage + And I follow "Test lesson name" + When I navigate to "Edit settings" in current page administration + And I expand all fieldsets + Then the "Maximum grade" "field" should be disabled