Skip to content

Commit

Permalink
Fixing PHPUnit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaboesch committed Aug 15, 2024
1 parent 3afeb33 commit 471b675
Show file tree
Hide file tree
Showing 31 changed files with 109 additions and 82 deletions.
2 changes: 1 addition & 1 deletion lang/ar/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'ar'
* Strings for component 'plagiarism_turnitin', language 'ar'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/cs/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'cs'
* Strings for component 'plagiarism_turnitin', language 'cs'
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand Down
2 changes: 1 addition & 1 deletion lang/de/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'de'
* Strings for component 'plagiarism_turnitin', language 'de'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/en/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'en'
* Strings for component 'plagiarism_turnitin', language 'en'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/es/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'es'
* Strings for component 'plagiarism_turnitin', language 'es'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/fi/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'fi'
* Strings for component 'plagiarism_turnitin', language 'fi'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/fr/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'fr'
* Strings for component 'plagiarism_turnitin', language 'fr'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/it/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'it'
* Strings for component 'plagiarism_turnitin', language 'it'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/ja/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'ja'
* Strings for component 'plagiarism_turnitin', language 'ja'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/ko/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'ko'
* Strings for component 'plagiarism_turnitin', language 'ko'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/nl/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'nl'
* Strings for component 'plagiarism_turnitin', language 'nl'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/pl/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'pl'
* Strings for component 'plagiarism_turnitin', language 'pl'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/pt_br/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'pt_br'
* Strings for component 'plagiarism_turnitin', language 'pt_br'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/ro/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'ro'
* Strings for component 'plagiarism_turnitin', language 'ro'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/ru/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'ru'
* Strings for component 'plagiarism_turnitin', language 'ru'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/sv/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'sv'
* Strings for component 'plagiarism_turnitin', language 'sv'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/tr/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'tr'
* Strings for component 'plagiarism_turnitin', language 'tr'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/vi/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'vi'
* Strings for component 'plagiarism_turnitin', language 'vi'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/zh_hans/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'zh_hans'
* Strings for component 'plagiarism_turnitin', language 'zh_hans'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
2 changes: 1 addition & 1 deletion lang/zh_tw/plagiarism_turnitin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder

/**
* Strings for component 'qtype_kprime', language 'zh_tw'
* Strings for component 'plagiarism_turnitin', language 'zh_tw'
*
* @package plagiarism_turnitin
* @copyright 2012 iParadigms LLC
Expand Down
7 changes: 4 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1528,8 +1528,9 @@ private function update_submission($cm, $submissionid, $tiisubmission) {
* @param object $cm The course module.
* @param object $submission The submission object.
* @param int $userid The user id.
* @param bool $cron Whether this is a cron job.
*/
private function update_grade($cm, $submission, $userid, $cron = FALSE) {
private function update_grade($cm, $submission, $userid, $cron = false) {
global $DB, $USER, $CFG;
$return = true;

Expand Down Expand Up @@ -1629,7 +1630,7 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) {
$context = context_course::instance($cm->course);
if (has_capability('mod/assign:grade', $context, $USER->id)) {
// If the grade has changed and the change is not from a cron task then update the grader.
if ($currentgrade->grade != $grade->grade && $cron == FALSE) {
if ($currentgrade->grade != $grade->grade && $cron == false) {
$grade->grader = $USER->id;
}
}
Expand Down Expand Up @@ -2258,7 +2259,7 @@ public function cron_update_scores() {
// At the moment TII doesn't support double marking so we won't synchronise grades from Grade Mark
// as it would destroy the workflow.
if (!is_null($plagiarismfile->grade) && $cm->modname != "coursework") {
$this->update_grade($cm, $readsubmission, $currentsubmission->userid, TRUE);
$this->update_grade($cm, $readsubmission, $currentsubmission->userid, true);
}
}
} catch (Exception $e) {
Expand Down
30 changes: 15 additions & 15 deletions tests/classes/turnitin_assignment_class_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* @package turnitin
*/
final class turnitin_assignment_class_test extends advanced_testcase {
final class turnitin_assignment_class_test extends \advanced_testcase {

/**
* Set Overwrite mtrace to avoid output during the tests.
Expand All @@ -61,15 +61,15 @@ public function test_get_course_data(): void {
$this->resetAfterTest();

// Create a PP course.
$course = new stdClass();
$course = new \stdClass();
$course->courseid = 1;
$course->turnitin_ctl = "Test Course";
$course->turnitin_cid = 10;

// Insert the course to the plagiarism turnitin courses table.
$DB->insert_record('plagiarism_turnitin_courses', $course);

$response = turnitin_assignment::get_course_data(1, "site");
$response = \turnitin_assignment::get_course_data(1, "site");

$this->assertEquals($course->turnitin_ctl, $response->turnitin_ctl);
$this->assertEquals($course->turnitin_cid, $response->turnitin_cid);
Expand All @@ -88,7 +88,7 @@ public function test_create_tii_course(): void {
$this->resetAfterTest();

// Create a PP course.
$course = new stdClass();
$course = new \stdClass();
$course->courseid = 1;
$course->turnitin_ctl = "Test Course";
$course->turnitin_cid = 10;
Expand Down Expand Up @@ -119,7 +119,7 @@ public function test_create_tii_course(): void {

$response = $mock->create_tii_course($course, 1);

$expected = new stdClass();
$expected = new \stdClass();
$expected->id = $course->tii_rel_id;
$expected->turnitin_cid = 1;
$expected->turnitin_ctl = "This is a test course (Moodle PP)";
Expand Down Expand Up @@ -147,7 +147,7 @@ public function test_edit_tii_course(): void {
$this->resetAfterTest();

// Create a PP course.
$course = new stdClass();
$course = new \stdClass();
$course->courseid = 1;
$course->turnitin_ctl = "Test Course";
$course->turnitin_cid = 1;
Expand All @@ -173,7 +173,7 @@ public function test_edit_tii_course(): void {
->getMock();

// Edit a PP course.
$editcourse = new stdClass();
$editcourse = new \stdClass();
$editcourse->id = 1;
$editcourse->turnitin_cid = 10;
$editcourse->fullname = "This is an edited test course";
Expand All @@ -184,7 +184,7 @@ public function test_edit_tii_course(): void {

$responsecourse = $DB->get_record("plagiarism_turnitin_courses", ["id" => $course->id]);

$expected = new stdClass();
$expected = new \stdClass();
$expected->id = $course->id;
$expected->courseid = $course->courseid;
$expected->turnitin_ctl = "This is an edited test course (Moodle PP)";
Expand All @@ -206,12 +206,12 @@ public function test_truncate_title(): void {
$title = "This is a very long title that we are going to use to test the truncate title method.";
$limit = 50;

$response = turnitin_assignment::truncate_title($title, $limit);
$response = \turnitin_assignment::truncate_title($title, $limit);

$this->assertEquals('This is a very long title that we a... (Moodle PP)', $response);

// Try a title that is within our limit.
$response = turnitin_assignment::truncate_title("This title should not be truncated.", $limit);
$response = \turnitin_assignment::truncate_title("This title should not be truncated.", $limit);
$this->assertEquals('This title should not be truncated. (Moodle PP)', $response);
}

Expand All @@ -225,7 +225,7 @@ public function test_create_tii_assignment(): void {
$this->resetAfterTest();

// Create a PP assignment.
$assignment = new stdClass();
$assignment = new \stdClass();
$assignment->id = 1;

// Stub a fake tii comms.
Expand Down Expand Up @@ -264,7 +264,7 @@ public function test_edit_tii_assignment(): void {
$this->resetAfterTest();

// Create a PP assignment.
$assignment = new stdClass();
$assignment = new \stdClass();
$assignment->id = 1;
$assignment->title = "This is a test assignment.";

Expand Down Expand Up @@ -312,7 +312,7 @@ public function test_edit_tii_assignment(): void {
$this->assertEquals(get_string('editassignmenterror', 'plagiarism_turnitin'), $response["error"]);

// Test the error handling for the cron workflow.
$error = new stdClass();
$error = new \stdClass();
$error->title = $assignment->title;
$error->assignmentid = 1;

Expand All @@ -335,7 +335,7 @@ public function test_get_peermark_assignments(): void {
$this->resetAfterTest();

// Create a PP course.
$peermark = new stdClass();
$peermark = new \stdClass();
$peermark->parent_tii_assign_id = 1;
$peermark->title = "This is a test Peermark assignment.";
$peermark->tiiassignid = 1;
Expand All @@ -347,7 +347,7 @@ public function test_get_peermark_assignments(): void {
// Insert the peermark to the plagiarism turnitin courses table.
$DB->insert_record('plagiarism_turnitin_peermark', $peermark);

$assignment = new turnitin_assignment(0, 1);
$assignment = new \turnitin_assignment(0, 1);

// We should have a peermark object.
$response = $assignment->get_peermark_assignments(1, $peermark->parent_tii_assign_id);
Expand Down
10 changes: 5 additions & 5 deletions tests/classes/turnitin_user_class_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function test_get_moodle_user(): void {

$student = $this->getDataGenerator()->create_user();

$turnitinuser = new turnitin_user(0, null, null, null, null);
$turnitinuser = new \turnitin_user(0, null, null, null, null);
$response = $turnitinuser->get_moodle_user($student->id);

// Check that we have an object back with user details. No need to check all params.
Expand All @@ -82,7 +82,7 @@ public function test_get_moodle_user(): void {
public function test_get_pseudo_domain(): void {
$this->resetAfterTest();

$response = turnitin_user::get_pseudo_domain();
$response = \turnitin_user::get_pseudo_domain();
$this->assertEquals(PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_DOMAIN, $response);
}

Expand All @@ -95,7 +95,7 @@ public function test_get_pseudo_domain(): void {
public function test_get_pseudo_firstname(): void {
$this->resetAfterTest();

$turnitinuser = new turnitin_user(0, null, null, null, null);
$turnitinuser = new \turnitin_user(0, null, null, null, null);
$response = $turnitinuser->get_pseudo_firstname();
$this->assertEquals(PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_FIRSTNAME, $response);
}
Expand All @@ -117,7 +117,7 @@ public function test_get_pseudo_lastname(): void {
set_config('plagiarism_turnitin_pseudolastname', 1, 'plagiarism_turnitin');
set_config('plagiarism_turnitin_lastnamegen', 1, 'plagiarism_turnitin');

$turnitinuser = new turnitin_user($student->id, null, null, null, null);
$turnitinuser = new \turnitin_user($student->id, null, null, null, null);
$response = $turnitinuser->get_pseudo_lastname();
$this->assertEquals(PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_FIRSTNAME, $response);
}
Expand All @@ -142,7 +142,7 @@ public function test_unlink_user(): void {
$this->assertEquals(1, $count);

// Unlink the user.
$turnitinuser = new turnitin_user(0, null, null, null, null);
$turnitinuser = new \turnitin_user(0, null, null, null, null);
$turnitinuser->unlink_user($testuser["joins"][0]);

// We should have a Turnitin user ID of 0.
Expand Down
Loading

0 comments on commit 471b675

Please sign in to comment.