Skip to content

Commit 8bc26b9

Browse files
committed
Make Moodle Code Checker happy
1 parent 12d8122 commit 8bc26b9

File tree

6 files changed

+83
-51
lines changed

6 files changed

+83
-51
lines changed

db/upgrade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function xmldb_customcert_upgrade($oldversion) {
184184

185185
// Conditionally launch add field.
186186
if (!$dbman->field_exists($table, $field)) {
187-
$dbman->add_field($table, $field);
187+
$dbman->add_field($table, $field);
188188
}
189189

190190
upgrade_mod_savepoint(true, 2021051702, 'customcert'); // Replace with the actual version number.

element/daterange/tests/element_test.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
* @copyright 2018 Dmitrii Metelkin <[email protected]>
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
24+
25+
namespace customcertelement_daterange;
26+
27+
use stdClass;
28+
use advanced_testcase;
29+
use fake_datarange_element;
30+
2431
defined('MOODLE_INTERNAL') || die();
2532

2633
global $CFG;
@@ -34,7 +41,7 @@
3441
* @copyright 2018 Dmitrii Metelkin <[email protected]>
3542
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3643
*/
37-
class customcertelement_daterange_element_test extends advanced_testcase {
44+
class element_test extends advanced_testcase {
3845

3946
/**
4047
* Helper function to build element data.
@@ -82,7 +89,7 @@ protected function build_datarange_data(array $dataranges, $fallbackstring = '')
8289
* @param array $dataranges A list of dataranges.
8390
* @param string $fallbackstring Fall back strin
8491
*
85-
* @return \fake_datarange_element
92+
* @return fake_datarange_element
8693
*/
8794
protected function get_datarange_element(array $dataranges, $fallbackstring = '') {
8895
$datarangedata = $this->build_datarange_data($dataranges, $fallbackstring);

tests/element_helper_test.php

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2424
*/
2525

26+
namespace mod_customcert;
27+
28+
use grade_item;
29+
use grade_grade;
30+
use context_module;
31+
use context_system;
32+
use advanced_testcase;
33+
2634
defined('MOODLE_INTERNAL') || die();
2735

2836
global $CFG;
@@ -35,7 +43,7 @@
3543
* @copyright 2017 Mark Nelson <[email protected]>
3644
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3745
*/
38-
class mod_customcert_element_helper_testcase extends advanced_testcase {
46+
class element_helper_test extends advanced_testcase {
3947

4048
/**
4149
* Test set up.
@@ -58,7 +66,7 @@ public function test_get_courseid_element_in_course_certificate() {
5866

5967
// Get the template to add elements to.
6068
$template = $DB->get_record('customcert_templates', array('contextid' => context_module::instance($customcert->cmid)->id));
61-
$template = new \mod_customcert\template($template);
69+
$template = new template($template);
6270

6371
// Add a page to the template.
6472
$pageid = $template->add_page();
@@ -68,12 +76,12 @@ public function test_get_courseid_element_in_course_certificate() {
6876
$element->name = 'Test element';
6977
$element->element = 'testelement';
7078
$element->pageid = $pageid;
71-
$element->sequence = \mod_customcert\element_helper::get_element_sequence($element->pageid);
79+
$element->sequence = element_helper::get_element_sequence($element->pageid);
7280
$element->timecreated = time();
7381
$element->id = $DB->insert_record('customcert_elements', $element);
7482

7583
// Confirm the correct course id is returned.
76-
$this->assertEquals($course->id, \mod_customcert\element_helper::get_courseid($element->id));
84+
$this->assertEquals($course->id, element_helper::get_courseid($element->id));
7785
}
7886

7987
/**
@@ -83,7 +91,7 @@ public function test_get_courseid_element_in_site_template() {
8391
global $DB, $SITE;
8492

8593
// Add a template to the site.
86-
$template = \mod_customcert\template::create('Site template', context_system::instance()->id);
94+
$template = template::create('Site template', context_system::instance()->id);
8795

8896
// Add a page to the template.
8997
$pageid = $template->add_page();
@@ -93,12 +101,12 @@ public function test_get_courseid_element_in_site_template() {
93101
$element->name = 'Test element';
94102
$element->element = 'testelement';
95103
$element->pageid = $pageid;
96-
$element->sequence = \mod_customcert\element_helper::get_element_sequence($element->pageid);
104+
$element->sequence = element_helper::get_element_sequence($element->pageid);
97105
$element->timecreated = time();
98106
$element->id = $DB->insert_record('customcert_elements', $element);
99107

100108
// Confirm the correct course id is returned.
101-
$this->assertEquals($SITE->id, \mod_customcert\element_helper::get_courseid($element->id));
109+
$this->assertEquals($SITE->id, element_helper::get_courseid($element->id));
102110
}
103111

104112
/**
@@ -115,7 +123,7 @@ public function test_get_context_element_in_course_certificate() {
115123

116124
// Get the template to add elements to.
117125
$template = $DB->get_record('customcert_templates', array('contextid' => context_module::instance($customcert->cmid)->id));
118-
$template = new \mod_customcert\template($template);
126+
$template = new template($template);
119127

120128
// Add a page to the template.
121129
$pageid = $template->add_page();
@@ -125,13 +133,13 @@ public function test_get_context_element_in_course_certificate() {
125133
$element->name = 'Test element';
126134
$element->element = 'testelement';
127135
$element->pageid = $pageid;
128-
$element->sequence = \mod_customcert\element_helper::get_element_sequence($element->pageid);
136+
$element->sequence = element_helper::get_element_sequence($element->pageid);
129137
$element->timecreated = time();
130138
$element->id = $DB->insert_record('customcert_elements', $element);
131139

132140
// Confirm the correct course module id is returned.
133141
$this->assertEquals(context_module::instance($customcert->cmid),
134-
\mod_customcert\element_helper::get_context($element->id));
142+
element_helper::get_context($element->id));
135143
}
136144

137145
/**
@@ -141,7 +149,7 @@ public function test_get_context_element_in_site_template() {
141149
global $DB;
142150

143151
// Add a template to the site.
144-
$template = \mod_customcert\template::create('Site template', context_system::instance()->id);
152+
$template = template::create('Site template', context_system::instance()->id);
145153

146154
// Add a page to the template.
147155
$pageid = $template->add_page();
@@ -151,12 +159,12 @@ public function test_get_context_element_in_site_template() {
151159
$element->name = 'Test element';
152160
$element->element = 'testelement';
153161
$element->pageid = $pageid;
154-
$element->sequence = \mod_customcert\element_helper::get_element_sequence($element->pageid);
162+
$element->sequence = element_helper::get_element_sequence($element->pageid);
155163
$element->timecreated = time();
156164
$element->id = $DB->insert_record('customcert_elements', $element);
157165

158166
// Confirm the correct course module id is returned.
159-
$this->assertEquals(context_system::instance(), \mod_customcert\element_helper::get_context($element->id));
167+
$this->assertEquals(context_system::instance(), element_helper::get_context($element->id));
160168
}
161169

162170
/**
@@ -190,7 +198,7 @@ public function test_get_grade_items() {
190198
);
191199

192200
// Confirm the function returns the correct number of grade items.
193-
$gradeitems = \mod_customcert\element_helper::get_grade_items($course);
201+
$gradeitems = element_helper::get_grade_items($course);
194202
$this->assertCount(6, $gradeitems);
195203
$this->assertArrayHasKey($assign1->cmid, $gradeitems);
196204
$this->assertArrayHasKey($assign2->cmid, $gradeitems);
@@ -244,7 +252,7 @@ public function test_get_mod_grade_info() {
244252
$grade->insert();
245253

246254
// Check that the user received the grade.
247-
$grade = \mod_customcert\element_helper::get_mod_grade_info(
255+
$grade = element_helper::get_mod_grade_info(
248256
$assign->cmid,
249257
GRADE_DISPLAY_TYPE_PERCENTAGE,
250258
$student1->id
@@ -256,7 +264,7 @@ public function test_get_mod_grade_info() {
256264
$this->assertEquals($time, $grade->get_dategraded());
257265

258266
// Check that the user we did not grade has no grade.
259-
$grade = \mod_customcert\element_helper::get_mod_grade_info(
267+
$grade = element_helper::get_mod_grade_info(
260268
$assign->cmid,
261269
GRADE_DISPLAY_TYPE_PERCENTAGE,
262270
$student2->id
@@ -304,7 +312,7 @@ public function test_get_course_grade_info() {
304312
$grade->insert();
305313

306314
// Check that the user received the grade.
307-
$grade = \mod_customcert\element_helper::get_course_grade_info(
315+
$grade = element_helper::get_course_grade_info(
308316
$course->id,
309317
GRADE_DISPLAY_TYPE_PERCENTAGE,
310318
$student1->id
@@ -316,7 +324,7 @@ public function test_get_course_grade_info() {
316324
$this->assertEquals($time, $grade->get_dategraded());
317325

318326
// Check that the user we did not grade has no grade.
319-
$grade = \mod_customcert\element_helper::get_course_grade_info(
327+
$grade = element_helper::get_course_grade_info(
320328
$course->id,
321329
GRADE_DISPLAY_TYPE_PERCENTAGE,
322330
$student2->id
@@ -366,7 +374,7 @@ public function test_get_grade_item_info() {
366374
$grade->insert();
367375

368376
// Check that the user received the grade.
369-
$grade = \mod_customcert\element_helper::get_grade_item_info(
377+
$grade = element_helper::get_grade_item_info(
370378
$gi->id,
371379
GRADE_DISPLAY_TYPE_PERCENTAGE,
372380
$student1->id
@@ -378,7 +386,7 @@ public function test_get_grade_item_info() {
378386
$this->assertEquals($time, $grade->get_dategraded());
379387

380388
// Check that the user we did not grade has no grade.
381-
$grade = \mod_customcert\element_helper::get_grade_item_info(
389+
$grade = element_helper::get_grade_item_info(
382390
$gi->id,
383391
GRADE_DISPLAY_TYPE_PERCENTAGE,
384392
$student2->id

tests/email_certificate_task_test.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2424
*/
2525

26+
namespace mod_customcert;
27+
28+
use stdClass;
29+
use context_course;
30+
use advanced_testcase;
31+
use mod_customcert\task\email_certificate_task;
32+
2633
defined('MOODLE_INTERNAL') || die();
2734

2835
/**
@@ -33,7 +40,7 @@
3340
* @copyright 2017 Mark Nelson <[email protected]>
3441
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3542
*/
36-
class mod_customcert_task_email_certificate_task_testcase extends advanced_testcase {
43+
class email_certificate_task_test extends advanced_testcase {
3744

3845
/**
3946
* Test set up.
@@ -60,7 +67,7 @@ public function test_email_certificates_no_elements() {
6067

6168
// Run the task.
6269
$sink = $this->redirectEmails();
63-
$task = new \mod_customcert\task\email_certificate_task();
70+
$task = new email_certificate_task();
6471
$task->execute();
6572
$emails = $sink->get_messages();
6673

@@ -96,7 +103,7 @@ public function test_email_certificates_no_cap() {
96103
$template->id = $customcert->templateid;
97104
$template->name = 'A template';
98105
$template->contextid = context_course::instance($course->id)->id;
99-
$template = new \mod_customcert\template($template);
106+
$template = new template($template);
100107

101108
// Add a page to this template.
102109
$pageid = $template->add_page();
@@ -109,7 +116,7 @@ public function test_email_certificates_no_cap() {
109116

110117
// Run the task.
111118
$sink = $this->redirectEmails();
112-
$task = new \mod_customcert\task\email_certificate_task();
119+
$task = new email_certificate_task();
113120
$task->execute();
114121
$emails = $sink->get_messages();
115122

@@ -148,7 +155,7 @@ public function test_email_certificates_students() {
148155
$template->id = $customcert->templateid;
149156
$template->name = 'A template';
150157
$template->contextid = context_course::instance($course->id)->id;
151-
$template = new \mod_customcert\template($template);
158+
$template = new template($template);
152159

153160
// Add a page to this template.
154161
$pageid = $template->add_page();
@@ -167,7 +174,7 @@ public function test_email_certificates_students() {
167174

168175
// Run the task.
169176
$sink = $this->redirectEmails();
170-
$task = new \mod_customcert\task\email_certificate_task();
177+
$task = new email_certificate_task();
171178
$task->execute();
172179
$emails = $sink->get_messages();
173180

@@ -192,7 +199,7 @@ public function test_email_certificates_students() {
192199

193200
// Now, run the task again and ensure we did not issue any more certificates.
194201
$sink = $this->redirectEmails();
195-
$task = new \mod_customcert\task\email_certificate_task();
202+
$task = new email_certificate_task();
196203
$task->execute();
197204
$emails = $sink->get_messages();
198205

@@ -233,7 +240,7 @@ public function test_email_certificates_teachers() {
233240
$template->id = $customcert->templateid;
234241
$template->name = 'A template';
235242
$template->contextid = context_course::instance($course->id)->id;
236-
$template = new \mod_customcert\template($template);
243+
$template = new template($template);
237244

238245
// Add a page to this template.
239246
$pageid = $template->add_page();
@@ -246,7 +253,7 @@ public function test_email_certificates_teachers() {
246253

247254
// Run the task.
248255
$sink = $this->redirectEmails();
249-
$task = new \mod_customcert\task\email_certificate_task();
256+
$task = new email_certificate_task();
250257
$task->execute();
251258
$emails = $sink->get_messages();
252259

@@ -286,7 +293,7 @@ public function test_email_certificates_others() {
286293
$template->id = $customcert->templateid;
287294
$template->name = 'A template';
288295
$template->contextid = context_course::instance($course->id)->id;
289-
$template = new \mod_customcert\template($template);
296+
$template = new template($template);
290297

291298
// Add a page to this template.
292299
$pageid = $template->add_page();
@@ -299,7 +306,7 @@ public function test_email_certificates_others() {
299306

300307
// Run the task.
301308
$sink = $this->redirectEmails();
302-
$task = new \mod_customcert\task\email_certificate_task();
309+
$task = new email_certificate_task();
303310
$task->execute();
304311
$emails = $sink->get_messages();
305312

@@ -337,7 +344,7 @@ public function test_email_certificates_students_not_visible() {
337344
$template->id = $customcert->templateid;
338345
$template->name = 'A template';
339346
$template->contextid = context_course::instance($course->id)->id;
340-
$template = new \mod_customcert\template($template);
347+
$template = new template($template);
341348

342349
// Add a page to this template.
343350
$pageid = $template->add_page();
@@ -353,7 +360,7 @@ public function test_email_certificates_students_not_visible() {
353360

354361
// Run the task.
355362
$sink = $this->redirectEmails();
356-
$task = new \mod_customcert\task\email_certificate_task();
363+
$task = new email_certificate_task();
357364
$task->execute();
358365
$emails = $sink->get_messages();
359366

@@ -392,7 +399,7 @@ public function test_email_certificates_students_havent_met_required_time() {
392399
$template->id = $customcert->templateid;
393400
$template->name = 'A template';
394401
$template->contextid = context_course::instance($course->id)->id;
395-
$template = new \mod_customcert\template($template);
402+
$template = new template($template);
396403

397404
// Add a page to this template.
398405
$pageid = $template->add_page();
@@ -405,7 +412,7 @@ public function test_email_certificates_students_havent_met_required_time() {
405412

406413
// Run the task.
407414
$sink = $this->redirectEmails();
408-
$task = new \mod_customcert\task\email_certificate_task();
415+
$task = new email_certificate_task();
409416
$task->execute();
410417
$emails = $sink->get_messages();
411418

0 commit comments

Comments
 (0)