Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ctp 3560 test fixes 2 #21

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions classes/models/coursework.php
Original file line number Diff line number Diff line change
Expand Up @@ -1706,14 +1706,14 @@ public function get_student_group($student) {

if ($this->grouping_id) {
$sql = "
SELECT groups.*
FROM {groups} groups
SELECT g.*
FROM {groups} g
INNER JOIN {groupings_groups} groupings
ON groups.id = groupings.groupid
ON g.id = groupings.groupid
INNER JOIN {groups_members} gm
ON gm.groupid = groups.id
ON gm.groupid = g.id
WHERE gm.userid = :userid
AND groups.courseid = :courseid
AND g.courseid = :courseid
AND groupings.groupingid = :grouping_id

LIMIT 1
Expand All @@ -1724,20 +1724,18 @@ public function get_student_group($student) {
'userid' => $student->id()];
} else {
$sql = "
SELECT groups.*
FROM {groups} groups
SELECT g.*
FROM {groups} g
INNER JOIN {groups_members} gm
ON gm.groupid = groups.id
ON gm.groupid = g.id
WHERE gm.userid = :userid
AND groups.courseid = :courseid
LIMIT 1
";
AND g.courseid = :courseid
LIMIT 1";
$params = [
'userid' => $student->id(),
'courseid' => $this->get_course()->id,
];
}

$group = $DB->get_record_sql($sql, $params);
return group::find($group);

Expand Down Expand Up @@ -2264,23 +2262,19 @@ public function get_allocatables() {
if ($this->is_configured_to_have_group_submissions()) {
if ($this->grouping_id) {
$sql = "
SELECT groups.*
FROM {groups} groups
SELECT g.*
FROM {groups} g
INNER JOIN {groupings_groups} groupings
ON groups.id = groupings.groupid
WHERE groups.courseid = :courseid
ON g.id = groupings.groupid
WHERE g.courseid = :courseid
AND groupings.groupingid = :grouping_id
";
$params = [
'grouping_id' => $this->grouping_id,
'courseid' => $this->get_course()->id,
];
} else {
$sql = "
SELECT groups.*
FROM {groups} groups
WHERE groups.courseid = :courseid
";
$sql = "SELECT * FROM {groups} WHERE courseid = :courseid";
$params = [
'courseid' => $this->get_course()->id,
];
Expand Down
32 changes: 16 additions & 16 deletions classes/warnings.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ public function students_in_mutiple_grouos() {
groupings.groupingid,
u.firstname,
u.lastname
FROM {groups} groups
FROM {groups} g
INNER JOIN {groups_members} gm
ON groups.id = gm.groupid
ON g.id = gm.groupid
INNER JOIN {groupings_groups} groupings
ON groups.id=groupings.groupid
ON g.id=groupings.groupid
INNER JOIN {user} u
ON u.id = gm.userid
WHERE groups.courseid = :courseid
WHERE g.courseid = :courseid
AND groupings.groupingid = :groupingid
GROUP BY gm.userid, groupings.groupingid, u.firstname, u.lastname)a
WHERE noofgroups > 1";
Expand All @@ -107,12 +107,12 @@ public function students_in_mutiple_grouos() {
count(gm.userid) as noofgroups,
u.firstname,
u.lastname
FROM {groups} groups
FROM {groups} g
INNER JOIN {groups_members} gm
ON gm.groupid = groups.id
ON gm.groupid = g.id
INNER JOIN {user} u
ON u.id = gm.userid
WHERE groups.courseid = :courseid
WHERE g.courseid = :courseid
GROUP BY gm.userid, u.firstname, u.lastname) a
WHERE noofgroups > 1";

Expand All @@ -132,13 +132,13 @@ public function students_in_mutiple_grouos() {
// Get group ids of these students
if ($this->coursework->grouping_id) {

$sql = "SELECT groups.id,groups.name
FROM {groups} groups
$sql = "SELECT g.id, g.name
FROM {groups} g
INNER JOIN {groupings_groups} groupings
ON groups.id = groupings.groupid
ON g.id = groupings.groupid
INNER JOIN {groups_members} gm
ON gm.groupid = groups.id
WHERE groups.courseid = :courseid
ON gm.groupid = g.id
WHERE g.courseid = :courseid
AND gm.userid = :userid
AND groupings.groupingid =:grouping_id";

Expand All @@ -148,11 +148,11 @@ public function students_in_mutiple_grouos() {
'userid' => $student->userid];
} else {

$sql = "SELECT groups.id,groups.name
FROM {groups} groups
$sql = "SELECT g.id, g.name
FROM {groups} g
INNER JOIN {groups_members} gm
ON gm.groupid = groups.id
WHERE groups.courseid = :courseid
ON gm.groupid = g.id
WHERE g.courseid = :courseid
AND gm.userid = :userid";

$params = [
Expand Down
5 changes: 3 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ function coursework_grade_item_update($coursework, $grades = null) {
throw new invalid_parameter_exception("Invalid type '$paramtype' for coursework");
}

if (get_class($coursework) != 'mod_coursework\models\coursework') {
// On activity rename, core will pass in stdClass object here, not a coursework.
if (get_class($coursework) == 'stdClass') {
// On activity rename, core will pass in stdClass object here.
// Otherwise expect coursework or coursework_groups_decorator to be passed.
$coursework = \mod_coursework\models\coursework::find($coursework);
}

Expand Down
55 changes: 7 additions & 48 deletions tests/behat/behat_mod_coursework.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,6 @@ private function get_first_assesor_stage() {
return reset($stages);
}

/**
*
*
* @param $rolename
* @return string
*/
private function make_role_name_into_variable_name($rolename) {
$rolename = str_replace('other ', 'other_', $rolename);
return str_replace(' ', '', $rolename);
}

/**
* Returns an xpath string to find a tag that has a class and contains some text.
*
Expand Down Expand Up @@ -1896,40 +1885,6 @@ public function there_is_some_general_feedback() {
$this->get_coursework()->save();
}

/**
* @Given /^(I|the ([\w ]+)) (?:has|have) graded the submission as assessor (\d+)$/
*
* @param $i
* @param string $rolename
* @param int $assessornumber
* @throws coding_exception
*/
public function the_other_teacher_has_graded_the_submission($i, $rolename = '', $assessornumber = 1) {
watson8 marked this conversation as resolved.
Show resolved Hide resolved

if ($i == 'I') {
$rolename = 'teacher';
} else {
// other editing teacher => other_editingteacher
$rolename = $this->make_role_name_into_variable_name($rolename);
}

if (empty($this->$rolename)) {
throw new coding_exception('no ' . $rolename . ' user was found');
}

/**
* @var $generator mod_coursework_generator
*/
$generator = testing_util::get_data_generator()->get_plugin_generator('mod_coursework');

$feedback = new stdClass();
$feedback->submissionid = $this->submission->id;
$feedback->assessorid = $this->$rolename->id;
$feedback->stage_identifier = 'assessor_'.$assessornumber;
$feedback->grade = 50;
$generator->create_feedback($feedback);
}

/**
* @Then /^I should( not)? see the other teacher\'s grade as assessor (\d+)$/
* @param bool $negate
Expand Down Expand Up @@ -2756,8 +2711,7 @@ public function i_should_see_that_the_submission_was_made_by_the_other_student($
* @throws coding_exception
*/
public function i_am_logged_in_as_a($rolename) {

$rolename = $this->make_role_name_into_variable_name($rolename);
$rolename = str_replace(' ', '', $rolename);

if (empty($this->$rolename)) {
$this->$rolename = $this->create_user($rolename);
Expand Down Expand Up @@ -2826,8 +2780,13 @@ protected function create_user($rolename, $displayname = '') {
$user = \mod_coursework\models\user::find($user);
$user->password = 'user' . $this->usersuffix;

$roleid = $DB->get_field('role', 'id', ['shortname' => $rolename], MUST_EXIST);
// If the role name starts with 'other_' here (e.g. 'other_teacher') we need to remove it.
$rolename = str_replace('other_', '', $rolename);
$roleid = $DB->get_field('role', 'id', ['shortname' => $rolename]);

if (!$roleid) {
throw new coding_exception("Cannot find role shortname '$rolename' in role table");
}
if (empty($this->course)) {
throw new coding_exception('Must have a course to enrol the user onto');
}
Expand Down
Loading