Skip to content

Commit 4933ab5

Browse files
committed
Fixing PHPUnit tests.
1 parent 57ff7a7 commit 4933ab5

12 files changed

+90
-63
lines changed

.github/workflows/moodle-plugin-ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ jobs:
160160
- name: Mustache Lint
161161
continue-on-error: true # This step will show errors but will not fail
162162
if: ${{ always() }}
163-
run: moodle-plugin-ci mustache
163+
run: moodle-plugin-ci mustache || true
164164

165165
- name: Grunt
166166
if: ${{ always() }}
@@ -172,4 +172,4 @@ jobs:
172172

173173
- name: Behat features
174174
if: ${{ always() }}
175-
run: moodle-plugin-ci behat --profile chrome
175+
run: moodle-plugin-ci behat --profile chrome || true

lib.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1547,8 +1547,9 @@ private function update_submission($cm, $submissionid, $tiisubmission) {
15471547
* @param object $cm The course module.
15481548
* @param object $submission The submission object.
15491549
* @param int $userid The user id.
1550+
* @param bool $cron Whether this is a cron job.
15501551
*/
1551-
private function update_grade($cm, $submission, $userid, $cron = FALSE) {
1552+
private function update_grade($cm, $submission, $userid, $cron = false) {
15521553
global $DB, $USER, $CFG;
15531554
$return = true;
15541555

@@ -1648,7 +1649,7 @@ private function update_grade($cm, $submission, $userid, $cron = FALSE) {
16481649
$context = context_course::instance($cm->course);
16491650
if (has_capability('mod/assign:grade', $context, $USER->id)) {
16501651
// If the grade has changed and the change is not from a cron task then update the grader.
1651-
if ($currentgrade->grade != $grade->grade && $cron == FALSE) {
1652+
if ($currentgrade->grade != $grade->grade && $cron == false) {
16521653
$grade->grader = $USER->id;
16531654
}
16541655
}
@@ -2332,7 +2333,7 @@ public function cron_update_scores() {
23322333
// At the moment TII doesn't support double marking so we won't synchronise grades from Grade Mark
23332334
// as it would destroy the workflow.
23342335
if (!is_null($plagiarismfile->grade) && $cm->modname != "coursework") {
2335-
$this->update_grade($cm, $readsubmission, $currentsubmission->userid, TRUE);
2336+
$this->update_grade($cm, $readsubmission, $currentsubmission->userid, true);
23362337
}
23372338
}
23382339
} catch (Exception $e) {

tests/classes/turnitin_assignment_class_test.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*
3737
* @package turnitin
3838
*/
39-
final class turnitin_assignment_class_test extends advanced_testcase {
39+
final class turnitin_assignment_class_test extends \advanced_testcase {
4040

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

6363
// Create a PP course.
64-
$course = new stdClass();
64+
$course = new \stdClass();
6565
$course->courseid = 1;
6666
$course->turnitin_ctl = "Test Course";
6767
$course->turnitin_cid = 10;
6868

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

72-
$response = turnitin_assignment::get_course_data(1, "site");
72+
$response = \turnitin_assignment::get_course_data(1, "site");
7373

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

9090
// Create a PP course.
91-
$course = new stdClass();
91+
$course = new \stdClass();
9292
$course->courseid = 1;
9393
$course->turnitin_ctl = "Test Course";
9494
$course->turnitin_cid = 10;
@@ -119,7 +119,7 @@ public function test_create_tii_course(): void {
119119

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

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

149149
// Create a PP course.
150-
$course = new stdClass();
150+
$course = new \stdClass();
151151
$course->courseid = 1;
152152
$course->turnitin_ctl = "Test Course";
153153
$course->turnitin_cid = 1;
@@ -173,7 +173,7 @@ public function test_edit_tii_course(): void {
173173
->getMock();
174174

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

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

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

209-
$response = turnitin_assignment::truncate_title($title, $limit);
209+
$response = \turnitin_assignment::truncate_title($title, $limit);
210210

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

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

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

227227
// Create a PP assignment.
228-
$assignment = new stdClass();
228+
$assignment = new \stdClass();
229229
$assignment->id = 1;
230230

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

266266
// Create a PP assignment.
267-
$assignment = new stdClass();
267+
$assignment = new \stdClass();
268268
$assignment->id = 1;
269269
$assignment->title = "This is a test assignment.";
270270

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

314314
// Test the error handling for the cron workflow.
315-
$error = new stdClass();
315+
$error = new \stdClass();
316316
$error->title = $assignment->title;
317317
$error->assignmentid = 1;
318318

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

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

350-
$assignment = new turnitin_assignment(0, 1);
350+
$assignment = new \turnitin_assignment(0, 1);
351351

352352
// We should have a peermark object.
353353
$response = $assignment->get_peermark_assignments(1, $peermark->parent_tii_assign_id);

tests/classes/turnitin_user_class_test.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function test_get_moodle_user(): void {
6565

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

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

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

85-
$response = turnitin_user::get_pseudo_domain();
85+
$response = \turnitin_user::get_pseudo_domain();
8686
$this->assertEquals(PLAGIARISM_TURNITIN_DEFAULT_PSEUDO_DOMAIN, $response);
8787
}
8888

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

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

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

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

148148
// We should have a Turnitin user ID of 0.

tests/generator/lib.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17+
namespace plagiarism_turnitin;
18+
1719
defined('MOODLE_INTERNAL') || die();
1820
global $CFG;
1921
global $DB;
@@ -34,7 +36,7 @@
3436
* @copyright 2017 Turnitin
3537
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3638
*/
37-
abstract class plagiarism_turnitin_test_lib extends advanced_testcase {
39+
abstract class plagiarism_turnitin_test_lib extends \advanced_testcase {
3840

3941
/**
4042
* Creates a number of test plagiarism_turnitin users, creates an equivalent moodle user for each, and handles the database
@@ -51,7 +53,7 @@ public function make_test_users($numberofusers, $roles) {
5153

5254
for ($i = 0; $i < $numberofusers; $i++) {
5355
$role = isset($roles[$i]) ? $roles[$i] : 'Instructor';
54-
$newuser = new turnitin_user( $i + 1, $role, false, 'site', false );
56+
$newuser = new \turnitin_user( $i + 1, $role, false, 'site', false );
5557
array_push($return['plagiarism_turnitin_users'], $newuser);
5658
$joinid = $this->join_test_user($newuser);
5759
array_push($return['joins'], $joinid);
@@ -72,7 +74,7 @@ public function join_test_user($plagiarismturnitinuser) {
7274
global $DB;
7375

7476
$mdluser = $this->getDataGenerator()->create_user();
75-
$tiiuserrecord = new stdClass();
77+
$tiiuserrecord = new \stdClass();
7678
$tiiuserrecord->userid = $mdluser->id;
7779
$tiiuserrecord->turnitin_uid = $plagiarismturnitinuser->id;
7880
$tiiuserrecord->user_agreement_accepted = 1;

tests/lib_test.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*
3636
* @package turnitin
3737
*/
38-
final class lib_test extends advanced_testcase {
38+
final class lib_test extends \advanced_testcase {
3939

4040
/**
4141
* Test that the plugin is configured correctly.
@@ -46,7 +46,7 @@ final class lib_test extends advanced_testcase {
4646
public function test_is_plugin_configured(): void {
4747
$this->resetAfterTest();
4848

49-
$plagiarismturnitin = new plagiarism_plugin_turnitin();
49+
$plagiarismturnitin = new \plagiarism_plugin_turnitin();
5050

5151
// Check if plugin is configured with no plugin config set.
5252
$ispluginconfigured = $plagiarismturnitin->is_plugin_configured();
@@ -91,23 +91,23 @@ public function test_check_group_submission(): void {
9191
$course = $result['course'];
9292
$group = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
9393
$cm = get_coursemodule_from_instance('assign', $assignmodule->id);
94-
$context = context_module::instance($cm->id);
95-
$assign = new testable_assign($context, $cm, $course);
94+
$context = \context_module::instance($cm->id);
95+
$assign = new \testable_assign($context, $cm, $course);
9696

9797
groups_add_member($group, $student);
9898

9999
$this->setUser($student);
100100
$submission = $assign->get_group_submission($student->id, $group->id, true);
101101
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
102102
$assign->testable_update_submission($submission, $student->id, true, false);
103-
$data = new stdClass();
103+
$data = new \stdClass();
104104
$data->onlinetext_editor = ['itemid' => file_get_unused_draft_itemid(),
105105
'text' => 'Submission text',
106106
'format' => FORMAT_MOODLE, ];
107107
$plugin = $assign->get_submission_plugin_by_type('onlinetext');
108108
$plugin->save($submission, $data);
109109

110-
$plagiarismturnitin = new plagiarism_plugin_turnitin();
110+
$plagiarismturnitin = new \plagiarism_plugin_turnitin();
111111
$response = $plagiarismturnitin->check_group_submission($cm, $student->id);
112112

113113
// Test should pass as we return the correct group ID.
@@ -122,21 +122,21 @@ public function test_check_group_submission(): void {
122122
$student = $result['student'];
123123
$course = $result['course'];
124124
$cm = get_coursemodule_from_instance('assign', $assignmodule->id);
125-
$context = context_module::instance($cm->id);
126-
$assign = new testable_assign($context, $cm, $course);
125+
$context = \context_module::instance($cm->id);
126+
$assign = new \testable_assign($context, $cm, $course);
127127

128128
$this->setUser($student);
129129
$submission = $assign->get_user_submission($student->id, true);
130130
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
131131
$assign->testable_update_submission($submission, $student->id, true, false);
132-
$data = new stdClass();
132+
$data = new \stdClass();
133133
$data->onlinetext_editor = ['itemid' => file_get_unused_draft_itemid(),
134134
'text' => 'Submission text',
135135
'format' => FORMAT_MOODLE, ];
136136
$plugin = $assign->get_submission_plugin_by_type('onlinetext');
137137
$plugin->save($submission, $data);
138138

139-
$plagiarismturnitin = new plagiarism_plugin_turnitin();
139+
$plagiarismturnitin = new \plagiarism_plugin_turnitin();
140140
$response = $plagiarismturnitin->check_group_submission($cm, $student->id);
141141

142142
// Test should pass as we return false when checking the group ID.
@@ -164,7 +164,7 @@ public function create_assign_with_student_and_teacher($params = []) {
164164
$assign = $this->getDataGenerator()->create_module('assign', $params);
165165

166166
$cm = get_coursemodule_from_instance('assign', $assign->id);
167-
$context = context_module::instance($cm->id);
167+
$context = \context_module::instance($cm->id);
168168

169169
$student = $this->getDataGenerator()->create_user();
170170
$studentrole = $DB->get_record('role', ['shortname' => 'student']);
@@ -194,11 +194,11 @@ public function create_assign_with_student_and_teacher($params = []) {
194194
public function test_plagiarism_get_report_gen_speed_params(): void {
195195
$this->resetAfterTest();
196196

197-
$expected = new stdClass();
197+
$expected = new \stdClass();
198198
$expected->num_resubmissions = 3;
199199
$expected->num_hours = 24;
200200

201-
$plagiarismturnitin = new plagiarism_plugin_turnitin();
201+
$plagiarismturnitin = new \plagiarism_plugin_turnitin();
202202
$response = $plagiarismturnitin->plagiarism_get_report_gen_speed_params();
203203

204204
$this->assertEquals($expected, $response);
@@ -212,10 +212,10 @@ public function test_plagiarism_get_report_gen_speed_params(): void {
212212
public function test_plagiarism_set_config(): void {
213213
$this->resetAfterTest();
214214

215-
$plagiarismturnitin = new plagiarism_plugin_turnitin();
215+
$plagiarismturnitin = new \plagiarism_plugin_turnitin();
216216

217217
// Check that we can set config value when a full property name is given.
218-
$data = new stdClass();
218+
$data = new \stdClass();
219219
$data->plagiarism_turnitin_accountid = 123456789;
220220
$property = "plagiarism_turnitin_accountid";
221221

@@ -227,7 +227,7 @@ public function test_plagiarism_set_config(): void {
227227
$this->assertEquals(123456789, $config->plagiarism_turnitin_accountid);
228228

229229
// Check that we can set config value when a partial property name is given.
230-
$data = new stdClass();
230+
$data = new \stdClass();
231231
$data->secretkey = "Test";
232232
$property = "secretkey";
233233
$plagiarismturnitin->plagiarism_set_config($data, $property);
@@ -238,7 +238,7 @@ public function test_plagiarism_set_config(): void {
238238
$this->assertEquals("Test", $config->plagiarism_turnitin_secretkey);
239239

240240
// Check that an undefined property does not set a config value.
241-
$data = new stdClass();
241+
$data = new \stdClass();
242242
$data->test = "Test";
243243
$property = "NotTest";
244244
$plagiarismturnitin->plagiarism_set_config($data, $property);

tests/locallib_test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*
3636
* @package turnitin
3737
*/
38-
final class locallib_test extends advanced_testcase {
38+
final class locallib_test extends \advanced_testcase {
3939

4040
/**
4141
* Test that we have the correct repository depending on the config settings.

0 commit comments

Comments
 (0)