diff --git a/grade/report/history/tests/behat/basic_functionality.feature b/grade/report/history/tests/behat/basic_functionality.feature new file mode 100644 index 00000000000..09acaec3826 --- /dev/null +++ b/grade/report/history/tests/behat/basic_functionality.feature @@ -0,0 +1,102 @@ +@gradereport @gradereport_history +Feature: A teacher checks the grade history report in a course + In order to check the history of the grades + As a teacher + I need to check that the history report is correctly displaying changes + + @javascript + Scenario: Check the history report displays results correctly + Given the following "courses" exist: + | fullname | shortname | category | groupmode | + | Course 1 | C1 | 0 | 1 | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@asd.com | + | teacher2 | Teacher | 2 | teacher2@asd.com | + | student1 | Student | 1 | student1@asd.com | + | student2 | Student | 2 | student2@asd.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | teacher2 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Assignment" to section "1" and I fill the form with: + | Assignment name | The greatest assignment ever | + | Description | Write a behat test for Moodle - it's amazing! | + And I add a "Assignment" to section "1" and I fill the form with: + | Assignment name | Rewarding assignment | + | Description | After writing your behat test go grab a beer! | + And I follow "Grades" + And I turn editing mode on + And I give the grade "50.00" to the user "Student 1" for the grade item "The greatest assignment ever" + And I give the grade "60.00" to the user "Student 1" for the grade item "Rewarding assignment" + And I give the grade "50.00" to the user "Student 2" for the grade item "The greatest assignment ever" + And I give the grade "60.00" to the user "Student 2" for the grade item "Rewarding assignment" + And I press "Save changes" + And I log out + And I log in as "teacher2" + And I follow "Course 1" + And I follow "Grades" + And I turn editing mode on + And I give the grade "70.00" to the user "Student 1" for the grade item "The greatest assignment ever" + And I give the grade "80.00" to the user "Student 1" for the grade item "Rewarding assignment" + And I give the grade "70.00" to the user "Student 2" for the grade item "The greatest assignment ever" + And I give the grade "80.00" to the user "Student 2" for the grade item "Rewarding assignment" + And I press "Save changes" + When I follow "Grade history" + Then the following should exist in the "gradereport_history" table: + | First name/Surname | Grade item | Original grade | Revised grade | Grader | + | Student 1 | The greatest assignment ever | | 50.00 | Teacher 1 | + | Student 1 | Rewarding assignment | | 60.00 | Teacher 1 | + | Student 2 | The greatest assignment ever | | 50.00 | Teacher 1 | + | Student 2 | Rewarding assignment | | 60.00 | Teacher 1 | + | Student 1 | The greatest assignment ever | 50.00 | 70.00 | Teacher 2 | + | Student 1 | Rewarding assignment | 60.00 | 80.00 | Teacher 2 | + | Student 2 | The greatest assignment ever | 50.00 | 70.00 | Teacher 2 | + | Student 2 | Rewarding assignment | 60.00 | 80.00 | Teacher 2 | + # Test filtering by student. + And I press "Select users" + And I set the field with xpath "//form/input[@class='usp-search-field']" to "Student 1" + And I press "Search" + And I set the field with xpath "//div[@class='usp-checkbox']/input" to "1" + And I press "Finish selecting users" + And I press "Submit" + And the following should exist in the "gradereport_history" table: + | First name/Surname | Grade item | Original grade | Revised grade | Grader | + | Student 1 | The greatest assignment ever | | 50.00 | Teacher 1 | + | Student 1 | Rewarding assignment | | 60.00 | Teacher 1 | + | Student 1 | The greatest assignment ever | 50.00 | 70.00 | Teacher 2 | + | Student 1 | Rewarding assignment | 60.00 | 80.00 | Teacher 2 | + And the following should not exist in the "gradereport_history" table: + | Student 2 | The greatest assignment ever | | 50.00 | Teacher 1 | + | Student 2 | Rewarding assignment | | 60.00 | Teacher 1 | + | Student 2 | The greatest assignment ever | 50.00 | 70.00 | Teacher 2 | + | Student 2 | Rewarding assignment | 60.00 | 80.00 | Teacher 2 | + # Test filtering by assignment. + And I click on "The greatest assignment ever" "option" in the "#id_itemid" "css_element" + And I press "Submit" + And the following should exist in the "gradereport_history" table: + | First name/Surname | Grade item | Original grade | Revised grade | Grader | + | Student 1 | The greatest assignment ever | | 50.00 | Teacher 1 | + | Student 1 | The greatest assignment ever | 50.00 | 70.00 | Teacher 2 | + And the following should not exist in the "gradereport_history" table: + | Student 1 | Rewarding assignment | | 60.00 | Teacher 1 | + | Student 1 | Rewarding assignment | 60.00 | 80.00 | Teacher 2 | + # Test filtering by grader. + And I click on "Teacher 1" "option" in the "#id_grader" "css_element" + And I press "Submit" + And the following should exist in the "gradereport_history" table: + | First name/Surname | Grade item | Original grade | Revised grade | Grader | + | Student 1 | The greatest assignment ever | | 50.00 | Teacher 1 | + And the following should not exist in the "gradereport_history" table: + | Student 1 | The greatest assignment ever | 50.00 | 70.00 | Teacher 2 | + # Test filtering by revised grades. + And I click on "id_revisedonly" "checkbox" + And I press "Submit" + And the following should exist in the "gradereport_history" table: + | First name/Surname | Grade item | Original grade | Revised grade | Grader | + | Student 1 | The greatest assignment ever | | 50.00 | Teacher 1 | diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index d29a9cc659c..f3a17ffc98d 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -1000,9 +1000,14 @@ class behat_general extends behat_base { $tablenode = $this->get_selected_node('table', $table); $tablexpath = $tablenode->getXpath(); - // Check if column exists, it can be in thead or tbody first row. - $columnheaderxpath = $tablexpath . "[thead/tr/th[normalize-space(.)='$column'] | " - . "tbody/tr[1]/th[normalize-space(.)='" . $column . "']]"; + // Header can be in thead or tbody (first row), following xpath should work. + $theadheaderxpath = "thead/tr[1]/th[(normalize-space(.)='" . $column . "' or a[normalize-space(text())='" . + $column . "'])]"; + $tbodyheaderxpath = "tbody/tr[1]/td[(normalize-space(.)='" . $column . "' or a[normalize-space(text())='" . + $column . "'])]"; + + // Check if column exists. + $columnheaderxpath = $tablexpath . "[" . $theadheaderxpath . " | " . $tbodyheaderxpath . "]"; $columnheader = $this->getSession()->getDriver()->find($columnheaderxpath); if (empty($columnheader)) { $columnexceptionmsg = $column . '" in table "' . $table . '"'; @@ -1016,17 +1021,16 @@ class behat_general extends behat_base { // Following conditions were considered before finding column count. // 1. Table header can be in thead/tr/th or tbody/tr/td[1]. // 2. First column can have th (Gradebook -> user report), so having lenient sibling check. - $columnpositionxpath = "/child::*[position() = count(" . $tablexpath . "/thead/tr[1]/th[normalize-space(.)='" . - $column . "']/preceding-sibling::*) + 1]"; - $columnvaluexpath = $rowxpath . $columnpositionxpath . "[text()[contains(normalize-space(.),'" . $value . "')]]"; - + $columnpositionxpath = "/child::*[position() = count(" . $tablexpath . "/" . $theadheaderxpath . + "/preceding-sibling::*) + 1]"; + $columnvaluexpath = $rowxpath . $columnpositionxpath . "[contains(normalize-space(.),'" . $value . "')]"; // Looks for the requested node inside the container node. $coumnnode = $this->getSession()->getDriver()->find($columnvaluexpath); if (empty($coumnnode)) { // Check if tbody/tr[1] contains header selector. - $columnpositionxpath = "/child::*[position() = count(" . $tablexpath . "/tbody/tr[1]/td[normalize-space(.)='" . - $column . "']/preceding-sibling::*) + 1]"; - $columnvaluexpath = $rowxpath . $columnpositionxpath . "[text()[contains(normalize-space(.),'" . $value . "')]]"; + $columnpositionxpath = "/child::*[position() = count(" . $tablexpath . "/" . $tbodyheaderxpath . + "/preceding-sibling::*) + 1]"; + $columnvaluexpath = $rowxpath . $columnpositionxpath . "[contains(normalize-space(.),'" . $value . "')]"; $coumnnode = $this->getSession()->getDriver()->find($columnvaluexpath); if (empty($coumnnode)) { $locatorexceptionmsg = $value . '" in "' . $row . '" row with column "' . $column;