Skip to content

Commit

Permalink
Merge branch 'MDL-68915-master' of https://github.com/sharidas/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Jun 10, 2021
2 parents 226c1d7 + 25ea1f8 commit 4af7195
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/form/modgrade.php
Expand Up @@ -240,6 +240,13 @@ public function _createElements() {
$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', '', '<br />');
}
Expand Down
56 changes: 56 additions & 0 deletions 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
49 changes: 49 additions & 0 deletions 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
51 changes: 51 additions & 0 deletions 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
54 changes: 54 additions & 0 deletions 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

0 comments on commit 4af7195

Please sign in to comment.