-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CONTRIB-7254 - Added behat automated test to aide easier regression t…
…esting. Note this commit does not cater for full coverage because of insufficient development time
- Loading branch information
1 parent
488deda
commit 2a024ab
Showing
6 changed files
with
396 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Behat student-related step definitions for My feedback plugin acceptance tests. | ||
* | ||
* @package report_myfeedback | ||
* @category test | ||
* @copyright 2019 Segun Babalola | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); | ||
|
||
use Behat\Gherkin\Node\TableNode as TableNode, | ||
Behat\Mink\Exception\ExpectationException as ExpectationException; | ||
|
||
/** | ||
* Student-related steps definitions. | ||
* | ||
* @package report_myfeedback | ||
* @category test | ||
* @copyright 2019 Segun Babalola | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class behat_myfeedback extends behat_base { | ||
|
||
/** | ||
* @Given /^I have a Moodle account with the following details:$/ | ||
*/ | ||
public function i_have_a_moodle_account_with_the_following_details(TableNode $table) { | ||
$this->execute("behat_data_generators::the_following_exist", ['users', $table]); | ||
} | ||
|
||
/** | ||
* @Given /^the following grades have been awarded to students for assignments:$/ | ||
*/ | ||
public function assign_grades_to_students_for_assignments(TableNode $table) { | ||
global $DB; | ||
$data = $table->getRows(); | ||
|
||
$colummappings = $this->extract_column_mappings($data); | ||
|
||
if (is_array($data) && (count($data) > 1)) { | ||
for ($i=1; $i < count($data); $i++) { | ||
$usernamestudent = $data[$i][$colummappings['student']]; | ||
$usernametutor = $data[$i][$colummappings['grader']]; | ||
$assigmentname = $data[$i][$colummappings['assignment']]; | ||
$assignedgrade = $data[$i][$colummappings['grade']]; | ||
|
||
$studentid = $DB->get_field('user', 'id',['username' => $usernamestudent], MUST_EXIST); | ||
$tutorid = $DB->get_field('user', 'id',['username' => $usernametutor], MUST_EXIST); | ||
$assignmentid = $DB->get_field('assign', 'id',['name' => $assigmentname], MUST_EXIST); | ||
|
||
// Create grade_items record | ||
$gradeassignment = new stdClass(); | ||
$gradeassignment->assignment = $assignmentid; | ||
$gradeassignment->grade = $assignedgrade; | ||
$gradeassignment->userid = $studentid; | ||
$gradeassignment->grader = $tutorid; | ||
|
||
$DB->insert_record('assign_grades', $gradeassignment); | ||
|
||
$gradeitemid = $DB->get_field('grade_items', 'id',['itemname' => $assigmentname], MUST_EXIST); | ||
|
||
// Create grade_grades record | ||
$gradeitem = new stdClass(); | ||
$gradeitem->itemid = $gradeitemid; | ||
$gradeitem->userid = $studentid; | ||
$gradeitem->rawgrade = $assignedgrade; | ||
$gradeitem->finalgrade = $assignedgrade; | ||
$gradeitem->feedback = 'Behat test grade entry for ' . $assigmentname; | ||
$DB->insert_record('grade_grades', $gradeitem); | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
private function extract_column_mappings($table) { | ||
$mappings = []; | ||
if (is_array($table) && count($table)) { | ||
$columnheadings = $table[0]; | ||
if (is_array($columnheadings)) { | ||
foreach ($columnheadings as $key => $col) { | ||
$mappings[$col] = $key; | ||
} | ||
} | ||
} | ||
|
||
return $mappings; | ||
} | ||
|
||
/** | ||
* @Given /^the user, "(?P<username_string>(?:[^"]|\\")*)", is granted departmental admin rights for the courses:$/ | ||
*/ | ||
public function user_is_granted_departmental_admin_rights($username, TableNode $courses) { | ||
// Create departmental admin role. | ||
$adminroledata[] = ['shortname', 'name', 'archetype']; | ||
$adminroledata[] = ['departmental_admin', 'Departmental Admin', 'manager']; | ||
|
||
$this->execute("behat_data_generators::the_following_exist", ['roles', new TableNode($adminroledata)]); | ||
|
||
// Assign departmental admin role to the username. | ||
$roleassigndata[] = ['role', 'contextlevel', 'user', 'reference']; | ||
$roleassigndata[] = ['departmental_admin', 'System', $username, '']; | ||
$this->execute("behat_data_generators::the_following_exist", ['role assigns', | ||
new TableNode($roleassigndata) | ||
]); | ||
|
||
// Grant the departmental admin role permissions to the appropriate capability required by my feedback plugin. | ||
// I'm not convinced this is the ideal way to setup dept admin link to users so will revisit in future. | ||
// For now, will only check that the "Departmental admin dashboard" tab. | ||
$coursedata = $courses->getRows(); | ||
$coursepermissions[] = ['capability', 'permission', 'role', 'contextlevel', 'reference']; | ||
|
||
if (is_array($coursedata) && (count($coursedata) > 1)){ | ||
for ($i=1; $i<count($coursedata); $i++) { | ||
$coursepermissions[] = [ | ||
'report/myfeedback:progadmin', | ||
'Allow', | ||
'departmental_admin', | ||
'Course', | ||
$coursedata[$i][0] | ||
]; | ||
} | ||
|
||
$this->execute("behat_data_generators::the_following_exist",['permission overrides', | ||
new TableNode($coursepermissions) | ||
]); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @Given /^the following personal tutors are assigned the following tutees:$/ | ||
* | ||
* @param TableNode $table | ||
* @throws Exception | ||
*/ | ||
public function the_following_personal_tutors_are_assigned_the_following_tutees(TableNode $table) { | ||
// Grant "report/myfeedback:personaltutor" to the personal tutor role | ||
$coursepermissions[] = ['capability', 'permission', 'role', 'contextlevel', 'reference']; | ||
$coursepermissions[] = ['report/myfeedback:personaltutor', 'Allow', 'personal_tutor', 'System', '']; | ||
|
||
$this->execute("behat_data_generators::the_following_exist",['permission overrides', | ||
new TableNode($coursepermissions) | ||
]); | ||
|
||
// Grant listed user accounts the personal tutor role | ||
$data[] = ['role', 'contextlevel', 'user', 'reference']; | ||
foreach ($table as $relationship) { | ||
$data[] = ['personal_tutor', 'User', $relationship['tutor'], $relationship['tutee']]; | ||
} | ||
$this->execute("behat_data_generators::the_following_exist", ['role assigns', new TableNode($data)]); | ||
} | ||
|
||
/** | ||
* @Given /^I should see the following students listed:$/ | ||
* | ||
* @param TableNode $table | ||
* @throws Exception | ||
*/ | ||
public function i_should_see_the_following_students_listed(TableNode $table) { | ||
$expectedstudents = $table->getRows(); | ||
$colummappings = $this->extract_column_mappings($expectedstudents); | ||
|
||
if (is_array($expectedstudents) && (count($expectedstudents) > 1)) { | ||
for ($i=1; $i < count($expectedstudents); $i++) { | ||
$studentfullname = $expectedstudents[$i][$colummappings['fullname']]; | ||
$xpath = "//tr//td//a[contains(text(),'{$studentfullname}')]"; | ||
|
||
if (!$this->getSession()->getDriver()->find($xpath)) { | ||
throw new ExpectationException($studentfullname . ' is not listed (as expected)', $this->getSession()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Turns editing mode on. | ||
* @Given /^I navigate to the My feedback plugin page$/ | ||
*/ | ||
public function i_navigate_to_the_My_feedback_plugin_page() { | ||
$url = new moodle_url('/report/myfeedback/index.php', []); | ||
$this->getSession()->visit($this->locate_path($url->out_as_local_url(false))); | ||
} | ||
|
||
/** | ||
* Check expected tab exists | ||
* | ||
* @Then /^I should see a tab named "(?P<tab_name_string>(?:[^"]|\\")*)"$/ | ||
* | ||
* @throws ExpectationException | ||
* @throws \Behat\Mink\Exception\DriverException | ||
* @throws \Behat\Mink\Exception\UnsupportedDriverActionException | ||
*/ | ||
public function i_should_see_a_tab_named($tabname) { | ||
$xpath = "//div//ul//li//a[contains(text(),'{$tabname}')]"; | ||
if (!$this->getSession()->getDriver()->find($xpath)) { | ||
throw new ExpectationException("Cannot find tab named " . $tabname, $this->getSession()); | ||
} | ||
} | ||
|
||
/** | ||
* Click through to a named tab | ||
* | ||
* @When /^I click the tab titled "(?P<tab_name_string>(?:[^"]|\\")*)"$/ | ||
*/ | ||
public function i_click_tab_titled($tabtitle) { | ||
$this->execute("behat_general::click_link", $tabtitle); | ||
} | ||
|
||
/** | ||
* Submit "My Students" search form | ||
* | ||
* @When /^I search for tutees using "(?P<tab_name_string>(?:[^"]|\\")*)"$/ | ||
*/ | ||
public function i_submit_search_form_For_students($crieria) { | ||
$searchbox = $this->find_field("searchu"); | ||
$searchbox->setValue($crieria); | ||
$submit = $this->find_button('Search'); | ||
$submit->press(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# TODO: Investigate possibility of using language string variables in test steps. | ||
@mod @mod_feedback @javascript | ||
Feature: Tutors and administrators need access to grades and feedback to monitor student progress throughout the year | ||
In order to support students through the year | ||
As a tutor (i.e. personal, or module tutor) or administrator | ||
I need to view grades and feedback for assessment activities based on my assignment to student, course or department. | ||
|
||
Background: | ||
Given the following "users" exist: | ||
| username | firstname | lastname | email | | ||
| student1 | Student | One | student1@example.com | | ||
| student2 | Student | Two | student2@example.com | | ||
| student3 | Student | Three | student3@example.com | | ||
| tutor1 | Module | Tutor1 | tutor1@example.com | | ||
| tutor2 | Module | Tutor2 | tutor2@example.com | | ||
| tutor3 | Module | Tutor3 | tutor3@example.com | | ||
| deptAdmin| Department| Admin | admin@example.com | | ||
And the following "categories" exist: | ||
| name | category | idnumber | | ||
| Course admins Category | 0 | report_myfeedback | | ||
And the following "courses" exist: | ||
| fullname | shortname | category | | ||
| Course 1 | C1 | report_myfeedback | | ||
| Course 2 | C2 | 0 | | ||
| Course 3 | C3 | report_myfeedback | | ||
And the following "course enrolments" exist: | ||
| user | course | role | | ||
| student1 | C1 | student | | ||
| student2 | C2 | student | | ||
| student3 | C2 | student | | ||
| student3 | C3 | student | | ||
| tutor1 | C1 | teacher | | ||
| tutor2 | C2 | teacher | | ||
| tutor3 | C3 | teacher | | ||
And the following "roles" exist: | ||
| shortname | name | archetype | | ||
| personal_tutor | Personal Tutor | editingteacher | | ||
And the following personal tutors are assigned the following tutees: | ||
| tutor | tutee | | ||
| tutor3 | student1 | | ||
| tutor3 | student3 | | ||
And the user, "deptAdmin", is granted departmental admin rights for the courses: | ||
| coursename | | ||
| C1 | | ||
| C3 | | ||
And the following "scales" exist: | ||
| name | scale | | ||
| Feedback scale | Disappointing, Good, Very good, Excellent | | ||
And the following "activities" exist: | ||
| activity | name | intro | course | idnumber | grade | | ||
| assign | C1 assignment | Assignment for course C1 | C1 | assign1 | Feedback scale | | ||
| assign | C2 assignment | Assignment for course C2 | C2 | assign2 | Feedback scale | | ||
| assign | C3 assignment | Assignment for course C3 | C3 | assign3 | Feedback scale | | ||
And the following grades have been awarded to students for assignments: | ||
| student | assignment | grade | grader | | ||
| student1 | C1 assignment | 1 | tutor1 | | ||
| student2 | C2 assignment | 2 | tutor2 | | ||
| student2 | C3 assignment | 3 | tutor2 | | ||
| student3 | C3 assignment | 2 | tutor3 | | ||
|
||
@javascript | ||
Scenario: Module tutors need to be able to view grades of students taking courses they are recorded as a tutor for | ||
When I log in as "tutor1" | ||
And I navigate to the My feedback plugin page | ||
Then I should see a tab named "Module tutor dashboard" | ||
And I should see a tab named "My students" | ||
When I click the tab titled "My students" | ||
And I search for tutees using "%" | ||
Then I should see the following students listed: | ||
| username | email | fullname | | ||
| student1 | student1@example.com | Student One | | ||
|
||
@javascript | ||
Scenario: Personal tutors need to be able to view grades of their tutees. For instance, when a Personal Tutor is | ||
preparing for a meeting with a student during which the tutor wishes to discuss the student's performance | ||
(perhaps focusing on areas where they are doing well and where there is room for improvement.) | ||
When I log in as "tutor3" | ||
And I navigate to the My feedback plugin page | ||
Then I should see a tab named "Module tutor dashboard" | ||
And I should see a tab named "My students" | ||
When I click the tab titled "My students" | ||
And I search for tutees using "%" | ||
Then I should see the following students listed: | ||
| username | email | fullname | | ||
| student1 | student1@example.com | Student One | | ||
| student3 | student3@example.com | Student Three | | ||
|
||
@javascript | ||
Scenario: A Departmental Admin wishes to log-in and check student performance across a cohort so that they can identify | ||
any potential students struggling (and subsequently raise these instances of concerning performance with module Tutors.) | ||
When I log in as "deptAdmin" | ||
And I navigate to the My feedback plugin page | ||
Then I should see a tab named "Departmental admin dashboard" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# TODO: Investigate possibility of using language string variables in test steps. | ||
@mod @mod_feedback @javascript | ||
Feature: Students checking their own academic progress throughout the year | ||
In order to give me an accurate and holistic view of my strengths, weaknesses, academic performance and progress | ||
As a student | ||
I need to view grades and feedback for assessment activities across modules in a single-view report. | ||
|
||
Background: | ||
Given I have a Moodle account with the following details: | ||
| username | firstname | lastname | email | | ||
| student1 | First | Student | student1@example.com | | ||
| tutor1 | Module | Tutor1 | tutor1@example.com | | ||
And the following "categories" exist: | ||
| name | category | idnumber | | ||
| Course admins Category | 0 | report_myfeedback | | ||
And the following "courses" exist: | ||
| fullname | shortname | format | | ||
| Course 1 | C1 | topics | | ||
And the following "course enrolments" exist: | ||
| user | course | role | | ||
| student1 | C1 | student | | ||
| tutor1 | C1 | teacher | | ||
And the following "scales" exist: | ||
| name | scale | | ||
| Feedback scale | Disappointing, Good, Very good, Excellent | | ||
And the following "activities" exist: | ||
| activity | name | intro | course | idnumber | grade | | ||
| assign | C1 assignment | Assignment for course C1 | C1 | assign1 | Feedback scale | | ||
And the following grades have been awarded to students for assignments: | ||
| student | assignment | grade | grader | | ||
| student1 | C1 assignment | 1 | tutor1 | | ||
|
||
@javascript | ||
Scenario: Access my personalised My feedback report | ||
When I log in as "student1" | ||
And I navigate to the My feedback plugin page | ||
Then I should see a tab named "Overview" | ||
And I should see a tab named "Feedback comments" | ||
|
||
@javascript | ||
Scenario: A student is preparing for a meeting with a Career Advisor or Personal Tutor, and the student wishes to use | ||
the comments field to reflect on employability before the meeting. | ||
When I log in as "student1" | ||
And I navigate to the My feedback plugin page | ||
And I should see a tab named "Feedback comments" | ||
When I click the tab titled "Feedback comments" | ||
Then I should see "C1 assignment" in the "feedbackcomments" "table" | ||
And I should see "Add notes" in the "feedbackcomments" "table" |
Oops, something went wrong.