Skip to content

Commit

Permalink
Merge branch 'MDL-64357_master' of git://github.com/markn86/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Dec 11, 2018
2 parents dd202b5 + e56eb26 commit 85b0a91
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Expand Up @@ -546,9 +546,7 @@ public static function delete_orphans_ltiservice_gradebookservices_rows() {
$sql = "DELETE
FROM {ltiservice_gradebookservices}
WHERE gradeitemid NOT IN (SELECT id
FROM {grade_items} gi
WHERE gi.itemtype = 'mod'
AND gi.itemmodule = 'lti')";
FROM {grade_items} gi)";
$DB->execute($sql);
}

Expand Down
42 changes: 42 additions & 0 deletions mod/lti/service/gradebookservices/tests/task_cleanup_test.php
Expand Up @@ -100,4 +100,46 @@ public function test_cleanup_task() {

$this->assertEquals($gradeitem2->id, $gradebookserviceitem->gradeitemid);
}

/**
* Test the cleanup task with a manual grade item.
*/
public function test_cleanup_task_with_manual_item() {
global $CFG, $DB;

// This is required when running the unit test in isolation.
require_once($CFG->libdir . '/gradelib.php');

// Create a manual grade item for a course.
$course = $this->getDataGenerator()->create_course();
$params = [
'courseid' => $course->id,
'itemtype' => 'manual'
];
$gradeitem = new grade_item($params);
$gradeitem->insert();

// Insert it into the 'ltiservice_gradebookservices' table.
$data = new stdClass();
$data->gradeitemid = $gradeitem->id;
$data->courseid = $course->id;
$DB->insert_record('ltiservice_gradebookservices', $data);

// Run the task.
$task = new \ltiservice_gradebookservices\task\cleanup_task();
$task->execute();

// Check it still exist.
$this->assertEquals(1, $DB->count_records('ltiservice_gradebookservices'));

// Delete the manual item.
$gradeitem->delete();

// Run the task again.
$task = new \ltiservice_gradebookservices\task\cleanup_task();
$task->execute();

// Check it has been removed.
$this->assertEquals(0, $DB->count_records('ltiservice_gradebookservices'));
}
}

0 comments on commit 85b0a91

Please sign in to comment.