Skip to content

Commit

Permalink
Make Moodle Code Checker happy
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Jan 10, 2022
1 parent 12d8122 commit 8bc26b9
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 51 deletions.
2 changes: 1 addition & 1 deletion db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function xmldb_customcert_upgrade($oldversion) {

// Conditionally launch add field.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
$dbman->add_field($table, $field);
}

upgrade_mod_savepoint(true, 2021051702, 'customcert'); // Replace with the actual version number.
Expand Down
11 changes: 9 additions & 2 deletions element/daterange/tests/element_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
* @copyright 2018 Dmitrii Metelkin <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace customcertelement_daterange;

use stdClass;
use advanced_testcase;
use fake_datarange_element;

defined('MOODLE_INTERNAL') || die();

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

/**
* Helper function to build element data.
Expand Down Expand Up @@ -82,7 +89,7 @@ protected function build_datarange_data(array $dataranges, $fallbackstring = '')
* @param array $dataranges A list of dataranges.
* @param string $fallbackstring Fall back strin
*
* @return \fake_datarange_element
* @return fake_datarange_element
*/
protected function get_datarange_element(array $dataranges, $fallbackstring = '') {
$datarangedata = $this->build_datarange_data($dataranges, $fallbackstring);
Expand Down
48 changes: 28 additions & 20 deletions tests/element_helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_customcert;

use grade_item;
use grade_grade;
use context_module;
use context_system;
use advanced_testcase;

defined('MOODLE_INTERNAL') || die();

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

/**
* Test set up.
Expand All @@ -58,7 +66,7 @@ public function test_get_courseid_element_in_course_certificate() {

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

// Add a page to the template.
$pageid = $template->add_page();
Expand All @@ -68,12 +76,12 @@ public function test_get_courseid_element_in_course_certificate() {
$element->name = 'Test element';
$element->element = 'testelement';
$element->pageid = $pageid;
$element->sequence = \mod_customcert\element_helper::get_element_sequence($element->pageid);
$element->sequence = element_helper::get_element_sequence($element->pageid);
$element->timecreated = time();
$element->id = $DB->insert_record('customcert_elements', $element);

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

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

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

// Add a page to the template.
$pageid = $template->add_page();
Expand All @@ -93,12 +101,12 @@ public function test_get_courseid_element_in_site_template() {
$element->name = 'Test element';
$element->element = 'testelement';
$element->pageid = $pageid;
$element->sequence = \mod_customcert\element_helper::get_element_sequence($element->pageid);
$element->sequence = element_helper::get_element_sequence($element->pageid);
$element->timecreated = time();
$element->id = $DB->insert_record('customcert_elements', $element);

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

/**
Expand All @@ -115,7 +123,7 @@ public function test_get_context_element_in_course_certificate() {

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

// Add a page to the template.
$pageid = $template->add_page();
Expand All @@ -125,13 +133,13 @@ public function test_get_context_element_in_course_certificate() {
$element->name = 'Test element';
$element->element = 'testelement';
$element->pageid = $pageid;
$element->sequence = \mod_customcert\element_helper::get_element_sequence($element->pageid);
$element->sequence = element_helper::get_element_sequence($element->pageid);
$element->timecreated = time();
$element->id = $DB->insert_record('customcert_elements', $element);

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

/**
Expand All @@ -141,7 +149,7 @@ public function test_get_context_element_in_site_template() {
global $DB;

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

// Add a page to the template.
$pageid = $template->add_page();
Expand All @@ -151,12 +159,12 @@ public function test_get_context_element_in_site_template() {
$element->name = 'Test element';
$element->element = 'testelement';
$element->pageid = $pageid;
$element->sequence = \mod_customcert\element_helper::get_element_sequence($element->pageid);
$element->sequence = element_helper::get_element_sequence($element->pageid);
$element->timecreated = time();
$element->id = $DB->insert_record('customcert_elements', $element);

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

/**
Expand Down Expand Up @@ -190,7 +198,7 @@ public function test_get_grade_items() {
);

// Confirm the function returns the correct number of grade items.
$gradeitems = \mod_customcert\element_helper::get_grade_items($course);
$gradeitems = element_helper::get_grade_items($course);
$this->assertCount(6, $gradeitems);
$this->assertArrayHasKey($assign1->cmid, $gradeitems);
$this->assertArrayHasKey($assign2->cmid, $gradeitems);
Expand Down Expand Up @@ -244,7 +252,7 @@ public function test_get_mod_grade_info() {
$grade->insert();

// Check that the user received the grade.
$grade = \mod_customcert\element_helper::get_mod_grade_info(
$grade = element_helper::get_mod_grade_info(
$assign->cmid,
GRADE_DISPLAY_TYPE_PERCENTAGE,
$student1->id
Expand All @@ -256,7 +264,7 @@ public function test_get_mod_grade_info() {
$this->assertEquals($time, $grade->get_dategraded());

// Check that the user we did not grade has no grade.
$grade = \mod_customcert\element_helper::get_mod_grade_info(
$grade = element_helper::get_mod_grade_info(
$assign->cmid,
GRADE_DISPLAY_TYPE_PERCENTAGE,
$student2->id
Expand Down Expand Up @@ -304,7 +312,7 @@ public function test_get_course_grade_info() {
$grade->insert();

// Check that the user received the grade.
$grade = \mod_customcert\element_helper::get_course_grade_info(
$grade = element_helper::get_course_grade_info(
$course->id,
GRADE_DISPLAY_TYPE_PERCENTAGE,
$student1->id
Expand All @@ -316,7 +324,7 @@ public function test_get_course_grade_info() {
$this->assertEquals($time, $grade->get_dategraded());

// Check that the user we did not grade has no grade.
$grade = \mod_customcert\element_helper::get_course_grade_info(
$grade = element_helper::get_course_grade_info(
$course->id,
GRADE_DISPLAY_TYPE_PERCENTAGE,
$student2->id
Expand Down Expand Up @@ -366,7 +374,7 @@ public function test_get_grade_item_info() {
$grade->insert();

// Check that the user received the grade.
$grade = \mod_customcert\element_helper::get_grade_item_info(
$grade = element_helper::get_grade_item_info(
$gi->id,
GRADE_DISPLAY_TYPE_PERCENTAGE,
$student1->id
Expand All @@ -378,7 +386,7 @@ public function test_get_grade_item_info() {
$this->assertEquals($time, $grade->get_dategraded());

// Check that the user we did not grade has no grade.
$grade = \mod_customcert\element_helper::get_grade_item_info(
$grade = element_helper::get_grade_item_info(
$gi->id,
GRADE_DISPLAY_TYPE_PERCENTAGE,
$student2->id
Expand Down
37 changes: 22 additions & 15 deletions tests/email_certificate_task_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_customcert;

use stdClass;
use context_course;
use advanced_testcase;
use mod_customcert\task\email_certificate_task;

defined('MOODLE_INTERNAL') || die();

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

/**
* Test set up.
Expand All @@ -60,7 +67,7 @@ public function test_email_certificates_no_elements() {

// Run the task.
$sink = $this->redirectEmails();
$task = new \mod_customcert\task\email_certificate_task();
$task = new email_certificate_task();
$task->execute();
$emails = $sink->get_messages();

Expand Down Expand Up @@ -96,7 +103,7 @@ public function test_email_certificates_no_cap() {
$template->id = $customcert->templateid;
$template->name = 'A template';
$template->contextid = context_course::instance($course->id)->id;
$template = new \mod_customcert\template($template);
$template = new template($template);

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

// Run the task.
$sink = $this->redirectEmails();
$task = new \mod_customcert\task\email_certificate_task();
$task = new email_certificate_task();
$task->execute();
$emails = $sink->get_messages();

Expand Down Expand Up @@ -148,7 +155,7 @@ public function test_email_certificates_students() {
$template->id = $customcert->templateid;
$template->name = 'A template';
$template->contextid = context_course::instance($course->id)->id;
$template = new \mod_customcert\template($template);
$template = new template($template);

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

// Run the task.
$sink = $this->redirectEmails();
$task = new \mod_customcert\task\email_certificate_task();
$task = new email_certificate_task();
$task->execute();
$emails = $sink->get_messages();

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

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

Expand Down Expand Up @@ -233,7 +240,7 @@ public function test_email_certificates_teachers() {
$template->id = $customcert->templateid;
$template->name = 'A template';
$template->contextid = context_course::instance($course->id)->id;
$template = new \mod_customcert\template($template);
$template = new template($template);

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

// Run the task.
$sink = $this->redirectEmails();
$task = new \mod_customcert\task\email_certificate_task();
$task = new email_certificate_task();
$task->execute();
$emails = $sink->get_messages();

Expand Down Expand Up @@ -286,7 +293,7 @@ public function test_email_certificates_others() {
$template->id = $customcert->templateid;
$template->name = 'A template';
$template->contextid = context_course::instance($course->id)->id;
$template = new \mod_customcert\template($template);
$template = new template($template);

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

// Run the task.
$sink = $this->redirectEmails();
$task = new \mod_customcert\task\email_certificate_task();
$task = new email_certificate_task();
$task->execute();
$emails = $sink->get_messages();

Expand Down Expand Up @@ -337,7 +344,7 @@ public function test_email_certificates_students_not_visible() {
$template->id = $customcert->templateid;
$template->name = 'A template';
$template->contextid = context_course::instance($course->id)->id;
$template = new \mod_customcert\template($template);
$template = new template($template);

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

// Run the task.
$sink = $this->redirectEmails();
$task = new \mod_customcert\task\email_certificate_task();
$task = new email_certificate_task();
$task->execute();
$emails = $sink->get_messages();

Expand Down Expand Up @@ -392,7 +399,7 @@ public function test_email_certificates_students_havent_met_required_time() {
$template->id = $customcert->templateid;
$template->name = 'A template';
$template->contextid = context_course::instance($course->id)->id;
$template = new \mod_customcert\template($template);
$template = new template($template);

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

// Run the task.
$sink = $this->redirectEmails();
$task = new \mod_customcert\task\email_certificate_task();
$task = new email_certificate_task();
$task->execute();
$emails = $sink->get_messages();

Expand Down
Loading

0 comments on commit 8bc26b9

Please sign in to comment.