diff --git a/admin/tool/usertours/classes/cache.php b/admin/tool/usertours/classes/cache.php index 28f5eb34e10..a053fc5fd11 100644 --- a/admin/tool/usertours/classes/cache.php +++ b/admin/tool/usertours/classes/cache.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_usertours; + /** * Cache manager. * @@ -21,17 +23,6 @@ * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_usertours; - -defined('MOODLE_INTERNAL') || die(); - -/** - * Cache manager. - * - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ class cache { /** * @var CACHENAME_TOUR The name of the cache used for storing tours. @@ -97,7 +88,7 @@ EOF; } $target = $targetmatch->out_as_local_url(); - return array_filter($tours, function($tour) use ($possiblematches, $target) { + return array_filter($tours, function ($tour) use ($possiblematches, $target) { if (in_array($tour->pathmatch, $possiblematches)) { return true; } diff --git a/admin/tool/usertours/classes/configuration.php b/admin/tool/usertours/classes/configuration.php index ae63554eb30..2f18c29be7b 100644 --- a/admin/tool/usertours/classes/configuration.php +++ b/admin/tool/usertours/classes/configuration.php @@ -14,26 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Step configuration detail class. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours; -defined('MOODLE_INTERNAL') || die(); - /** * Step configuration detail class. * - * @copyright 2016 Andrew Nicols + * @package tool_usertours + * @copyright 2024 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class configuration { - /** * @var TOURDEFAULT */ @@ -60,7 +50,7 @@ class configuration { * @return mixed */ public static function get_default_value($key) { - switch($key) { + switch ($key) { case 'placement': return 'bottom'; case 'orphan': @@ -77,7 +67,7 @@ class configuration { * @return mixed */ public static function get_step_default_value($key) { - switch($key) { + switch ($key) { case 'placement': case 'orphan': case 'backdrop': @@ -94,10 +84,10 @@ class configuration { */ public static function get_placement_options($default = null) { $values = [ - 'top' => get_string('above', 'tool_usertours'), - 'bottom' => get_string('below', 'tool_usertours'), - 'left' => get_string('left', 'tool_usertours'), - 'right' => get_string('right', 'tool_usertours'), + 'top' => get_string('above', 'tool_usertours'), + 'bottom' => get_string('below', 'tool_usertours'), + 'left' => get_string('left', 'tool_usertours'), + 'right' => get_string('right', 'tool_usertours'), ]; if ($default === null) { @@ -114,5 +104,4 @@ class configuration { return $values; } - } diff --git a/admin/tool/usertours/classes/event/step_shown.php b/admin/tool/usertours/classes/event/step_shown.php index 3537b61f7b7..72ff3b4a6d5 100644 --- a/admin/tool/usertours/classes/event/step_shown.php +++ b/admin/tool/usertours/classes/event/step_shown.php @@ -14,18 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The tool_usertours step_shown event. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\event; -defined('MOODLE_INTERNAL') || die(); - /** * The tool_usertours step_shown event. * @@ -41,7 +31,6 @@ defined('MOODLE_INTERNAL') || die(); * } */ class step_shown extends \core\event\base { - /** * Init method. */ diff --git a/admin/tool/usertours/classes/event/tour_ended.php b/admin/tool/usertours/classes/event/tour_ended.php index 945d1e4eeb9..6853dd4a860 100644 --- a/admin/tool/usertours/classes/event/tour_ended.php +++ b/admin/tool/usertours/classes/event/tour_ended.php @@ -14,18 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The tool_usertours tour_ended event. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\event; -defined('MOODLE_INTERNAL') || die(); - /** * The tool_usertours tour_ended event. * @@ -41,7 +31,6 @@ defined('MOODLE_INTERNAL') || die(); * } */ class tour_ended extends \core\event\base { - /** * Init method. */ diff --git a/admin/tool/usertours/classes/event/tour_reset.php b/admin/tool/usertours/classes/event/tour_reset.php index bd9e60d02c2..660f35f5db1 100644 --- a/admin/tool/usertours/classes/event/tour_reset.php +++ b/admin/tool/usertours/classes/event/tour_reset.php @@ -14,18 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The tool_usertours tour_reset event. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\event; -defined('MOODLE_INTERNAL') || die(); - /** * The tool_usertours tour_reset event. * @@ -41,7 +31,6 @@ defined('MOODLE_INTERNAL') || die(); * } */ class tour_reset extends \core\event\base { - /** * Init method. */ diff --git a/admin/tool/usertours/classes/event/tour_started.php b/admin/tool/usertours/classes/event/tour_started.php index 915cb586de3..d44114f051c 100644 --- a/admin/tool/usertours/classes/event/tour_started.php +++ b/admin/tool/usertours/classes/event/tour_started.php @@ -14,18 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * The tool_usertours tour_started event. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\event; -defined('MOODLE_INTERNAL') || die(); - /** * The tool_usertours tour_started event. * @@ -41,7 +31,6 @@ defined('MOODLE_INTERNAL') || die(); * } */ class tour_started extends \core\event\base { - /** * Init method. */ diff --git a/admin/tool/usertours/classes/external/tour.php b/admin/tool/usertours/classes/external/tour.php index 649becb5de8..9ecad8e43ac 100644 --- a/admin/tool/usertours/classes/external/tour.php +++ b/admin/tool/usertours/classes/external/tour.php @@ -43,10 +43,10 @@ class tour extends external_api { global $PAGE; $params = self::validate_parameters(self::fetch_and_start_tour_parameters(), [ - 'tourid' => $tourid, - 'context' => $context, - 'pageurl' => $pageurl, - ]); + 'tourid' => $tourid, + 'context' => $context, + 'pageurl' => $pageurl, + ]); $context = \context_helper::instance_by_id($params['context']); self::validate_context($context); @@ -60,8 +60,8 @@ class tour extends external_api { \tool_usertours\event\tour_started::create([ 'contextid' => $context->id, - 'objectid' => $tour->get_id(), - 'other' => [ + 'objectid' => $tour->get_id(), + 'other' => [ 'pageurl' => $params['pageurl'], ], ])->trigger(); @@ -78,9 +78,9 @@ class tour extends external_api { */ public static function fetch_and_start_tour_parameters() { return new external_function_parameters([ - 'tourid' => new external_value(PARAM_INT, 'Tour ID'), - 'context' => new external_value(PARAM_INT, 'Context ID'), - 'pageurl' => new external_value(PARAM_URL, 'Page URL'), + 'tourid' => new external_value(PARAM_INT, 'Tour ID'), + 'context' => new external_value(PARAM_INT, 'Context ID'), + 'pageurl' => new external_value(PARAM_URL, 'Page URL'), ]); } @@ -91,12 +91,12 @@ class tour extends external_api { */ public static function fetch_and_start_tour_returns() { return new external_single_structure([ - 'tourconfig' => new external_single_structure([ - 'name' => new external_value(PARAM_RAW, 'Tour Name'), - 'steps' => new external_multiple_structure(self::step_structure_returns()), - 'endtourlabel' => new external_value(PARAM_RAW, 'Label of the end tour button'), + 'tourconfig' => new external_single_structure([ + 'name' => new external_value(PARAM_RAW, 'Tour Name'), + 'steps' => new external_multiple_structure(self::step_structure_returns()), + 'endtourlabel' => new external_value(PARAM_RAW, 'Label of the end tour button'), 'displaystepnumbers' => new external_value(PARAM_BOOL, 'display step number'), - ], 'Tour config', VALUE_OPTIONAL) + ], 'Tour config', VALUE_OPTIONAL), ]); } @@ -110,10 +110,10 @@ class tour extends external_api { */ public static function reset_tour($tourid, $context, $pageurl) { $params = self::validate_parameters(self::reset_tour_parameters(), [ - 'tourid' => $tourid, - 'context' => $context, - 'pageurl' => $pageurl, - ]); + 'tourid' => $tourid, + 'context' => $context, + 'pageurl' => $pageurl, + ]); $context = \context_helper::instance_by_id($params['context']); self::validate_context($context); @@ -130,9 +130,9 @@ class tour extends external_api { \tool_usertours\event\tour_reset::create([ 'contextid' => $context->id, - 'objectid' => $params['tourid'], - 'other' => [ - 'pageurl' => $params['pageurl'], + 'objectid' => $params['tourid'], + 'other' => [ + 'pageurl' => $params['pageurl'], ], ])->trigger(); break; @@ -149,9 +149,9 @@ class tour extends external_api { */ public static function reset_tour_parameters() { return new external_function_parameters([ - 'tourid' => new external_value(PARAM_INT, 'Tour ID'), - 'context' => new external_value(PARAM_INT, 'Context ID'), - 'pageurl' => new external_value(PARAM_URL, 'Current page location'), + 'tourid' => new external_value(PARAM_INT, 'Tour ID'), + 'context' => new external_value(PARAM_INT, 'Context ID'), + 'pageurl' => new external_value(PARAM_URL, 'Current page location'), ]); } @@ -162,7 +162,7 @@ class tour extends external_api { */ public static function reset_tour_returns() { return new external_single_structure([ - 'startTour' => new external_value(PARAM_INT, 'Tour ID', VALUE_OPTIONAL), + 'startTour' => new external_value(PARAM_INT, 'Tour ID', VALUE_OPTIONAL), ]); } @@ -178,25 +178,26 @@ class tour extends external_api { */ public static function complete_tour($tourid, $context, $pageurl, $stepid, $stepindex) { $params = self::validate_parameters(self::complete_tour_parameters(), [ - 'tourid' => $tourid, - 'context' => $context, - 'pageurl' => $pageurl, - 'stepid' => $stepid, - 'stepindex' => $stepindex, - ]); + 'tourid' => $tourid, + 'context' => $context, + 'pageurl' => $pageurl, + 'stepid' => $stepid, + 'stepindex' => $stepindex, + ]); $context = \context_helper::instance_by_id($params['context']); self::validate_context($context); $tour = tourinstance::instance($params['tourid']); + $tour->mark_user_completed(); \tool_usertours\event\tour_ended::create([ 'contextid' => $context->id, - 'objectid' => $params['tourid'], - 'other' => [ - 'pageurl' => $params['pageurl'], - 'stepid' => $params['stepid'], + 'objectid' => $params['tourid'], + 'other' => [ + 'pageurl' => $params['pageurl'], + 'stepid' => $params['stepid'], 'stepindex' => $params['stepindex'], ], ])->trigger(); @@ -211,10 +212,10 @@ class tour extends external_api { */ public static function complete_tour_parameters() { return new external_function_parameters([ - 'tourid' => new external_value(PARAM_INT, 'Tour ID'), - 'context' => new external_value(PARAM_INT, 'Context ID'), - 'pageurl' => new external_value(PARAM_LOCALURL, 'Page URL'), - 'stepid' => new external_value(PARAM_INT, 'Step ID'), + 'tourid' => new external_value(PARAM_INT, 'Tour ID'), + 'context' => new external_value(PARAM_INT, 'Context ID'), + 'pageurl' => new external_value(PARAM_LOCALURL, 'Page URL'), + 'stepid' => new external_value(PARAM_INT, 'Step ID'), 'stepindex' => new external_value(PARAM_INT, 'Step Number'), ]); } @@ -240,12 +241,12 @@ class tour extends external_api { */ public static function step_shown($tourid, $context, $pageurl, $stepid, $stepindex) { $params = self::validate_parameters(self::step_shown_parameters(), [ - 'tourid' => $tourid, - 'context' => $context, - 'pageurl' => $pageurl, - 'stepid' => $stepid, - 'stepindex' => $stepindex, - ]); + 'tourid' => $tourid, + 'context' => $context, + 'pageurl' => $pageurl, + 'stepid' => $stepid, + 'stepindex' => $stepindex, + ]); $context = \context_helper::instance_by_id($params['context']); self::validate_context($context); @@ -257,11 +258,11 @@ class tour extends external_api { \tool_usertours\event\step_shown::create([ 'contextid' => $context->id, - 'objectid' => $params['stepid'], + 'objectid' => $params['stepid'], - 'other' => [ - 'pageurl' => $params['pageurl'], - 'tourid' => $params['tourid'], + 'other' => [ + 'pageurl' => $params['pageurl'], + 'tourid' => $params['tourid'], 'stepindex' => $params['stepindex'], ], ])->trigger(); @@ -276,10 +277,10 @@ class tour extends external_api { */ public static function step_shown_parameters() { return new external_function_parameters([ - 'tourid' => new external_value(PARAM_INT, 'Tour ID'), - 'context' => new external_value(PARAM_INT, 'Context ID'), - 'pageurl' => new external_value(PARAM_URL, 'Page URL'), - 'stepid' => new external_value(PARAM_INT, 'Step ID'), + 'tourid' => new external_value(PARAM_INT, 'Tour ID'), + 'context' => new external_value(PARAM_INT, 'Context ID'), + 'pageurl' => new external_value(PARAM_URL, 'Page URL'), + 'stepid' => new external_value(PARAM_INT, 'Step ID'), 'stepindex' => new external_value(PARAM_INT, 'Step Number'), ]); } @@ -300,24 +301,47 @@ class tour extends external_api { */ public static function step_structure_returns() { return new external_single_structure([ - 'title' => new external_value(PARAM_RAW, - 'Step Title'), - 'content' => new external_value(PARAM_RAW, - 'Step Content'), - 'element' => new external_value(PARAM_TEXT, - 'Step Target'), - 'placement' => new external_value(PARAM_TEXT, - 'Step Placement'), - 'delay' => new external_value(PARAM_INT, - 'Delay before showing the step (ms)', VALUE_OPTIONAL), - 'backdrop' => new external_value(PARAM_BOOL, - 'Whether a backdrop should be used', VALUE_OPTIONAL), - 'reflex' => new external_value(PARAM_BOOL, - 'Whether to move to the next step when the target element is clicked', VALUE_OPTIONAL), - 'orphan' => new external_value(PARAM_BOOL, - 'Whether to display the step even if it could not be found', VALUE_OPTIONAL), - 'stepid' => new external_value(PARAM_INT, - 'The actual ID of the step', VALUE_OPTIONAL), + 'title' => new external_value( + PARAM_RAW, + 'Step Title' + ), + 'content' => new external_value( + PARAM_RAW, + 'Step Content' + ), + 'element' => new external_value( + PARAM_TEXT, + 'Step Target' + ), + 'placement' => new external_value( + PARAM_TEXT, + 'Step Placement' + ), + 'delay' => new external_value( + PARAM_INT, + 'Delay before showing the step (ms)', + VALUE_OPTIONAL + ), + 'backdrop' => new external_value( + PARAM_BOOL, + 'Whether a backdrop should be used', + VALUE_OPTIONAL + ), + 'reflex' => new external_value( + PARAM_BOOL, + 'Whether to move to the next step when the target element is clicked', + VALUE_OPTIONAL + ), + 'orphan' => new external_value( + PARAM_BOOL, + 'Whether to display the step even if it could not be found', + VALUE_OPTIONAL + ), + 'stepid' => new external_value( + PARAM_INT, + 'The actual ID of the step', + VALUE_OPTIONAL + ), ]); } } diff --git a/admin/tool/usertours/classes/helper.php b/admin/tool/usertours/classes/helper.php index 6c2befa697a..8327dbd0ed4 100644 --- a/admin/tool/usertours/classes/helper.php +++ b/admin/tool/usertours/classes/helper.php @@ -14,29 +14,18 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tour helper. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours; use core\output\inplace_editable; -use tool_usertours\local\clientside_filter\clientside_filter; - -defined('MOODLE_INTERNAL') || die(); /** * Tour helper. * * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package tool_usertours */ class helper { - /** * @var MOVE_UP */ @@ -158,10 +147,10 @@ class helper { */ public static function get_reset_tour_for_all_link($tourid) { return new \moodle_url('/admin/tool/usertours/configure.php', [ - 'id' => $tourid, - 'action' => manager::ACTION_RESETFORALL, - 'sesskey' => sesskey(), - ]); + 'id' => $tourid, + 'action' => manager::ACTION_RESETFORALL, + 'sesskey' => sesskey(), + ]); } /** @@ -204,9 +193,9 @@ class helper { */ public static function get_export_tour_link($tourid) { $link = new \moodle_url('/admin/tool/usertours/configure.php', [ - 'action' => manager::ACTION_EXPORTTOUR, - 'id' => $tourid, - ]); + 'action' => manager::ACTION_EXPORTTOUR, + 'id' => $tourid, + ]); return $link; } @@ -219,8 +208,8 @@ class helper { */ public static function get_duplicate_tour_link($tourid) { $link = new \moodle_url('/admin/tool/usertours/configure.php', [ - 'action' => manager::ACTION_DUPLICATETOUR, - 'id' => $tourid, + 'action' => manager::ACTION_DUPLICATETOUR, + 'id' => $tourid, ]); return $link; @@ -234,10 +223,10 @@ class helper { */ public static function get_delete_tour_link($tourid) { return new \moodle_url('/admin/tool/usertours/configure.php', [ - 'id' => $tourid, - 'action' => manager::ACTION_DELETETOUR, - 'sesskey' => sesskey(), - ]); + 'id' => $tourid, + 'action' => manager::ACTION_DELETETOUR, + 'sesskey' => sesskey(), + ]); } /** @@ -262,18 +251,17 @@ class helper { * @param array $options Display options. * @return string */ - public static function format_icon_link($url, $icon, $alt, $iconcomponent = 'moodle', $options = array()) { + public static function format_icon_link($url, $icon, $alt, $iconcomponent = 'moodle', $options = []) { global $OUTPUT; return $OUTPUT->action_icon( - $url, - new \pix_icon($icon, $alt, $iconcomponent, [ - 'title' => $alt, - ]), - null, - $options - ); - + $url, + new \pix_icon($icon, $alt, $iconcomponent, [ + 'title' => $alt, + ]), + null, + $options + ); } /** @@ -282,7 +270,7 @@ class helper { * @param array $options Display options. * @return string */ - public static function get_filler_icon($options = array()) { + public static function get_filler_icon($options = []) { global $OUTPUT; return \html_writer::span( @@ -299,10 +287,10 @@ class helper { */ public static function get_delete_step_link($stepid) { return new \moodle_url('/admin/tool/usertours/configure.php', [ - 'action' => manager::ACTION_DELETESTEP, - 'id' => $stepid, - 'sesskey' => sesskey(), - ]); + 'action' => manager::ACTION_DELETESTEP, + 'id' => $stepid, + 'sesskey' => sesskey(), + ]); } /** @@ -314,16 +302,16 @@ class helper { public static function render_tourname_inplace_editable(tour $tour): inplace_editable { $name = format_text(static::get_string_from_input($tour->get_name()), FORMAT_HTML); return new inplace_editable( - 'tool_usertours', - 'tourname', - $tour->get_id(), - true, - \html_writer::link( - $tour->get_view_link(), - $name - ), - $tour->get_name() - ); + 'tool_usertours', + 'tourname', + $tour->get_id(), + true, + \html_writer::link( + $tour->get_view_link(), + $name + ), + $tour->get_name() + ); } /** @@ -335,13 +323,13 @@ class helper { public static function render_tourdescription_inplace_editable(tour $tour): inplace_editable { $description = format_text(static::get_string_from_input($tour->get_description()), FORMAT_HTML); return new inplace_editable( - 'tool_usertours', - 'tourdescription', - $tour->get_id(), - true, - $description, - $tour->get_description() - ); + 'tool_usertours', + 'tourdescription', + $tour->get_id(), + true, + $description, + $tour->get_description() + ); } /** @@ -364,15 +352,15 @@ class helper { } $editable = new inplace_editable( - 'tool_usertours', - 'tourenabled', - $tour->get_id(), - true, - $OUTPUT->pix_icon($icon, $alt, 'moodle', [ - 'title' => $alt, - ]), - $value - ); + 'tool_usertours', + 'tourenabled', + $tour->get_id(), + true, + $OUTPUT->pix_icon($icon, $alt, 'moodle', [ + 'title' => $alt, + ]), + $value + ); $editable->set_type_toggle(); return $editable; @@ -388,16 +376,16 @@ class helper { $title = format_text(static::get_string_from_input($step->get_title()), FORMAT_HTML); return new inplace_editable( - 'tool_usertours', - 'stepname', - $step->get_id(), - true, - \html_writer::link( - $step->get_edit_link(), - $title - ), - $step->get_title() - ); + 'tool_usertours', + 'stepname', + $step->get_id(), + true, + \html_writer::link( + $step->get_edit_link(), + $title + ), + $step->get_title() + ); } /** @@ -408,7 +396,7 @@ class helper { public static function get_tours() { global $DB; - $tours = $DB->get_records('tool_usertours_tours', array(), 'sortorder ASC'); + $tours = $DB->get_records('tool_usertours_tours', [], 'sortorder ASC'); $return = []; foreach ($tours as $tour) { $return[$tour->id] = tour::load_from_record($tour); @@ -435,7 +423,7 @@ class helper { public static function get_tour_from_sortorder($sortorder) { global $DB; - $tour = $DB->get_record('tool_usertours_tours', array('sortorder' => $sortorder)); + $tour = $DB->get_record('tool_usertours_tours', ['sortorder' => $sortorder]); return tour::load_from_record($tour); } @@ -460,7 +448,7 @@ class helper { $index = 0; foreach ($tours as $tour) { if ($tour->sortorder != $index) { - $DB->set_field('tool_usertours_tours', 'sortorder', $index, array('id' => $tour->id)); + $DB->set_field('tool_usertours_tours', 'sortorder', $index, ['id' => $tour->id]); } $index++; } @@ -508,7 +496,7 @@ class helper { public static function get_step_from_sortorder($tourid, $sortorder) { global $DB; - $step = $DB->get_record('tool_usertours_steps', array('tourid' => $tourid, 'sortorder' => $sortorder)); + $step = $DB->get_record('tool_usertours_steps', ['tourid' => $tourid, 'sortorder' => $sortorder]); return step::load_from_record($step); } @@ -538,11 +526,11 @@ class helper { if ($tours) { $filters = static::get_all_clientside_filters(); - $tourdetails = array_map(function($tour) use ($filters) { + $tourdetails = array_map(function ($tour) use ($filters) { return [ - 'tourId' => $tour->get_id(), - 'startTour' => $tour->should_show_for_user(), - 'filtervalues' => $tour->get_client_filter_values($filters), + 'tourId' => $tour->get_id(), + 'startTour' => $tour->should_show_for_user(), + 'filtervalues' => $tour->get_client_filter_values($filters), ]; }, $tours); @@ -552,8 +540,8 @@ class helper { } $PAGE->requires->js_call_amd('tool_usertours/usertours', 'init', [ - $tourdetails, - $filternames, + $tourdetails, + $filternames, ]); } } @@ -567,7 +555,7 @@ class helper { $filters = \core_component::get_component_classes_in_namespace('tool_usertours', 'local\filter'); $filters = array_keys($filters); - $filters = array_filter($filters, function($filterclass) { + $filters = array_filter($filters, function ($filterclass) { $rc = new \ReflectionClass($filterclass); return $rc->isInstantiable(); }); @@ -586,7 +574,7 @@ class helper { $filters = \core_component::get_component_classes_in_namespace('tool_usertours', 'local\clientside_filter'); $filters = array_keys($filters); - $filters = array_filter($filters, function($filterclass) { + $filters = array_filter($filters, function ($filterclass) { $rc = new \ReflectionClass($filterclass); return $rc->isInstantiable(); }); diff --git a/admin/tool/usertours/classes/local/clientside_filter/clientside_filter.php b/admin/tool/usertours/classes/local/clientside_filter/clientside_filter.php index 6fa403ac57a..ed394f29be6 100644 --- a/admin/tool/usertours/classes/local/clientside_filter/clientside_filter.php +++ b/admin/tool/usertours/classes/local/clientside_filter/clientside_filter.php @@ -14,18 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Clientside filter base. - * - * @package tool_usertours - * @copyright 2020 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\local\clientside_filter; -defined('MOODLE_INTERNAL') || die(); - use stdClass; use tool_usertours\local\filter\base; use tool_usertours\tour; @@ -33,6 +23,7 @@ use tool_usertours\tour; /** * Clientside filter base. * + * @package tool_usertours * @copyright 2020 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -46,10 +37,10 @@ abstract class clientside_filter extends base { public static function get_client_side_values(tour $tour): stdClass { $data = (object) []; - if (is_a(static::class, clientside_filter::class, true)) { + if (is_a(static::class, self::class, true)) { $data->filterdata = $tour->get_filter_values(static::get_filter_name()); } return $data; } -} \ No newline at end of file +} diff --git a/admin/tool/usertours/classes/local/clientside_filter/cssselector.php b/admin/tool/usertours/classes/local/clientside_filter/cssselector.php index e6d6c2d778e..ef30c589592 100644 --- a/admin/tool/usertours/classes/local/clientside_filter/cssselector.php +++ b/admin/tool/usertours/classes/local/clientside_filter/cssselector.php @@ -14,13 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Selector filter. - * - * @package tool_usertours - * @copyright 2020 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ namespace tool_usertours\local\clientside_filter; use stdClass; @@ -29,6 +22,7 @@ use tool_usertours\tour; /** * Course filter. * + * @package tool_usertours * @copyright 2020 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -107,7 +101,7 @@ class cssselector extends clientside_filter { // Filter values might not exist for tours that were created before this filter existed. if (!$filtervalues) { - return new stdClass; + return new stdClass(); } return (object) $filtervalues; diff --git a/admin/tool/usertours/classes/local/filter/accessdate.php b/admin/tool/usertours/classes/local/filter/accessdate.php index 26fecd4b8c7..7ca30008d65 100644 --- a/admin/tool/usertours/classes/local/filter/accessdate.php +++ b/admin/tool/usertours/classes/local/filter/accessdate.php @@ -13,29 +13,19 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . - -/** - * Access Date filter. - * - * @package tool_usertours - * @copyright 2019 Tom Dickman - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ namespace tool_usertours\local\filter; -defined('MOODLE_INTERNAL') || die(); - use context; use tool_usertours\tour; /** * Access date filter. Used to determine if USER should see a tour based on a particular access date. * + * @package tool_usertours * @copyright 2019 Tom Dickman * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class accessdate extends base { - /** * Access date filtering constant for setting base date as account creation date. */ @@ -74,12 +64,11 @@ class accessdate extends base { */ public static function get_filter_options() { - return array( + return [ self::FILTER_ACCOUNT_CREATION => get_string('filter_date_account_creation', 'tool_usertours'), self::FILTER_FIRST_LOGIN => get_string('filter_date_first_login', 'tool_usertours'), self::FILTER_LAST_LOGIN => get_string('filter_date_last_login', 'tool_usertours'), - ); - + ]; } /** @@ -96,8 +85,14 @@ class accessdate extends base { $range = "{$key}_range"; $enabled = "{$key}_enabled"; - $mform->addElement('advcheckbox', $enabled, get_string($key, 'tool_usertours'), - get_string('filter_accessdate_enabled', 'tool_usertours'), null, array(0, 1)); + $mform->addElement( + 'advcheckbox', + $enabled, + get_string($key, 'tool_usertours'), + get_string('filter_accessdate_enabled', 'tool_usertours'), + null, + [0, 1] + ); $mform->addHelpButton($enabled, $enabled, 'tool_usertours'); $mform->addElement('select', $key, ' ', self::get_filter_options()); @@ -110,7 +105,6 @@ class accessdate extends base { ]); $mform->setDefault($range, 90 * DAYSECS); $mform->hideIf($range, $enabled, 'notchecked'); - } /** @@ -224,4 +218,4 @@ class accessdate extends base { } return $result; } -} \ No newline at end of file +} diff --git a/admin/tool/usertours/classes/local/filter/base.php b/admin/tool/usertours/classes/local/filter/base.php index ff1de4442a9..fc73c58dedd 100644 --- a/admin/tool/usertours/classes/local/filter/base.php +++ b/admin/tool/usertours/classes/local/filter/base.php @@ -14,24 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Filter base. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\local\filter; -defined('MOODLE_INTERNAL') || die(); - use tool_usertours\tour; use context; /** * Filter base. * + * @package tool_usertours * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/admin/tool/usertours/classes/local/filter/category.php b/admin/tool/usertours/classes/local/filter/category.php index 0b1f119853d..fd5566d998c 100644 --- a/admin/tool/usertours/classes/local/filter/category.php +++ b/admin/tool/usertours/classes/local/filter/category.php @@ -14,24 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Category filter. - * - * @package tool_usertours - * @copyright 2017 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\local\filter; -defined('MOODLE_INTERNAL') || die(); - use tool_usertours\tour; use context; /** * Category filter. * + * @package tool_usertours * @copyright 2017 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/admin/tool/usertours/classes/local/filter/course.php b/admin/tool/usertours/classes/local/filter/course.php index 32fb21ddb5d..a440bc0598c 100644 --- a/admin/tool/usertours/classes/local/filter/course.php +++ b/admin/tool/usertours/classes/local/filter/course.php @@ -14,24 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Course filter. - * - * @package tool_usertours - * @copyright 2017 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\local\filter; -defined('MOODLE_INTERNAL') || die(); - use tool_usertours\tour; use context; /** * Course filter. * + * @package tool_usertours * @copyright 2017 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/admin/tool/usertours/classes/local/filter/courseformat.php b/admin/tool/usertours/classes/local/filter/courseformat.php index 95e2b7c8613..de2ca143523 100644 --- a/admin/tool/usertours/classes/local/filter/courseformat.php +++ b/admin/tool/usertours/classes/local/filter/courseformat.php @@ -14,24 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Course format filter. - * - * @package tool_usertours - * @copyright 2017 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\local\filter; -defined('MOODLE_INTERNAL') || die(); - use tool_usertours\tour; use context; /** * Course format filter. * + * @package tool_usertours * @copyright 2017 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/admin/tool/usertours/classes/local/filter/role.php b/admin/tool/usertours/classes/local/filter/role.php index a64ee83585c..e3c67ebe5a2 100644 --- a/admin/tool/usertours/classes/local/filter/role.php +++ b/admin/tool/usertours/classes/local/filter/role.php @@ -14,24 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Theme filter. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\local\filter; -defined('MOODLE_INTERNAL') || die(); - use tool_usertours\tour; use context; /** * Theme filter. * + * @package tool_usertours * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -106,7 +97,7 @@ class role extends base { } // Use a request cache to save on DB queries. - // We may be checking multiple tours and they'll all be for the same userid, and contextid + // We may be checking multiple tours and they'll all be for the same userid, and contextid. $cache = \cache::make_from_params(\cache_store::MODE_REQUEST, 'tool_usertours', 'filter_role'); // Get all of the roles used in this context, including special roles such as user, and frontpageuser. diff --git a/admin/tool/usertours/classes/local/filter/theme.php b/admin/tool/usertours/classes/local/filter/theme.php index 786684c9c13..e041d172cc3 100644 --- a/admin/tool/usertours/classes/local/filter/theme.php +++ b/admin/tool/usertours/classes/local/filter/theme.php @@ -14,24 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Theme filter. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\local\filter; -defined('MOODLE_INTERNAL') || die(); - use tool_usertours\tour; use context; /** * Theme filter. * + * @package tool_usertours * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/admin/tool/usertours/classes/local/forms/editstep.php b/admin/tool/usertours/classes/local/forms/editstep.php index b9418e75e22..8c586101f33 100644 --- a/admin/tool/usertours/classes/local/forms/editstep.php +++ b/admin/tool/usertours/classes/local/forms/editstep.php @@ -98,7 +98,7 @@ class editstep extends \moodleform { // Content type. $typeoptions = [ static::CONTENTTYPE_LANGSTRING => get_string('content_type_langstring', 'tool_usertours'), - static::CONTENTTYPE_MANUAL => get_string('content_type_manual', 'tool_usertours') + static::CONTENTTYPE_MANUAL => get_string('content_type_manual', 'tool_usertours'), ]; $mform->addElement('select', 'contenttype', get_string('content_type', 'tool_usertours'), $typeoptions); $mform->addHelpButton('contenttype', 'content_type', 'tool_usertours'); @@ -114,7 +114,7 @@ class editstep extends \moodleform { 'maxbytes' => $CFG->maxbytes, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'changeformat' => 1, - 'trusttext' => true + 'trusttext' => true, ]; $objs = $mform->createElement('editor', 'content', get_string('content', 'tool_usertours'), null, $editoroptions); // TODO: MDL-68540 We need to add the editor to a group element because editor element will not work with hideIf. diff --git a/admin/tool/usertours/classes/local/forms/edittour.php b/admin/tool/usertours/classes/local/forms/edittour.php index 80409b1aa78..cf6f50402cd 100644 --- a/admin/tool/usertours/classes/local/forms/edittour.php +++ b/admin/tool/usertours/classes/local/forms/edittour.php @@ -28,7 +28,8 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); require_once($CFG->libdir . '/formslib.php'); -use \tool_usertours\helper; +use tool_usertours\helper; +use tool_usertours\tour; /** * Form for editing tours. @@ -88,6 +89,17 @@ class edittour extends \moodleform { $mform->addElement('checkbox', 'displaystepnumbers', get_string('displaystepnumbers', 'tool_usertours')); $mform->addHelpButton('displaystepnumbers', 'displaystepnumbers', 'tool_usertours'); + $mform->addElement( + 'select', + 'showtourwhen', + get_string('showtourwhen', 'tool_usertours'), + [ + tour::SHOW_TOUR_UNTIL_COMPLETE => get_string('showtouruntilcomplete', 'tool_usertours'), + tour::SHOW_TOUR_ON_EACH_PAGE_VISIT => get_string('showtoureachtime', 'tool_usertours'), + ] + ); + $mform->setDefault('showtourwhen', tour::SHOW_TOUR_UNTIL_COMPLETE); + // Configuration. $this->tour->add_config_to_form($mform); diff --git a/admin/tool/usertours/classes/local/table/step_list.php b/admin/tool/usertours/classes/local/table/step_list.php index c774c6e63f6..87937d7b0e1 100644 --- a/admin/tool/usertours/classes/local/table/step_list.php +++ b/admin/tool/usertours/classes/local/table/step_list.php @@ -39,7 +39,6 @@ require_once($CFG->libdir . '/tablelib.php'); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class step_list extends \flexible_table { - /** * @var int $tourid The id of the tour. */ @@ -54,25 +53,25 @@ class step_list extends \flexible_table { parent::__construct('steps'); $this->tourid = $tourid; - $baseurl = new \moodle_url('/tool/usertours/configure.php', array( + $baseurl = new \moodle_url('/tool/usertours/configure.php', [ 'id' => $tourid, - )); + ]); $this->define_baseurl($baseurl); // Column definition. - $this->define_columns(array( + $this->define_columns([ 'title', 'content', 'target', 'actions', - )); + ]); - $this->define_headers(array( - get_string('title', 'tool_usertours'), + $this->define_headers([ + get_string('title', 'tool_usertours'), get_string('content', 'tool_usertours'), - get_string('target', 'tool_usertours'), + get_string('target', 'tool_usertours'), get_string('actions', 'tool_usertours'), - )); + ]); $this->set_attribute('class', 'admintable generaltable steptable'); $this->setup(); @@ -98,8 +97,14 @@ class step_list extends \flexible_table { protected function col_content(step $step) { $content = $step->get_content(); $systemcontext = \context_system::instance(); - $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $systemcontext->id, - 'tool_usertours', 'stepcontent', $step->get_id()); + $content = file_rewrite_pluginfile_urls( + $content, + 'pluginfile.php', + $systemcontext->id, + 'tool_usertours', + 'stepcontent', + $step->get_id() + ); $content = helper::get_string_from_input($content); $content = step::get_step_image_from_input($content); @@ -135,8 +140,11 @@ class step_list extends \flexible_table { if ($step->is_last_step()) { $actions[] = helper::get_filler_icon(); } else { - $actions[] = helper::format_icon_link($step->get_movedown_link(), 't/down', - get_string('movestepdown', 'tool_usertours')); + $actions[] = helper::format_icon_link( + $step->get_movedown_link(), + 't/down', + get_string('movestepdown', 'tool_usertours') + ); } $actions[] = helper::format_icon_link($step->get_edit_link(), 't/edit', get_string('edit')); diff --git a/admin/tool/usertours/classes/local/table/tour_list.php b/admin/tool/usertours/classes/local/table/tour_list.php index 0ea20a13dbc..dd5298cd8d1 100644 --- a/admin/tool/usertours/classes/local/table/tour_list.php +++ b/admin/tool/usertours/classes/local/table/tour_list.php @@ -38,7 +38,6 @@ require_once($CFG->libdir . '/tablelib.php'); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class tour_list extends \flexible_table { - /** @var int The count of all tours. */ protected int $tourcount = 0; @@ -52,21 +51,21 @@ class tour_list extends \flexible_table { $this->define_baseurl($baseurl); // Column definition. - $this->define_columns(array( + $this->define_columns([ 'name', 'description', 'appliesto', 'enabled', 'actions', - )); + ]); - $this->define_headers(array( + $this->define_headers([ get_string('name', 'tool_usertours'), get_string('description', 'tool_usertours'), get_string('appliesto', 'tool_usertours'), get_string('enabled', 'tool_usertours'), get_string('actions', 'tool_usertours'), - )); + ]); $this->set_attribute('class', 'admintable generaltable'); $this->setup(); @@ -129,22 +128,32 @@ class tour_list extends \flexible_table { if ($tour->is_first_tour()) { $actions[] = helper::get_filler_icon(); } else { - $actions[] = helper::format_icon_link($tour->get_moveup_link(), 't/up', - get_string('movetourup', 'tool_usertours')); + $actions[] = helper::format_icon_link( + $tour->get_moveup_link(), + 't/up', + get_string('movetourup', 'tool_usertours') + ); } if ($tour->is_last_tour($this->tourcount)) { $actions[] = helper::get_filler_icon(); } else { - $actions[] = helper::format_icon_link($tour->get_movedown_link(), 't/down', - get_string('movetourdown', 'tool_usertours')); + $actions[] = helper::format_icon_link( + $tour->get_movedown_link(), + 't/down', + get_string('movetourdown', 'tool_usertours') + ); } $actions[] = helper::format_icon_link($tour->get_view_link(), 't/viewdetails', get_string('view')); $actions[] = helper::format_icon_link($tour->get_edit_link(), 't/edit', get_string('edit')); $actions[] = helper::format_icon_link($tour->get_duplicate_link(), 't/copy', get_string('duplicate')); - $actions[] = helper::format_icon_link($tour->get_export_link(), 't/export', - get_string('exporttour', 'tool_usertours'), 'tool_usertours'); + $actions[] = helper::format_icon_link( + $tour->get_export_link(), + 't/export', + get_string('exporttour', 'tool_usertours'), + 'tool_usertours' + ); $actions[] = helper::format_icon_link($tour->get_delete_link(), 't/delete', get_string('delete'), null, [ 'data-action' => 'delete', 'data-id' => $tour->get_id(), diff --git a/admin/tool/usertours/classes/local/target/base.php b/admin/tool/usertours/classes/local/target/base.php index 663e5bf03b6..e3b829bfb04 100644 --- a/admin/tool/usertours/classes/local/target/base.php +++ b/admin/tool/usertours/classes/local/target/base.php @@ -14,23 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Target base. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\local\target; -defined('MOODLE_INTERNAL') || die(); - use tool_usertours\step; /** * Target base. * + * @package tool_usertours * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ diff --git a/admin/tool/usertours/classes/local/target/block.php b/admin/tool/usertours/classes/local/target/block.php index 095e9018c4c..06071c7d5cb 100644 --- a/admin/tool/usertours/classes/local/target/block.php +++ b/admin/tool/usertours/classes/local/target/block.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_usertours\local\target; + /** * Block target. * @@ -21,21 +23,7 @@ * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_usertours\local\target; - -defined('MOODLE_INTERNAL') || die(); - -use tool_usertours\step; - -/** - * Block target. - * - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ class block extends base { - /** * Convert the target value to a valid CSS selector for use in the * output configuration. @@ -101,8 +89,12 @@ class block extends base { * @param MoodleQuickForm $mform The form to add configuration to. */ public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) { - $mform->hideIf('targetvalue_block', 'targettype', 'noteq', - \tool_usertours\target::get_target_constant_for_class(self::class)); + $mform->hideIf( + 'targetvalue_block', + 'targettype', + 'noteq', + \tool_usertours\target::get_target_constant_for_class(self::class) + ); } /** diff --git a/admin/tool/usertours/classes/local/target/selector.php b/admin/tool/usertours/classes/local/target/selector.php index b0cc92682f0..16057c0e04c 100644 --- a/admin/tool/usertours/classes/local/target/selector.php +++ b/admin/tool/usertours/classes/local/target/selector.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_usertours\local\target; + /** * Selector target. * @@ -21,21 +23,7 @@ * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_usertours\local\target; - -defined('MOODLE_INTERNAL') || die(); - -use tool_usertours\step; - -/** - * Selector target. - * - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ class selector extends base { - /** * Convert the target value to a valid CSS selector for use in the * output configuration. @@ -91,8 +79,12 @@ class selector extends base { * @param MoodleQuickForm $mform The form to add configuration to. */ public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) { - $mform->hideIf('targetvalue_selector', 'targettype', 'noteq', - \tool_usertours\target::get_target_constant_for_class(self::class)); + $mform->hideIf( + 'targetvalue_selector', + 'targettype', + 'noteq', + \tool_usertours\target::get_target_constant_for_class(self::class) + ); } /** diff --git a/admin/tool/usertours/classes/local/target/unattached.php b/admin/tool/usertours/classes/local/target/unattached.php index 316fdea4b85..0c530368710 100644 --- a/admin/tool/usertours/classes/local/target/unattached.php +++ b/admin/tool/usertours/classes/local/target/unattached.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_usertours\local\target; + /** * A step designed to be orphaned. * @@ -21,19 +23,6 @@ * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_usertours\local\target; - -defined('MOODLE_INTERNAL') || die(); - -use tool_usertours\step; - -/** - * A step designed to be orphaned. - * - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ class unattached extends base { /** * @var array $forcedsettings The settings forced by this type. diff --git a/admin/tool/usertours/classes/manager.php b/admin/tool/usertours/classes/manager.php index ab207e6ce5c..cd9c22ebfee 100644 --- a/admin/tool/usertours/classes/manager.php +++ b/admin/tool/usertours/classes/manager.php @@ -14,18 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tour manager. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours; -defined('MOODLE_INTERNAL') || die(); - use tool_usertours\local\forms; use tool_usertours\local\table; use core\notification; @@ -33,11 +23,11 @@ use core\notification; /** * Tour manager. * + * @package tool_usertours * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class manager { - /** * @var ACTION_LISTTOURS The action to get the list of tours. */ @@ -163,7 +153,7 @@ class manager { $PAGE->set_primary_active_tab('siteadminnode'); // Add the main content. - switch($action) { + switch ($action) { case self::ACTION_NEWTOUR: case self::ACTION_EDITTOUR: $this->edit_tour(optional_param('id', null, PARAM_INT)); @@ -356,7 +346,6 @@ class manager { if ($id) { $tour = tour::instance($id); $PAGE->navbar->add(helper::get_string_from_input($tour->get_name()), $tour->get_edit_link()); - } else { $tour = new tour(); $PAGE->navbar->add(get_string('newtour', 'tool_usertours'), $tour->get_edit_link()); @@ -374,6 +363,7 @@ class manager { $tour->set_enabled(!empty($data->enabled)); $tour->set_endtourlabel($data->endtourlabel); $tour->set_display_step_numbers(!empty($data->displaystepnumbers)); + $tour->set_showtourwhen($data->showtourwhen); foreach (configuration::get_defaultable_keys() as $key) { $tour->set_config($key, $data->$key); @@ -403,6 +393,7 @@ class manager { foreach (helper::get_all_filters() as $filterclass) { $filterclass::prepare_filter_values_for_form($tour, $data); } + $form->set_data($data); } @@ -568,7 +559,7 @@ class manager { require_sesskey(); - $tour = $DB->get_record('tool_usertours_tours', array('id' => $tourid)); + $tour = $DB->get_record('tool_usertours_tours', ['id' => $tourid]); $tour->enabled = $visibility; $DB->update_record('tool_usertours_tours', $tour); @@ -784,9 +775,10 @@ class manager { */ protected static function _move_tour(tour $tour, $direction) { // We can't move the first tour higher, nor the last tour any lower. - if (($tour->is_first_tour() && $direction == helper::MOVE_UP) || - ($tour->is_last_tour() && $direction == helper::MOVE_DOWN)) { - + if ( + ($tour->is_first_tour() && $direction == helper::MOVE_UP) || + ($tour->is_last_tour() && $direction == helper::MOVE_DOWN) + ) { return; } diff --git a/admin/tool/usertours/classes/output/renderer.php b/admin/tool/usertours/classes/output/renderer.php index 27c1ae37901..6c9ed28f8ba 100644 --- a/admin/tool/usertours/classes/output/renderer.php +++ b/admin/tool/usertours/classes/output/renderer.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_usertours\output; + /** * Renderer. * @@ -21,16 +23,5 @@ * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_usertours\output; - -defined('MOODLE_INTERNAL') || die(); - -/** - * Renderer. - * - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ class renderer extends \plugin_renderer_base { } diff --git a/admin/tool/usertours/classes/output/step.php b/admin/tool/usertours/classes/output/step.php index a3f5f81a024..a85a0a5664a 100644 --- a/admin/tool/usertours/classes/output/step.php +++ b/admin/tool/usertours/classes/output/step.php @@ -38,7 +38,6 @@ use tool_usertours\step as stepsource; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class step implements \renderable { - /** * @var The step instance. */ @@ -65,8 +64,14 @@ class step implements \renderable { $content = $step->get_content(); $systemcontext = \context_system::instance(); - $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $systemcontext->id, - 'tool_usertours', 'stepcontent', $step->get_id()); + $content = file_rewrite_pluginfile_urls( + $content, + 'pluginfile.php', + $systemcontext->id, + 'tool_usertours', + 'stepcontent', + $step->get_id() + ); $content = helper::get_string_from_input($content); $content = $step::get_step_image_from_input($content); @@ -74,17 +79,17 @@ class step implements \renderable { $result = (object) [ 'stepid' => $step->get_id(), 'title' => \core_external\util::format_text( - helper::get_string_from_input($step->get_title()), - FORMAT_HTML, - $PAGE->context->id, - 'tool_usertours' - )[0], + helper::get_string_from_input($step->get_title()), + FORMAT_HTML, + $PAGE->context->id, + 'tool_usertours' + )[0], 'content' => \core_external\util::format_text( - $content, - $step->get_contentformat(), - $PAGE->context->id, - 'tool_usertours' - )[0], + $content, + $step->get_contentformat(), + $PAGE->context->id, + 'tool_usertours' + )[0], 'element' => $step->get_target()->convert_to_css(), ]; diff --git a/admin/tool/usertours/classes/output/tour.php b/admin/tool/usertours/classes/output/tour.php index 6e933fb7cc4..d232e44d163 100644 --- a/admin/tool/usertours/classes/output/tour.php +++ b/admin/tool/usertours/classes/output/tour.php @@ -14,6 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_usertours\output; + +use tool_usertours\tour as toursource; + /** * Tour renderable. * @@ -21,21 +25,7 @@ * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_usertours\output; - -defined('MOODLE_INTERNAL') || die(); - -use tool_usertours\tour as toursource; - -/** - * Tour renderable. - * - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ class tour implements \renderable { - /** * @var The tour instance. */ diff --git a/admin/tool/usertours/classes/privacy/provider.php b/admin/tool/usertours/classes/privacy/provider.php index db71ee9a1a9..c65b204860f 100644 --- a/admin/tool/usertours/classes/privacy/provider.php +++ b/admin/tool/usertours/classes/privacy/provider.php @@ -14,25 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Privacy Subsystem implementation for tool_usertours. - * - * @package tool_usertours - * @copyright 2018 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours\privacy; -use \core_privacy\local\request\writer; -use \core_privacy\local\metadata\collection; -use \core_privacy\local\request\transform; - -defined('MOODLE_INTERNAL') || die(); +use core_privacy\local\request\writer; +use core_privacy\local\metadata\collection; +use core_privacy\local\request\transform; /** * Implementation of the privacy subsystem plugin provider for the user tours feature. * + * @package tool_usertours * @copyright 2018 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ @@ -41,9 +32,7 @@ class provider implements \core_privacy\local\metadata\provider, // This plugin has some sitewide user preferences to export. - \core_privacy\local\request\user_preference_provider -{ - + \core_privacy\local\request\user_preference_provider { /** * Returns meta data about this system. * diff --git a/admin/tool/usertours/classes/step.php b/admin/tool/usertours/classes/step.php index 95715e177ad..485bc081536 100644 --- a/admin/tool/usertours/classes/step.php +++ b/admin/tool/usertours/classes/step.php @@ -14,6 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_usertours; + +use context_system; +use stdClass; + /** * Step class. * @@ -21,22 +26,7 @@ * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_usertours; - -use context_system; -use stdClass; - -defined('MOODLE_INTERNAL') || die(); - -/** - * Step class. - * - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ class step { - /** * @var int $id The id of the step. */ @@ -137,7 +127,7 @@ class step { global $DB; return $this->reload_from_record( - $DB->get_record('tool_usertours_steps', array('id' => $id)) + $DB->get_record('tool_usertours_steps', ['id' => $id]) ); } @@ -414,7 +404,7 @@ class step { */ public function get_config($key = null, $default = null) { if ($this->config === null) { - $this->config = (object) array(); + $this->config = (object) []; } if ($key === null) { @@ -448,7 +438,7 @@ class step { */ public function set_config($key, $value) { if ($this->config === null) { - $this->config = (object) array(); + $this->config = (object) []; } if ($value === null) { @@ -497,7 +487,7 @@ class step { 'name' => $file->get_filename(), 'path' => $file->get_filepath(), 'content' => base64_encode($file->get_content()), - 'encode' => 'base64' + 'encode' => 'base64', ]; } @@ -635,7 +625,7 @@ class step { return; } - $DB->delete_records('tool_usertours_steps', array('id' => $this->id)); + $DB->delete_records('tool_usertours_steps', ['id' => $this->id]); $this->get_tour()->reset_step_sortorder(); // Notify of a change to the step configuration. @@ -817,15 +807,19 @@ class step { return $content; } - $content = preg_replace_callback('%@@PIXICON::(?P([^::]*))::(?P([^@@]*))@@%', - function(array $matches) { + $content = preg_replace_callback( + '%@@PIXICON::(?P([^::]*))::(?P([^@@]*))@@%', + function (array $matches) { global $OUTPUT; $component = $matches['component']; if ($component == 'moodle') { $component = 'core'; } - return \html_writer::img($OUTPUT->image_url($matches['identifier'], $component)->out(false), '', - ['class' => 'img-fluid']); + return \html_writer::img( + $OUTPUT->image_url($matches['identifier'], $component)->out(false), + '', + ['class' => 'img-fluid'] + ); }, $content ); diff --git a/admin/tool/usertours/classes/target.php b/admin/tool/usertours/classes/target.php index f65c2caa0e2..9299ca5180c 100644 --- a/admin/tool/usertours/classes/target.php +++ b/admin/tool/usertours/classes/target.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_usertours; + /** * Target class. * @@ -21,19 +23,7 @@ * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_usertours; - -defined('MOODLE_INTERNAL') || die(); - -/** - * Target class. - * - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ class target { - /** * @var TARGET_SELECTOR The target is a CSS selector. */ diff --git a/admin/tool/usertours/classes/tour.php b/admin/tool/usertours/classes/tour.php index c51f9e85f0d..61001c5745d 100644 --- a/admin/tool/usertours/classes/tour.php +++ b/admin/tool/usertours/classes/tour.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_usertours; + /** * Tour class. * @@ -21,21 +23,7 @@ * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_usertours; - -use tool_usertours\local\clientside_filter\clientside_filter; - -defined('MOODLE_INTERNAL') || die(); - -/** - * Tour class. - * - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ class tour { - /** * The tour is currently disabled * @@ -64,6 +52,12 @@ class tour { */ const TOUR_REQUESTED_BY_USER = 'tool_usertours_tour_reset_time_'; + /** @var int Whether to show the tour only until it has been marked complete */ + const SHOW_TOUR_UNTIL_COMPLETE = 1; + + /** @var int Whether to show the tour every time a page matches */ + const SHOW_TOUR_ON_EACH_PAGE_VISIT = 2; + /** * @var $id The tour ID. */ @@ -157,7 +151,7 @@ class tour { global $DB; return $this->reload_from_record( - $DB->get_record('tool_usertours_tours', array('id' => $id), '*', MUST_EXIST) + $DB->get_record('tool_usertours_tours', ['id' => $id], '*', MUST_EXIST) ); } @@ -424,7 +418,7 @@ class tour { * @return object */ public function to_record() { - return (object) array( + return (object) [ 'id' => $this->id, 'name' => $this->name, 'description' => $this->description, @@ -434,7 +428,7 @@ class tour { 'endtourlabel' => $this->endtourlabel, 'configdata' => json_encode($this->config), 'displaystepnumbers' => $this->displaystepnumbers, - ); + ]; } /** @@ -519,7 +513,7 @@ class tour { */ public function get_config($key = null, $default = null) { if ($this->config === null) { - $this->config = (object) array(); + $this->config = (object) []; } if ($key === null) { return $this->config; @@ -545,7 +539,7 @@ class tour { */ public function set_config($key, $value) { if ($this->config === null) { - $this->config = (object) array(); + $this->config = (object) []; } $this->config->$key = $value; $this->dirty = true; @@ -602,7 +596,7 @@ class tour { } // Remove the configuration for the tour. - $DB->delete_records('tool_usertours_tours', array('id' => $this->id)); + $DB->delete_records('tool_usertours_tours', ['id' => $this->id]); helper::reset_tour_sortorder(); $this->remove_user_preferences(); @@ -617,11 +611,11 @@ class tour { */ public function reset_step_sortorder() { global $DB; - $steps = $DB->get_records('tool_usertours_steps', array('tourid' => $this->id), 'sortorder ASC', 'id'); + $steps = $DB->get_records('tool_usertours_steps', ['tourid' => $this->id], 'sortorder ASC', 'id'); $index = 0; foreach ($steps as $step) { - $DB->set_field('tool_usertours_steps', 'sortorder', $index, array('id' => $step->id)); + $DB->set_field('tool_usertours_steps', 'sortorder', $index, ['id' => $step->id]); $index++; } @@ -653,6 +647,11 @@ class tour { return false; } + if ($this->get_showtourwhen() === self::SHOW_TOUR_ON_EACH_PAGE_VISIT) { + // The tour should be shown on every page visit. + return true; + } + if ($tourcompletiondate = get_user_preferences(self::TOUR_LAST_COMPLETED_BY_USER . $this->get_id(), null)) { if ($tourresetdate = get_user_preferences(self::TOUR_REQUESTED_BY_USER . $this->get_id(), null)) { if ($tourresetdate >= $tourcompletiondate) { @@ -775,6 +774,7 @@ class tour { */ public function prepare_data_for_form() { $data = $this->to_record(); + $data->showtourwhen = $this->get_showtourwhen(); foreach (configuration::get_defaultable_keys() as $key) { $data->$key = $this->get_config($key, configuration::get_default_value($key)); } @@ -872,4 +872,29 @@ class tour { public function get_display_step_numbers(): bool { return $this->displaystepnumbers; } + + /** + * Set the value for the when to show the tour. + * + * @see self::SHOW_TOUR_UNTIL_COMPLETE + * @see self::SHOW_TOUR_ON_EACH_PAGE_VISIT + * + * @param int $value + * @return self + */ + public function set_showtourwhen(int $value): tour { + return $this->set_config('showtourwhen', $value); + } + + /** + * When to show the tour. + * + * @see self::SHOW_TOUR_UNTIL_COMPLETE + * @see self::SHOW_TOUR_ON_EACH_PAGE_VISIT + * + * @return int + */ + public function get_showtourwhen(): int { + return $this->get_config('showtourwhen', self::SHOW_TOUR_UNTIL_COMPLETE); + } } diff --git a/admin/tool/usertours/configure.php b/admin/tool/usertours/configure.php index cb7bc983218..5ff066b18e9 100644 --- a/admin/tool/usertours/configure.php +++ b/admin/tool/usertours/configure.php @@ -31,5 +31,5 @@ $pluginmanager = new \tool_usertours\manager(); $PAGE->set_context(context_system::instance()); $pluginmanager->execute( - $action - ); + $action +); diff --git a/admin/tool/usertours/db/access.php b/admin/tool/usertours/db/access.php index 1e8e6b927c9..4dd38c2245d 100644 --- a/admin/tool/usertours/db/access.php +++ b/admin/tool/usertours/db/access.php @@ -24,13 +24,13 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( +$capabilities = [ 'tool/usertours:managetours' => [ 'captype' => 'write', 'riskbitmask' => RISK_XSS, 'contextlevel' => CONTEXT_SYSTEM, 'archetypes' => [ 'manager' => CAP_ALLOW, - ] + ], ], -); +]; diff --git a/admin/tool/usertours/db/caches.php b/admin/tool/usertours/db/caches.php index 3ae3c8fb4c7..28e38465699 100644 --- a/admin/tool/usertours/db/caches.php +++ b/admin/tool/usertours/db/caches.php @@ -24,19 +24,19 @@ defined('MOODLE_INTERNAL') || die(); -$definitions = array( - 'tourdata' => array( +$definitions = [ + 'tourdata' => [ 'mode' => cache_store::MODE_APPLICATION, 'simplekeys' => true, 'simpledata' => true, 'staticacceleration' => true, 'staticaccelerationsize' => 1, - ), - 'stepdata' => array( + ], + 'stepdata' => [ 'mode' => cache_store::MODE_APPLICATION, 'simplekeys' => true, 'simpledata' => true, 'staticacceleration' => true, 'staticaccelerationsize' => 1, - ), -); + ], +]; diff --git a/admin/tool/usertours/db/services.php b/admin/tool/usertours/db/services.php index 38e65eaa5a5..9b47633c5d6 100644 --- a/admin/tool/usertours/db/services.php +++ b/admin/tool/usertours/db/services.php @@ -24,40 +24,40 @@ defined('MOODLE_INTERNAL') || die(); -$functions = array( - 'tool_usertours_fetch_and_start_tour' => array( +$functions = [ + 'tool_usertours_fetch_and_start_tour' => [ 'classname' => 'tool_usertours\external\tour', 'methodname' => 'fetch_and_start_tour', 'description' => 'Fetch the specified tour', 'type' => 'read', 'capabilities' => '', 'ajax' => true, - ), + ], - 'tool_usertours_step_shown' => array( + 'tool_usertours_step_shown' => [ 'classname' => 'tool_usertours\external\tour', 'methodname' => 'step_shown', 'description' => 'Mark the specified step as completed for the current user', 'type' => 'write', 'capabilities' => '', 'ajax' => true, - ), + ], - 'tool_usertours_complete_tour' => array( + 'tool_usertours_complete_tour' => [ 'classname' => 'tool_usertours\external\tour', 'methodname' => 'complete_tour', 'description' => 'Mark the specified tour as completed for the current user', 'type' => 'write', 'capabilities' => '', 'ajax' => true, - ), + ], - 'tool_usertours_reset_tour' => array( + 'tool_usertours_reset_tour' => [ 'classname' => 'tool_usertours\external\tour', 'methodname' => 'reset_tour', 'description' => 'Remove the specified tour', 'type' => 'write', 'capabilities' => '', 'ajax' => true, - ), -); + ], +]; diff --git a/admin/tool/usertours/lang/en/tool_usertours.php b/admin/tool/usertours/lang/en/tool_usertours.php index 0672417b728..815806de4a9 100644 --- a/admin/tool/usertours/lang/en/tool_usertours.php +++ b/admin/tool/usertours/lang/en/tool_usertours.php @@ -36,6 +36,9 @@ $string['description_help'] = 'The description of a tour may be added as plain t Alternatively, a language string ID may be entered in the format identifier,component (with no brackets or space after the comma).'; $string['displaystepnumbers'] = 'Display step numbers'; $string['displaystepnumbers_help'] = 'Whether to display a step number count e.g. 1/4, 2/4 etc. to indicate the length of the user tour.'; +$string['showtourwhen'] = 'Show tour'; +$string['showtoureachtime'] = 'each time a filter matches it'; +$string['showtouruntilcomplete'] = 'until it has been closed'; $string['confirmstepremovalquestion'] = 'Are you sure that you wish to remove this step?'; $string['confirmstepremovaltitle'] = 'Confirm step removal'; $string['confirmtourremovalquestion'] = 'Are you sure that you wish to remove this tour?'; diff --git a/admin/tool/usertours/tests/accessdate_filter_test.php b/admin/tool/usertours/tests/accessdate_filter_test.php index 52b44c3c31b..1458ee14763 100644 --- a/admin/tool/usertours/tests/accessdate_filter_test.php +++ b/admin/tool/usertours/tests/accessdate_filter_test.php @@ -24,9 +24,9 @@ use tool_usertours\local\filter\accessdate; * @package tool_usertours * @copyright 2019 Tom Dickman * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \tool_usertours\local\filter\accessdate */ class accessdate_filter_test extends \advanced_testcase { - public function setUp(): void { $this->resetAfterTest(true); } @@ -36,7 +36,7 @@ class accessdate_filter_test extends \advanced_testcase { * * @return array */ - public function filter_matches_provider() { + public static function filter_matches_provider(): array { return [ 'No config set; Matches' => [ [], @@ -45,61 +45,61 @@ class accessdate_filter_test extends \advanced_testcase { ], 'Filter is not enabled; Match' => [ ['filter_accessdate' => accessdate::FILTER_ACCOUNT_CREATION, 'filter_accessdate_range' => 90 * DAYSECS, - 'filter_accessdate_enabled' => 0], + 'filter_accessdate_enabled' => 0, ], ['timecreated' => time() - (89 * DAYSECS)], true, ], 'Filter is not enabled (tour would not be displayed if it was); Match' => [ ['filter_accessdate' => accessdate::FILTER_ACCOUNT_CREATION, 'filter_accessdate_range' => 90 * DAYSECS, - 'filter_accessdate_enabled' => 0], + 'filter_accessdate_enabled' => 0, ], ['timecreated' => time() - (91 * DAYSECS)], true, ], 'Inside range of account creation date; Match' => [ ['filter_accessdate' => accessdate::FILTER_ACCOUNT_CREATION, 'filter_accessdate_range' => 90 * DAYSECS, - 'filter_accessdate_enabled' => 1], + 'filter_accessdate_enabled' => 1, ], ['timecreated' => time() - (89 * DAYSECS)], true, ], 'Outside range of account creation date; No match' => [ ['filter_accessdate' => accessdate::FILTER_ACCOUNT_CREATION, 'filter_accessdate_range' => 90 * DAYSECS, - 'filter_accessdate_enabled' => 1], + 'filter_accessdate_enabled' => 1, ], ['timecreated' => time() - (91 * DAYSECS)], false, ], 'Inside range of first login date; Match' => [ ['filter_accessdate' => accessdate::FILTER_FIRST_LOGIN, 'filter_accessdate_range' => 90 * DAYSECS, - 'filter_accessdate_enabled' => 1], + 'filter_accessdate_enabled' => 1, ], ['firstaccess' => time() - (89 * DAYSECS)], true, ], 'Outside range of first login date; No match' => [ ['filter_accessdate' => accessdate::FILTER_FIRST_LOGIN, 'filter_accessdate_range' => 90 * DAYSECS, - 'filter_accessdate_enabled' => 1], + 'filter_accessdate_enabled' => 1, ], ['firstaccess' => time() - (91 * DAYSECS)], false, ], 'Inside range of last login date; Match' => [ ['filter_accessdate' => accessdate::FILTER_LAST_LOGIN, 'filter_accessdate_range' => 90 * DAYSECS, - 'filter_accessdate_enabled' => 1], + 'filter_accessdate_enabled' => 1, ], ['lastlogin' => time() - (89 * DAYSECS)], true, ], 'Outside range of last login date; No match' => [ ['filter_accessdate' => accessdate::FILTER_LAST_LOGIN, 'filter_accessdate_range' => 90 * DAYSECS, - 'filter_accessdate_enabled' => 1], + 'filter_accessdate_enabled' => 1, ], ['lastlogin' => time() - (91 * DAYSECS)], false, ], 'User has never logged in, but tour should be visible; Match' => [ ['filter_accessdate' => accessdate::FILTER_LAST_LOGIN, 'filter_accessdate_range' => 90 * DAYSECS, - 'filter_accessdate_enabled' => 1], + 'filter_accessdate_enabled' => 1, ], ['lastlogin' => 0, 'timecreated' => time() - (89 * DAYSECS)], true, ], 'User has never logged in, and tour should not be visible; No match' => [ ['filter_accessdate' => accessdate::FILTER_LAST_LOGIN, 'filter_accessdate_range' => 90 * DAYSECS, - 'filter_accessdate_enabled' => 1], + 'filter_accessdate_enabled' => 1, ], ['lastlogin' => 0, 'timecreated' => time() - (91 * DAYSECS)], false, ], @@ -115,7 +115,7 @@ class accessdate_filter_test extends \advanced_testcase { * @param array $userstate any user state required for test. * @param bool $expected result expected. */ - public function test_filter_matches($filtervalues, $userstate, $expected) { + public function test_filter_matches($filtervalues, $userstate, $expected): void { $course = $this->getDataGenerator()->create_course(); $context = \context_course::instance($course->id); @@ -127,5 +127,4 @@ class accessdate_filter_test extends \advanced_testcase { $this->assertEquals($expected, accessdate::filter_matches($tour, $context)); } - } diff --git a/admin/tool/usertours/tests/behat/behat_tool_usertours.php b/admin/tool/usertours/tests/behat/behat_tool_usertours.php index ef00bd2f7a0..797f5b5142a 100644 --- a/admin/tool/usertours/tests/behat/behat_tool_usertours.php +++ b/admin/tool/usertours/tests/behat/behat_tool_usertours.php @@ -25,7 +25,7 @@ require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php'); -use Behat\Gherkin\Node\TableNode as TableNode; +use Behat\Gherkin\Node\TableNode; /** * User tour related steps definitions. * @@ -35,7 +35,6 @@ use Behat\Gherkin\Node\TableNode as TableNode; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class behat_tool_usertours extends behat_base { - /** * Add a new user tour. * @@ -90,8 +89,9 @@ class behat_tool_usertours extends behat_base { * @Given /^I open the User tour settings page$/ */ public function i_open_the_user_tour_settings_page() { - $this->execute('behat_navigation::i_navigate_to_in_site_administration', - get_string('appearance', 'admin') . ' > ' . + $this->execute( + 'behat_navigation::i_navigate_to_in_site_administration', + get_string('appearance', 'admin') . ' > ' . get_string('usertours', 'tool_usertours') ); } diff --git a/admin/tool/usertours/tests/behat/tour_prevents_completion.feature b/admin/tool/usertours/tests/behat/tour_prevents_completion.feature new file mode 100644 index 00000000000..0b2e687be9f --- /dev/null +++ b/admin/tool/usertours/tests/behat/tour_prevents_completion.feature @@ -0,0 +1,29 @@ +@tool @tool_usertours +Feature: Prevent yours from being marked as complete + In order to impart key information + As an administrator + I can prevent a user tour from being marked as complete + + Background: + Given I log in as "admin" + And I add a new user tour with: + | Name | First tour | + | Description | My first tour | + | Apply to URL match | FRONTPAGE | + | Tour is enabled | 1 | + | Show with backdrop | 1 | + # 2 = tour::SHOW_TOUR_ON_EACH_PAGE_VISIT + | Show tour | 2 | + And I add steps to the "First tour" tour: + | targettype | Title | id_content | Content type | + | Display in middle of page | Welcome | Welcome tour. | Manual | + + @javascript + Scenario: Ending the tour should not mark it as complete + # Changing the window viewport to mobile so we will have the footer section. + Given I am on site homepage + And I should see "Welcome" + And I press "Got it" + And I should not see "Welcome" + When I am on site homepage + Then I should see "Welcome" diff --git a/admin/tool/usertours/tests/cache_test.php b/admin/tool/usertours/tests/cache_test.php index 27f96008d12..54cadfaf578 100644 --- a/admin/tool/usertours/tests/cache_test.php +++ b/admin/tool/usertours/tests/cache_test.php @@ -27,6 +27,7 @@ require_once(__DIR__ . '/helper_trait.php'); * @package tool_usertours * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \tool_usertours\cache */ class cache_test extends \advanced_testcase { // There are shared helpers for these tests in the helper trait. @@ -35,7 +36,7 @@ class cache_test extends \advanced_testcase { /** * Test that get_enabled_tourdata does not return disabled tours. */ - public function test_get_enabled_tourdata_disabled() { + public function test_get_enabled_tourdata_disabled(): void { $this->resetAfterTest(); $tour = $this->helper_create_tour((object)['enabled' => false]); @@ -48,7 +49,7 @@ class cache_test extends \advanced_testcase { /** * Test that get_enabled_tourdata does not return an enabled but empty tour. */ - public function test_get_enabled_tourdata_enabled_no_steps() { + public function test_get_enabled_tourdata_enabled_no_steps(): void { $this->resetAfterTest(); $this->helper_create_tour(); @@ -60,7 +61,7 @@ class cache_test extends \advanced_testcase { /** * Test that get_enabled_tourdata returns a tour with steps. */ - public function test_get_enabled_tourdata_enabled() { + public function test_get_enabled_tourdata_enabled(): void { $this->resetAfterTest(); // Create two tours. Only the second has steps. @@ -79,7 +80,7 @@ class cache_test extends \advanced_testcase { /** * Test that get_enabled_tourdata returns tours in the correct sortorder */ - public function test_get_enabled_tourdata_enabled_sortorder() { + public function test_get_enabled_tourdata_enabled_sortorder(): void { $this->resetAfterTest(); $tour1 = $this->helper_create_tour(); @@ -100,7 +101,7 @@ class cache_test extends \advanced_testcase { /** * Test that caching prevents additional DB reads. */ - public function test_get_enabled_tourdata_single_fetch() { + public function test_get_enabled_tourdata_single_fetch(): void { global $DB; $this->resetAfterTest(); @@ -118,7 +119,6 @@ class cache_test extends \advanced_testcase { // No subsequent reads for any further calls. $matches = \tool_usertours\cache::get_enabled_tourdata(); $this->assertEquals(1, $DB->perf_get_reads() - $startreads); - } /** @@ -126,31 +126,31 @@ class cache_test extends \advanced_testcase { * * @return array */ - public function get_matching_tourdata_provider() { + public static function get_matching_tourdata_provider(): array { $tourconfigs = [ (object) [ 'name' => 'my_exact_1', - 'pathmatch' => '/my/view.php' + 'pathmatch' => '/my/view.php', ], (object) [ 'name' => 'my_failed_regex', - 'pathmatch' => '/my/*.php' + 'pathmatch' => '/my/*.php', ], (object) [ 'name' => 'my_glob_1', - 'pathmatch' => '/my/%' + 'pathmatch' => '/my/%', ], (object) [ 'name' => 'my_glob_2', - 'pathmatch' => '/my/%' + 'pathmatch' => '/my/%', ], (object) [ 'name' => 'frontpage_only', - 'pathmatch' => 'FRONTPAGE' + 'pathmatch' => 'FRONTPAGE', ], (object) [ 'name' => 'frontpage_match', - 'pathmatch' => '/?%' + 'pathmatch' => '/?%', ], ]; @@ -186,7 +186,7 @@ class cache_test extends \advanced_testcase { * @param string $targetmatch The match to be tested * @param array $expected An array containing the ordered names of the expected tours */ - public function test_get_matching_tourdata($tourconfigs, $targetmatch, $expected) { + public function test_get_matching_tourdata($tourconfigs, $targetmatch, $expected): void { $this->resetAfterTest(); foreach ($tourconfigs as $tourconfig) { $tour = $this->helper_create_tour($tourconfig); @@ -205,7 +205,7 @@ class cache_test extends \advanced_testcase { /** * Test that notify_tour_change clears the cache. */ - public function test_notify_tour_change() { + public function test_notify_tour_change(): void { global $DB; $this->resetAfterTest(); @@ -236,7 +236,7 @@ class cache_test extends \advanced_testcase { /** * Test that get_stepdata returns an empty array when no steps were found. */ - public function test_get_stepdata_no_steps() { + public function test_get_stepdata_no_steps(): void { $this->resetAfterTest(); $tour = $this->helper_create_tour((object)['enabled' => false]); @@ -249,7 +249,7 @@ class cache_test extends \advanced_testcase { /** * Test that get_stepdata returns an empty array when no steps were found. */ - public function test_get_stepdata_correct_tour() { + public function test_get_stepdata_correct_tour(): void { $this->resetAfterTest(); $tour1 = $this->helper_create_tour((object)['enabled' => false]); @@ -274,7 +274,7 @@ class cache_test extends \advanced_testcase { * This is very difficult to determine because the act of changing the * order will likely change the DB natural sorting. */ - public function test_get_stepdata_ordered_steps() { + public function test_get_stepdata_ordered_steps(): void { $this->resetAfterTest(); $tour = $this->helper_create_tour((object)['enabled' => false]); @@ -290,7 +290,7 @@ class cache_test extends \advanced_testcase { $this->assertCount(4, $data); // Re-order the steps. - usort($steps, function($a, $b) { + usort($steps, function ($a, $b) { return ($a->get_sortorder() < $b->get_sortorder()) ? -1 : 1; }); @@ -303,7 +303,7 @@ class cache_test extends \advanced_testcase { /** * Test that caching prevents additional DB reads. */ - public function test_get_stepdata_single_fetch() { + public function test_get_stepdata_single_fetch(): void { global $DB; $this->resetAfterTest(); @@ -324,7 +324,7 @@ class cache_test extends \advanced_testcase { /** * Test that notify_step_change clears the cache. */ - public function test_notify_step_change() { + public function test_notify_step_change(): void { global $DB; $this->resetAfterTest(); diff --git a/admin/tool/usertours/tests/helper_test.php b/admin/tool/usertours/tests/helper_test.php index f6c574b3077..3a2f1cdad26 100644 --- a/admin/tool/usertours/tests/helper_test.php +++ b/admin/tool/usertours/tests/helper_test.php @@ -14,35 +14,25 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tests for helper. - * - * @package tool_usertours - * @copyright 2022 Huong Nguyen - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_usertours; use advanced_testcase; -defined('MOODLE_INTERNAL') || die(); - /** * Tests for helper. * * @package tool_usertours * @copyright 2022 Huong Nguyen * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \tool_usertours\helper */ class helper_test extends advanced_testcase { - /** * Data Provider for get_string_from_input. * * @return array */ - public function get_string_from_input_provider(): array { + public static function get_string_from_input_provider(): array { return [ 'Text' => [ 'example', @@ -78,7 +68,7 @@ class helper_test extends advanced_testcase { * @param string $string The string to test * @param string $expected The expected result */ - public function test_get_string_from_input($string, $expected) { + public function test_get_string_from_input($string, $expected): void { $this->assertEquals($expected, helper::get_string_from_input($string)); } } diff --git a/admin/tool/usertours/tests/helper_trait.php b/admin/tool/usertours/tests/helper_trait.php index c3638a1d41b..988ace5abcd 100644 --- a/admin/tool/usertours/tests/helper_trait.php +++ b/admin/tool/usertours/tests/helper_trait.php @@ -14,16 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Helpers for unit tests. - * - * @package tool_usertours - * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - /** * Helpers for unit tests. * @@ -47,7 +37,7 @@ trait tool_usertours_helper_trait { 'name' => '', 'description' => '', 'configdata' => '', - 'displaystepnumbers' => true + 'displaystepnumbers' => true, ]; if ($tourconfig === null) { diff --git a/admin/tool/usertours/tests/manager_test.php b/admin/tool/usertours/tests/manager_test.php index 82b52db87f0..924ba268e85 100644 --- a/admin/tool/usertours/tests/manager_test.php +++ b/admin/tool/usertours/tests/manager_test.php @@ -28,6 +28,7 @@ require_once(__DIR__ . '/helper_trait.php'); * @package tool_usertours * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \tool_usertours\manager */ class manager_test extends \advanced_testcase { // There are shared helpers for these tests in the helper trait. @@ -74,28 +75,28 @@ class manager_test extends \advanced_testcase { * * @return array */ - public function sesskey_required_provider() { + public static function sesskey_required_provider(): array { $tourid = rand(1, 100); $stepid = rand(1, 100); return [ - 'Tour removal' => [ - 'delete_tour', - [$tourid], - ], - 'Step removal' => [ - 'delete_step', - [$stepid], - ], - 'Tour visibility' => [ - 'show_hide_tour', - [$tourid, true], - ], - 'Move step' => [ - 'move_step', - [$stepid], - ], - ]; + 'Tour removal' => [ + 'delete_tour', + [$tourid], + ], + 'Step removal' => [ + 'delete_step', + [$stepid], + ], + 'Tour visibility' => [ + 'show_hide_tour', + [$tourid, true], + ], + 'Move step' => [ + 'move_step', + [$stepid], + ], + ]; } /** @@ -105,7 +106,7 @@ class manager_test extends \advanced_testcase { * @param string $function The function to test * @param array $arguments The arguments to pass with it */ - public function test_sesskey_required($function, $arguments) { + public function test_sesskey_required($function, $arguments): void { $manager = new \tool_usertours\manager(); $rc = new \ReflectionClass('\tool_usertours\manager'); @@ -120,7 +121,7 @@ class manager_test extends \advanced_testcase { * * @return array */ - public function move_tour_provider() { + public static function move_tour_provider(): array { $alltours = [ ['name' => 'Tour 1'], ['name' => 'Tour 2'], @@ -166,7 +167,7 @@ class manager_test extends \advanced_testcase { * @param int $expectedsortorder * @return void */ - public function test_move_tour($alltours, $movetourname, $direction, $expectedsortorder) { + public function test_move_tour($alltours, $movetourname, $direction, $expectedsortorder): void { global $DB; $this->resetAfterTest(); @@ -196,114 +197,115 @@ class manager_test extends \advanced_testcase { * * @return array */ - public function get_matching_tours_provider() { + public static function get_matching_tours_provider(): array { global $CFG; $alltours = [ [ - 'pathmatch' => '/my/%', - 'enabled' => false, - 'name' => 'Failure', - 'description' => '', - 'configdata' => '', - ], + 'pathmatch' => '/my/%', + 'enabled' => false, + 'name' => 'Failure', + 'description' => '', + 'configdata' => '', + ], [ - 'pathmatch' => '/my/%', - 'enabled' => true, - 'name' => 'My tour enabled', - 'description' => '', - 'configdata' => '', - ], + 'pathmatch' => '/my/%', + 'enabled' => true, + 'name' => 'My tour enabled', + 'description' => '', + 'configdata' => '', + ], [ - 'pathmatch' => '/my/%', - 'enabled' => true, - 'name' => 'My tour enabled 2', - 'description' => '', - 'configdata' => '', - ], + 'pathmatch' => '/my/%', + 'enabled' => true, + 'name' => 'My tour enabled 2', + 'description' => '', + 'configdata' => '', + ], [ - 'pathmatch' => '/my/%', - 'enabled' => false, - 'name' => 'Failure', - 'description' => '', - 'configdata' => '', - ], + 'pathmatch' => '/my/%', + 'enabled' => false, + 'name' => 'Failure', + 'description' => '', + 'configdata' => '', + ], [ - 'pathmatch' => '/course/?id=%foo=bar', - 'enabled' => false, - 'name' => 'Failure', - 'description' => '', - 'configdata' => '', - ], + 'pathmatch' => '/course/?id=%foo=bar', + 'enabled' => false, + 'name' => 'Failure', + 'description' => '', + 'configdata' => '', + ], [ - 'pathmatch' => '/course/?id=%foo=bar', - 'enabled' => true, - 'name' => 'course tour with additional params enabled', - 'description' => '', - 'configdata' => '', - ], + 'pathmatch' => '/course/?id=%foo=bar', + 'enabled' => true, + 'name' => 'course tour with additional params enabled', + 'description' => '', + 'configdata' => '', + ], [ - 'pathmatch' => '/course/?id=%foo=bar', - 'enabled' => false, - 'name' => 'Failure', - 'description' => '', - 'configdata' => '', - ], + 'pathmatch' => '/course/?id=%foo=bar', + 'enabled' => false, + 'name' => 'Failure', + 'description' => '', + 'configdata' => '', + ], [ - 'pathmatch' => '/course/?id=%', - 'enabled' => false, - 'name' => 'Failure', - 'description' => '', - 'configdata' => '', - ], + 'pathmatch' => '/course/?id=%', + 'enabled' => false, + 'name' => 'Failure', + 'description' => '', + 'configdata' => '', + ], [ - 'pathmatch' => '/course/?id=%', - 'enabled' => true, - 'name' => 'course tour enabled', - 'description' => '', - 'configdata' => '', - ], + 'pathmatch' => '/course/?id=%', + 'enabled' => true, + 'name' => 'course tour enabled', + 'description' => '', + 'configdata' => '', + ], [ - 'pathmatch' => '/course/?id=%', - 'enabled' => false, - 'name' => 'Failure', - 'description' => '', - 'configdata' => '', - ], + 'pathmatch' => '/course/?id=%', + 'enabled' => false, + 'name' => 'Failure', + 'description' => '', + 'configdata' => '', + ], ]; - return [ - 'No matches found' => [ - $alltours, - $CFG->wwwroot . '/some/invalid/value', - [], - ], - 'Never return a disabled tour' => [ - $alltours, - $CFG->wwwroot . '/my/index.php', - ['My tour enabled', 'My tour enabled 2'], - ], - 'My not course' => [ - $alltours, - $CFG->wwwroot . '/my/index.php', - ['My tour enabled', 'My tour enabled 2'], - ], - 'My with params' => [ - $alltours, - $CFG->wwwroot . '/my/index.php?id=42', - ['My tour enabled', 'My tour enabled 2'], - ], - 'Course with params' => [ - $alltours, - $CFG->wwwroot . '/course/?id=42', - ['course tour enabled'], - ], - 'Course with params and trailing content' => [ - $alltours, - $CFG->wwwroot . '/course/?id=42&foo=bar', - ['course tour with additional params enabled', 'course tour enabled'], - ], - ]; + return + [ + 'No matches found' => [ + $alltours, + $CFG->wwwroot . '/some/invalid/value', + [], + ], + 'Never return a disabled tour' => [ + $alltours, + $CFG->wwwroot . '/my/index.php', + ['My tour enabled', 'My tour enabled 2'], + ], + 'My not course' => [ + $alltours, + $CFG->wwwroot . '/my/index.php', + ['My tour enabled', 'My tour enabled 2'], + ], + 'My with params' => [ + $alltours, + $CFG->wwwroot . '/my/index.php?id=42', + ['My tour enabled', 'My tour enabled 2'], + ], + 'Course with params' => [ + $alltours, + $CFG->wwwroot . '/course/?id=42', + ['course tour enabled'], + ], + 'Course with params and trailing content' => [ + $alltours, + $CFG->wwwroot . '/course/?id=42&foo=bar', + ['course tour with additional params enabled', 'course tour enabled'], + ], + ]; } /** @@ -314,7 +316,7 @@ class manager_test extends \advanced_testcase { * @param string $url The URL to test. * @param array $expected List of names of the expected matching tours. */ - public function test_get_matching_tours(array $alltours, string $url, array $expected) { + public function test_get_matching_tours(array $alltours, string $url, array $expected): void { $this->resetAfterTest(); $this->setGuestUser(); @@ -334,7 +336,7 @@ class manager_test extends \advanced_testcase { /** * Test that no matching tours are returned if there is pending site policy agreement. */ - public function test_get_matching_tours_for_user_without_site_policy_agreed() { + public function test_get_matching_tours_for_user_without_site_policy_agreed(): void { global $CFG; $this->resetAfterTest(); diff --git a/admin/tool/usertours/tests/privacy/provider_test.php b/admin/tool/usertours/tests/privacy/provider_test.php index 907feb48352..e63ace554d3 100644 --- a/admin/tool/usertours/tests/privacy/provider_test.php +++ b/admin/tool/usertours/tests/privacy/provider_test.php @@ -14,18 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the tool_usertours implementation of the privacy API. - * - * @package tool_usertours - * @category test - * @copyright 2018 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ namespace tool_usertours\privacy; -defined('MOODLE_INTERNAL') || die(); - use core_privacy\local\metadata\collection; use core_privacy\local\request\writer; use tool_usertours\tour; @@ -34,11 +24,13 @@ use tool_usertours\privacy\provider; /** * Unit tests for the tool_usertours implementation of the privacy API. * + * @package tool_usertours + * @category test * @copyright 2018 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \tool_usertours\privacy\provider */ class provider_test extends \core_privacy\tests\provider_testcase { - /** * Helper method for creating a tour * @@ -56,7 +48,7 @@ class provider_test extends \core_privacy\tests\provider_testcase { /** * Ensure that get_metadata exports valid content. */ - public function test_get_metadata() { + public function test_get_metadata(): void { $items = new collection('tool_usertours'); $result = provider::get_metadata($items); $this->assertSame($items, $result); @@ -66,7 +58,7 @@ class provider_test extends \core_privacy\tests\provider_testcase { /** * Ensure that export_user_preferences returns no data if the user has completed no tours. */ - public function test_export_user_preferences_no_pref() { + public function test_export_user_preferences_no_pref(): void { $user = \core_user::get_user_by_username('admin'); provider::export_user_preferences($user->id); @@ -78,7 +70,7 @@ class provider_test extends \core_privacy\tests\provider_testcase { /** * Ensure that export_user_preferences returns request completion data. */ - public function test_export_user_preferences_completed() { + public function test_export_user_preferences_completed(): void { global $DB; $this->resetAfterTest(); @@ -101,7 +93,7 @@ class provider_test extends \core_privacy\tests\provider_testcase { /** * Ensure that export_user_preferences returns request completion data. */ - public function test_export_user_preferences_requested() { + public function test_export_user_preferences_requested(): void { global $DB; $this->resetAfterTest(); @@ -149,14 +141,16 @@ class provider_test extends \core_privacy\tests\provider_testcase { $this->assertCount(1, $prefs); // We should have received back the "completed tour" preference of the test user. - $this->assertStringStartsWith('You last marked the "' . $tour->get_name() . '" user tour as completed on', - reset($prefs)->description); + $this->assertStringStartsWith( + 'You last marked the "' . $tour->get_name() . '" user tour as completed on', + reset($prefs)->description + ); } /** * Ensure that export_user_preferences excludes deleted tours. */ - public function test_export_user_preferences_deleted_tour() { + public function test_export_user_preferences_deleted_tour(): void { global $DB; $this->resetAfterTest(); diff --git a/admin/tool/usertours/tests/role_filter_test.php b/admin/tool/usertours/tests/role_filter_test.php index 20ee1be9629..ceff72fb39b 100644 --- a/admin/tool/usertours/tests/role_filter_test.php +++ b/admin/tool/usertours/tests/role_filter_test.php @@ -22,9 +22,9 @@ namespace tool_usertours; * @package tool_usertours * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \tool_usertours\local\filter\role */ class role_filter_test extends \advanced_testcase { - /** * @var $course Test course */ @@ -72,7 +72,7 @@ class role_filter_test extends \advanced_testcase { /** * Test the filter_matches function when any is set. */ - public function test_filter_matches_any() { + public function test_filter_matches_any(): void { $context = \context_course::instance($this->course->id); // Note: No need to persist this tour. @@ -93,7 +93,7 @@ class role_filter_test extends \advanced_testcase { /** * Test the filter_matches function when one role is set. */ - public function test_filter_matches_single_role() { + public function test_filter_matches_single_role(): void { $context = \context_course::instance($this->course->id); $roles = [ @@ -122,7 +122,7 @@ class role_filter_test extends \advanced_testcase { /** * Test the filter_matches function when multiple roles are set. */ - public function test_filter_matches_multiple_role() { + public function test_filter_matches_multiple_role(): void { $context = \context_course::instance($this->course->id); $roles = [ @@ -152,7 +152,7 @@ class role_filter_test extends \advanced_testcase { /** * Test the filter_matches function when one user has multiple roles. */ - public function test_filter_matches_multiple_role_one_user() { + public function test_filter_matches_multiple_role_one_user(): void { $context = \context_course::instance($this->course->id); $roles = [ @@ -184,7 +184,7 @@ class role_filter_test extends \advanced_testcase { /** * Test the filter_matches function when it is targetted at an admin. */ - public function test_filter_matches_multiple_role_only_admin() { + public function test_filter_matches_multiple_role_only_admin(): void { $context = \context_course::instance($this->course->id); $roles = [ @@ -212,7 +212,7 @@ class role_filter_test extends \advanced_testcase { /** * Test the filter_matches function when multiple roles are set, including an admin user. */ - public function test_filter_matches_multiple_role_including_admin() { + public function test_filter_matches_multiple_role_including_admin(): void { $context = \context_course::instance($this->course->id); $roles = [ @@ -243,7 +243,7 @@ class role_filter_test extends \advanced_testcase { /** * Test the filter_matches function when an admin user has multiple roles. */ - public function test_filter_matches_multiple_role_admin_user() { + public function test_filter_matches_multiple_role_admin_user(): void { global $USER; $context = \context_course::instance($this->course->id); @@ -266,7 +266,7 @@ class role_filter_test extends \advanced_testcase { /** * Test that the get_filter_options function does not include the guest roles. */ - public function test_get_filter_options_no_guest_roles() { + public function test_get_filter_options_no_guest_roles(): void { create_role('Test Role', 'testrole', 'This is a test role', 'guest'); $allroles = role_get_names(null, ROLENAME_ALIAS); diff --git a/admin/tool/usertours/tests/step_test.php b/admin/tool/usertours/tests/step_test.php index f6286f05471..8ba2cafa2fa 100644 --- a/admin/tool/usertours/tests/step_test.php +++ b/admin/tool/usertours/tests/step_test.php @@ -27,9 +27,9 @@ require_once($CFG->libdir . '/formslib.php'); * @package tool_usertours * @copyright 2016 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \tool_usertours\step */ class step_test extends \advanced_testcase { - /** * @var moodle_database */ @@ -62,8 +62,7 @@ class step_test extends \advanced_testcase { global $DB; $DB = $this->getMockBuilder('moodle_database') - ->getMock() - ; + ->getMock(); return $DB; } @@ -73,60 +72,58 @@ class step_test extends \advanced_testcase { * * @return array */ - public function dirty_value_provider() { - return [ + public static function dirty_value_provider(): array { + return + [ 'tourid' => [ - 'tourid', - [1], - ], + 'tourid', + [1], + ], 'title' => [ - 'title', - ['Lorem'], - ], + 'title', + ['Lorem'], + ], 'content' => [ - 'content', - ['Lorem'], - ], + 'content', + ['Lorem'], + ], 'targettype' => [ - 'targettype', - ['Lorem'], - ], + 'targettype', + ['Lorem'], + ], 'targetvalue' => [ - 'targetvalue', - ['Lorem'], - ], + 'targetvalue', + ['Lorem'], + ], 'sortorder' => [ - 'sortorder', - [1], - ], + 'sortorder', + [1], + ], 'config' => [ - 'config', - ['key', 'value'], - ], + 'config', + ['key', 'value'], + ], ]; } /** * Test the fetch function. */ - public function test_fetch() { + public function test_fetch(): void { $step = $this->getMockBuilder(\tool_usertours\step::class) ->onlyMethods(['reload_from_record']) - ->getMock() - ; + ->getMock(); $idretval = rand(1, 100); $DB = $this->mock_database(); $DB->method('get_record') - ->willReturn($idretval) - ; + ->willReturn($idretval); $retval = rand(1, 100); $step->expects($this->once()) ->method('reload_from_record') ->with($this->equalTo($idretval)) - ->wilLReturn($retval) - ; + ->wilLReturn($retval); $rc = new \ReflectionClass(\tool_usertours\step::class); $rcm = $rc->getMethod('fetch'); @@ -142,7 +139,7 @@ class step_test extends \advanced_testcase { * @param string $name The key to update * @param string $value The value to set */ - public function test_dirty_values($name, $value) { + public function test_dirty_values($name, $value): void { $step = new \tool_usertours\step(); $method = 'set_' . $name; call_user_func_array([$step, $method], $value); @@ -158,12 +155,12 @@ class step_test extends \advanced_testcase { * * @return array */ - public function step_sortorder_provider() { + public static function step_sortorder_provider(): array { return [ - [0, 5, true, false], - [1, 5, false, false], - [4, 5, false, true], - ]; + [0, 5, true, false], + [1, 5, false, false], + [4, 5, false, true], + ]; } /** @@ -175,15 +172,14 @@ class step_test extends \advanced_testcase { * @param bool $isfirst Whether this is the first step * @param bool $islast Whether this is the last step */ - public function test_is_first_step($sortorder, $count, $isfirst, $islast) { + public function test_is_first_step($sortorder, $count, $isfirst, $islast): void { $step = $this->getMockBuilder(\tool_usertours\step::class) ->onlyMethods(['get_sortorder']) ->getMock(); $step->expects($this->once()) ->method('get_sortorder') - ->willReturn($sortorder) - ; + ->willReturn($sortorder); $this->assertEquals($isfirst, $step->is_first_step()); } @@ -197,7 +193,7 @@ class step_test extends \advanced_testcase { * @param bool $isfirst Whether this is the first step * @param bool $islast Whether this is the last step */ - public function test_is_last_step($sortorder, $count, $isfirst, $islast) { + public function test_is_last_step($sortorder, $count, $isfirst, $islast): void { $step = $this->getMockBuilder(\tool_usertours\step::class) ->onlyMethods(['get_sortorder', 'get_tour']) ->getMock(); @@ -208,18 +204,15 @@ class step_test extends \advanced_testcase { $step->expects($this->once()) ->method('get_tour') - ->willReturn($tour) - ; + ->willReturn($tour); $tour->expects($this->once()) ->method('count_steps') - ->willReturn($count) - ; + ->willReturn($count); $step->expects($this->once()) ->method('get_sortorder') - ->willReturn($sortorder) - ; + ->willReturn($sortorder); $this->assertEquals($islast, $step->is_last_step()); } @@ -227,19 +220,19 @@ class step_test extends \advanced_testcase { /** * Test get_config with no keys provided. */ - public function test_get_config_no_keys() { + public function test_get_config_no_keys(): void { $step = new \tool_usertours\step(); $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('config'); $allvalues = (object) [ - 'some' => 'value', - 'another' => 42, - 'key' => [ - 'somethingelse', - ], - ]; + 'some' => 'value', + 'another' => 42, + 'key' => [ + 'somethingelse', + ], + ]; $rcp->setValue($step, $allvalues); @@ -251,92 +244,92 @@ class step_test extends \advanced_testcase { * * @return array */ - public function get_config_provider() { + public static function get_config_provider(): array { $allvalues = (object) [ - 'some' => 'value', - 'another' => 42, - 'key' => [ - 'somethingelse', - ], - ]; + 'some' => 'value', + 'another' => 42, + 'key' => [ + 'somethingelse', + ], + ]; $tourconfig = rand(1, 100); $forcedconfig = rand(1, 100); return [ - 'No initial config' => [ - null, - null, - null, - $tourconfig, - false, - $forcedconfig, - (object) [], - ], - 'All values' => [ - $allvalues, - null, - null, - $tourconfig, - false, - $forcedconfig, - $allvalues, - ], - 'Valid string value' => [ - $allvalues, - 'some', - null, - $tourconfig, - false, - $forcedconfig, - 'value', - ], - 'Valid array value' => [ - $allvalues, - 'key', - null, - $tourconfig, - false, - $forcedconfig, - ['somethingelse'], - ], - 'Invalid value' => [ - $allvalues, - 'notavalue', - null, - $tourconfig, - false, - $forcedconfig, - $tourconfig, - ], - 'Configuration value' => [ - $allvalues, - 'placement', - null, - $tourconfig, - false, - $forcedconfig, - $tourconfig, - ], - 'Invalid value with default' => [ - $allvalues, - 'notavalue', - 'somedefault', - $tourconfig, - false, - $forcedconfig, - 'somedefault', - ], - 'Value forced at target' => [ - $allvalues, - 'somevalue', - 'somedefault', - $tourconfig, - true, - $forcedconfig, - $forcedconfig, - ], - ]; + 'No initial config' => [ + null, + null, + null, + $tourconfig, + false, + $forcedconfig, + (object) [], + ], + 'All values' => [ + $allvalues, + null, + null, + $tourconfig, + false, + $forcedconfig, + $allvalues, + ], + 'Valid string value' => [ + $allvalues, + 'some', + null, + $tourconfig, + false, + $forcedconfig, + 'value', + ], + 'Valid array value' => [ + $allvalues, + 'key', + null, + $tourconfig, + false, + $forcedconfig, + ['somethingelse'], + ], + 'Invalid value' => [ + $allvalues, + 'notavalue', + null, + $tourconfig, + false, + $forcedconfig, + $tourconfig, + ], + 'Configuration value' => [ + $allvalues, + 'placement', + null, + $tourconfig, + false, + $forcedconfig, + $tourconfig, + ], + 'Invalid value with default' => [ + $allvalues, + 'notavalue', + 'somedefault', + $tourconfig, + false, + $forcedconfig, + 'somedefault', + ], + 'Value forced at target' => [ + $allvalues, + 'somevalue', + 'somedefault', + $tourconfig, + true, + $forcedconfig, + $forcedconfig, + ], + ]; } /** @@ -351,7 +344,7 @@ class step_test extends \advanced_testcase { * @param mixed $forcedvalue The example value * @param mixed $expected The expected value */ - public function test_get_config_valid_keys($values, $key, $default, $tourconfig, $isforced, $forcedvalue, $expected) { + public function test_get_config_valid_keys($values, $key, $default, $tourconfig, $isforced, $forcedvalue, $expected): void { $step = $this->getMockBuilder(\tool_usertours\step::class) ->onlyMethods(['get_target', 'get_targettype', 'get_tour']) ->getMock(); @@ -362,43 +355,35 @@ class step_test extends \advanced_testcase { $target = $this->getMockBuilder(\tool_usertours\local\target\base::class) ->disableOriginalConstructor() - ->getMock() - ; + ->getMock(); $target->expects($this->any()) ->method('is_setting_forced') - ->willReturn($isforced) - ; + ->willReturn($isforced); $target->expects($this->any()) ->method('get_forced_setting_value') ->with($this->equalTo($key)) - ->willReturn($forcedvalue) - ; + ->willReturn($forcedvalue); $step->expects($this->any()) ->method('get_targettype') - ->willReturn('type') - ; + ->willReturn('type'); $step->expects($this->any()) ->method('get_target') - ->willReturn($target) - ; + ->willReturn($target); $tour = $this->getMockBuilder(\tool_usertours\tour::class) - ->getMock() - ; + ->getMock(); $tour->expects($this->any()) ->method('get_config') - ->willReturn($tourconfig) - ; + ->willReturn($tourconfig); $step->expects($this->any()) ->method('get_tour') - ->willReturn($tour) - ; + ->willReturn($tour); $this->assertEquals($expected, $step->get_config($key, $default)); } @@ -406,14 +391,14 @@ class step_test extends \advanced_testcase { /** * Data provider for set_config. */ - public function set_config_provider() { + public static function set_config_provider(): array { $allvalues = (object) [ - 'some' => 'value', - 'another' => 42, - 'key' => [ - 'somethingelse', - ], - ]; + 'some' => 'value', + 'another' => 42, + 'key' => [ + 'somethingelse', + ], + ]; $randvalue = rand(1, 100); @@ -422,27 +407,27 @@ class step_test extends \advanced_testcase { $newvalues = $allvalues; $newvalues->some = 'unset'; $provider['Unset an existing value'] = [ - $allvalues, - 'some', - null, - $newvalues, - ]; + $allvalues, + 'some', + null, + $newvalues, + ]; $newvalues = $allvalues; $newvalues->some = $randvalue; $provider['Set an existing value'] = [ - $allvalues, - 'some', - $randvalue, - $newvalues, - ]; + $allvalues, + 'some', + $randvalue, + $newvalues, + ]; $provider['Set a new value'] = [ - $allvalues, - 'newkey', - $randvalue, - (object) array_merge((array) $allvalues, ['newkey' => $randvalue]), - ]; + $allvalues, + 'newkey', + $randvalue, + (object) array_merge((array) $allvalues, ['newkey' => $randvalue]), + ]; return $provider; } @@ -456,7 +441,7 @@ class step_test extends \advanced_testcase { * @param mixed $newvalue The new value to set * @param mixed $expected The expected value */ - public function test_set_config($initialvalues, $key, $newvalue, $expected) { + public function test_set_config($initialvalues, $key, $newvalue, $expected): void { $step = new \tool_usertours\step(); $rc = new \ReflectionClass(\tool_usertours\step::class); @@ -465,13 +450,11 @@ class step_test extends \advanced_testcase { $target = $this->getMockBuilder(\tool_usertours\local\target\base::class) ->disableOriginalConstructor() - ->getMock() - ; + ->getMock(); $target->expects($this->any()) ->method('is_setting_forced') - ->willReturn(false) - ; + ->willReturn(false); $step->set_config($key, $newvalue); @@ -481,22 +464,19 @@ class step_test extends \advanced_testcase { /** * Ensure that non-dirty tours are not persisted. */ - public function test_persist_non_dirty() { + public function test_persist_non_dirty(): void { $step = $this->getMockBuilder(\tool_usertours\step::class) ->onlyMethods([ - 'to_record', - 'reload', - ]) - ->getMock() - ; + 'to_record', + 'reload', + ]) + ->getMock(); $step->expects($this->never()) - ->method('to_record') - ; + ->method('to_record'); $step->expects($this->never()) - ->method('reload') - ; + ->method('reload'); $this->assertSame($step, $step->persist()); } @@ -504,36 +484,31 @@ class step_test extends \advanced_testcase { /** * Ensure that new dirty steps are persisted. */ - public function test_persist_dirty_new() { + public function test_persist_dirty_new(): void { // Mock the database. $DB = $this->mock_database(); $DB->expects($this->once()) ->method('insert_record') - ->willReturn(42) - ; + ->willReturn(42); // Mock the tour. $step = $this->getMockBuilder(\tool_usertours\step::class) ->onlyMethods([ - 'to_record', - 'calculate_sortorder', - 'reload', - ]) - ->getMock() - ; + 'to_record', + 'calculate_sortorder', + 'reload', + ]) + ->getMock(); $step->expects($this->once()) ->method('to_record') ->willReturn((object)['id' => 42]); - ; $step->expects($this->once()) - ->method('calculate_sortorder') - ; + ->method('calculate_sortorder'); $step->expects($this->once()) - ->method('reload') - ; + ->method('reload'); $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('dirty'); @@ -549,38 +524,33 @@ class step_test extends \advanced_testcase { /** * Ensure that new non-dirty, forced steps are persisted. */ - public function test_persist_force_new() { + public function test_persist_force_new(): void { global $DB; // Mock the database. $DB = $this->mock_database(); $DB->expects($this->once()) ->method('insert_record') - ->willReturn(42) - ; + ->willReturn(42); // Mock the tour. $step = $this->getMockBuilder(\tool_usertours\step::class) ->onlyMethods([ - 'to_record', - 'calculate_sortorder', - 'reload', - ]) - ->getMock() - ; + 'to_record', + 'calculate_sortorder', + 'reload', + ]) + ->getMock(); $step->expects($this->once()) ->method('to_record') ->willReturn((object)['id' => 42]); - ; $step->expects($this->once()) - ->method('calculate_sortorder') - ; + ->method('calculate_sortorder'); $step->expects($this->once()) - ->method('reload') - ; + ->method('reload'); $tour = $this->createMock(\tool_usertours\tour::class); $rc = new \ReflectionClass(\tool_usertours\step::class); @@ -593,35 +563,30 @@ class step_test extends \advanced_testcase { /** * Ensure that existing dirty steps are persisted. */ - public function test_persist_dirty_existing() { + public function test_persist_dirty_existing(): void { // Mock the database. $DB = $this->mock_database(); $DB->expects($this->once()) - ->method('update_record') - ; + ->method('update_record'); // Mock the tour. $step = $this->getMockBuilder(\tool_usertours\step::class) ->onlyMethods([ - 'to_record', - 'calculate_sortorder', - 'reload', - ]) - ->getMock() - ; + 'to_record', + 'calculate_sortorder', + 'reload', + ]) + ->getMock(); $step->expects($this->once()) ->method('to_record') ->willReturn((object)['id' => 42]); - ; $step->expects($this->never()) - ->method('calculate_sortorder') - ; + ->method('calculate_sortorder'); $step->expects($this->once()) - ->method('reload') - ; + ->method('reload'); $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('id'); @@ -640,37 +605,32 @@ class step_test extends \advanced_testcase { /** * Ensure that existing non-dirty, forced steps are persisted. */ - public function test_persist_force_existing() { + public function test_persist_force_existing(): void { global $DB; // Mock the database. $DB = $this->mock_database(); $DB->expects($this->once()) - ->method('update_record') - ; + ->method('update_record'); // Mock the tour. $step = $this->getMockBuilder(\tool_usertours\step::class) ->onlyMethods([ - 'to_record', - 'calculate_sortorder', - 'reload', - ]) - ->getMock() - ; + 'to_record', + 'calculate_sortorder', + 'reload', + ]) + ->getMock(); $step->expects($this->once()) ->method('to_record') - ->willReturn((object)['id' => 42]); - ; + ->willReturn((object) ['id' => 42]); $step->expects($this->never()) - ->method('calculate_sortorder') - ; + ->method('calculate_sortorder'); $step->expects($this->once()) - ->method('reload') - ; + ->method('reload'); $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('id'); @@ -686,17 +646,15 @@ class step_test extends \advanced_testcase { /** * Check that a tour which has never been persisted is removed correctly. */ - public function test_remove_non_persisted() { + public function test_remove_non_persisted(): void { $step = $this->getMockBuilder(\tool_usertours\step::class) ->onlyMethods([]) - ->getMock() - ; + ->getMock(); // Mock the database. $DB = $this->mock_database(); $DB->expects($this->never()) - ->method('delete_records') - ; + ->method('delete_records'); $this->assertNull($step->remove()); } @@ -704,38 +662,33 @@ class step_test extends \advanced_testcase { /** * Check that a tour which has been persisted is removed correctly. */ - public function test_remove_persisted() { + public function test_remove_persisted(): void { $id = rand(1, 100); $tour = $this->getMockBuilder(\tool_usertours\tour::class) ->onlyMethods([ - 'reset_step_sortorder', - ]) - ->getMock() - ; + 'reset_step_sortorder', + ]) + ->getMock(); $tour->expects($this->once()) - ->method('reset_step_sortorder') - ; + ->method('reset_step_sortorder'); $step = $this->getMockBuilder(\tool_usertours\step::class) ->onlyMethods([ - 'get_tour', - ]) - ->getMock() - ; + 'get_tour', + ]) + ->getMock(); $step->expects($this->once()) ->method('get_tour') - ->willReturn($tour) - ; + ->willReturn($tour); // Mock the database. $DB = $this->mock_database(); $DB->expects($this->once()) ->method('delete_records') - ->with($this->equalTo('tool_usertours_steps'), $this->equalTo(['id' => $id])) - ; + ->with($this->equalTo('tool_usertours_steps'), $this->equalTo(['id' => $id])); $rc = new \ReflectionClass(\tool_usertours\step::class); $rcp = $rc->getProperty('id'); @@ -750,37 +703,37 @@ class step_test extends \advanced_testcase { * * @return array */ - public function getter_provider() { + public static function getter_provider(): array { return [ - 'id' => [ - 'id', - rand(1, 100), - ], - 'tourid' => [ - 'tourid', - rand(1, 100), - ], - 'title' => [ - 'title', - 'Lorem', - ], - 'content' => [ - 'content', - 'Lorem', - ], - 'targettype' => [ - 'targettype', - 'Lorem', - ], - 'targetvalue' => [ - 'targetvalue', - 'Lorem', - ], - 'sortorder' => [ - 'sortorder', - rand(1, 100), - ], - ]; + 'id' => [ + 'id', + rand(1, 100), + ], + 'tourid' => [ + 'tourid', + rand(1, 100), + ], + 'title' => [ + 'title', + 'Lorem', + ], + 'content' => [ + 'content', + 'Lorem', + ], + 'targettype' => [ + 'targettype', + 'Lorem', + ], + 'targetvalue' => [ + 'targetvalue', + 'Lorem', + ], + 'sortorder' => [ + 'sortorder', + rand(1, 100), + ], + ]; } /** @@ -790,7 +743,7 @@ class step_test extends \advanced_testcase { * @param string $key The key to test * @param mixed $value The expected value */ - public function test_getters($key, $value) { + public function test_getters($key, $value): void { $step = new \tool_usertours\step(); $rc = new \ReflectionClass(\tool_usertours\step::class); @@ -806,7 +759,7 @@ class step_test extends \advanced_testcase { /** * Ensure that the get_step_image_from_input function replace PIXICON placeholder with the correct images correctly. */ - public function test_get_step_image_from_input() { + public function test_get_step_image_from_input(): void { // Test step content with single image. $stepcontent = '@@PIXICON::tour/tour_mycourses::tool_usertours@@
Test'; $stepcontent = \tool_usertours\step::get_step_image_from_input($stepcontent); @@ -817,7 +770,8 @@ class step_test extends \advanced_testcase { $this->assertStringNotContainsString('PIXICON', $stepcontent); // Test step content with multiple images. - $stepcontent = '@@PIXICON::tour/tour_mycourses::tool_usertours@@
Test
@@PIXICON::tour/tour_myhomepage::tool_usertours@@'; + $stepcontent = + '@@PIXICON::tour/tour_mycourses::tool_usertours@@
Test
@@PIXICON::tour/tour_myhomepage::tool_usertours@@'; $stepcontent = \tool_usertours\step::get_step_image_from_input($stepcontent); // If the format is correct, PIXICON placeholder will be replaced with the img tag. $this->assertStringStartsWith(' * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \tool_usertours\local\filter\theme */ class theme_filter_test extends \advanced_testcase { - /** * Data Provider for filter_matches function. * * @return array */ - public function filter_matches_provider() { + public static function filter_matches_provider(): array { return [ 'No config set; Matches' => [ null, @@ -73,7 +73,7 @@ class theme_filter_test extends \advanced_testcase { * @param string $currenttheme The name of the current theme * @param boolean $expected Whether the tour is expected to match */ - public function test_filter_matches($filtervalues, $currenttheme, $expected) { + public function test_filter_matches($filtervalues, $currenttheme, $expected): void { global $PAGE; $filtername = \tool_usertours\local\filter\theme::class; diff --git a/admin/tool/usertours/tests/tour_test.php b/admin/tool/usertours/tests/tour_test.php index fa3685ac9fd..e32df99a1f8 100644 --- a/admin/tool/usertours/tests/tour_test.php +++ b/admin/tool/usertours/tests/tour_test.php @@ -16,25 +16,25 @@ namespace tool_usertours; -defined('MOODLE_INTERNAL') || die(); - -global $CFG; -require_once($CFG->libdir . '/formslib.php'); - /** * Tests for tour. * * @package tool_usertours * @copyright 2016 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \tool_usertours\tour */ class tour_test extends \advanced_testcase { - /** * @var moodle_database */ protected $db; + public static function setUpBeforeClass(): void { + global $CFG; + require_once($CFG->libdir . '/formslib.php'); + } + /** * Setup to store the DB reference. */ @@ -62,8 +62,7 @@ class tour_test extends \advanced_testcase { global $DB; $DB = $this->getMockBuilder(\moodle_database::class) - ->getMock() - ; + ->getMock(); return $DB; } @@ -73,33 +72,37 @@ class tour_test extends \advanced_testcase { * * @return array */ - public function dirty_value_provider() { + public static function dirty_value_provider(): array { return [ - 'name' => [ - 'name', - ['Lorem'], - ], - 'description' => [ - 'description', - ['Lorem'], - ], - 'pathmatch' => [ - 'pathmatch', - ['Lorem'], - ], - 'enabled' => [ - 'enabled', - ['Lorem'], - ], - 'sortorder' => [ - 'sortorder', - [1], - ], - 'config' => [ - 'config', - ['key', 'value'], - ], - ]; + 'name' => [ + 'name', + ['Lorem'], + ], + 'description' => [ + 'description', + ['Lorem'], + ], + 'pathmatch' => [ + 'pathmatch', + ['Lorem'], + ], + 'enabled' => [ + 'enabled', + ['Lorem'], + ], + 'sortorder' => [ + 'sortorder', + [1], + ], + 'config' => [ + 'config', + ['key', 'value'], + ], + 'showtourwhen' => [ + 'showtourwhen', + [0], + ], + ]; } /** @@ -109,7 +112,7 @@ class tour_test extends \advanced_testcase { * @param string $name The name of the key being tested * @param mixed $value The value being set */ - public function test_dirty_values($name, $value) { + public function test_dirty_values($name, $value): void { $tour = new \tool_usertours\tour(); $method = 'set_' . $name; call_user_func_array([$tour, $method], $value); @@ -125,37 +128,37 @@ class tour_test extends \advanced_testcase { * * @return array */ - public function getter_provider() { + public static function getter_provider(): array { return [ - 'id' => [ - 'id', - rand(1, 100), - ], - 'name' => [ - 'name', - 'Lorem', - ], - 'description' => [ - 'description', - 'Lorem', - ], - 'pathmatch' => [ - 'pathmatch', - 'Lorem', - ], - 'enabled' => [ - 'enabled', - 'Lorem', - ], - 'sortorder' => [ - 'sortorder', - rand(1, 100), - ], - 'config' => [ - 'config', - ['key', 'value'], - ], - ]; + 'id' => [ + 'id', + rand(1, 100), + ], + 'name' => [ + 'name', + 'Lorem', + ], + 'description' => [ + 'description', + 'Lorem', + ], + 'pathmatch' => [ + 'pathmatch', + 'Lorem', + ], + 'enabled' => [ + 'enabled', + 'Lorem', + ], + 'sortorder' => [ + 'sortorder', + rand(1, 100), + ], + 'config' => [ + 'config', + ['key', 'value'], + ], + ]; } /** @@ -165,7 +168,7 @@ class tour_test extends \advanced_testcase { * @param string $key The name of the key being tested * @param mixed $value The value being set */ - public function test_getters($key, $value) { + public function test_getters($key, $value): void { $tour = new \tool_usertours\tour(); $rc = new \ReflectionClass(tour::class); @@ -181,15 +184,13 @@ class tour_test extends \advanced_testcase { /** * Ensure that non-dirty tours are not persisted. */ - public function test_persist_non_dirty() { + public function test_persist_non_dirty(): void { $tour = $this->getMockBuilder(tour::class) ->onlyMethods(['to_record']) - ->getMock() - ; + ->getMock(); $tour->expects($this->never()) - ->method('to_record') - ; + ->method('to_record'); $this->assertSame($tour, $tour->persist()); } @@ -197,36 +198,31 @@ class tour_test extends \advanced_testcase { /** * Ensure that new dirty tours are persisted. */ - public function test_persist_dirty_new() { + public function test_persist_dirty_new(): void { // Mock the database. $DB = $this->mock_database(); $DB->expects($this->never()) - ->method('update_record') - ; + ->method('update_record'); $id = rand(1, 100); $DB->expects($this->once()) ->method('insert_record') - ->willReturn($id) - ; + ->willReturn($id); // Mock the tour. $tour = $this->getMockBuilder(tour::class) ->onlyMethods([ - 'to_record', - 'reload', - ]) - ->getMock() - ; + 'to_record', + 'reload', + ]) + ->getMock(); $tour->expects($this->once()) - ->method('to_record') - ; + ->method('to_record'); $tour->expects($this->once()) - ->method('reload') - ; + ->method('reload'); $rc = new \ReflectionClass(tour::class); @@ -242,38 +238,33 @@ class tour_test extends \advanced_testcase { /** * Ensure that non-dirty, forced tours are persisted. */ - public function test_persist_force_new() { + public function test_persist_force_new(): void { global $DB; // Mock the database. $DB = $this->mock_database(); $DB->expects($this->never()) - ->method('update_record') - ; + ->method('update_record'); $id = rand(1, 100); $DB->expects($this->once()) ->method('insert_record') - ->willReturn($id) - ; + ->willReturn($id); // Mock the tour. $tour = $this->getMockBuilder(tour::class) ->onlyMethods([ - 'to_record', - 'reload', - ]) - ->getMock() - ; + 'to_record', + 'reload', + ]) + ->getMock(); $tour->expects($this->once()) - ->method('to_record') - ; + ->method('to_record'); $tour->expects($this->once()) - ->method('reload') - ; + ->method('reload'); $this->assertSame($tour, $tour->persist(true)); @@ -285,34 +276,29 @@ class tour_test extends \advanced_testcase { /** * Ensure that dirty tours are persisted. */ - public function test_persist_dirty_existing() { + public function test_persist_dirty_existing(): void { // Mock the database. $DB = $this->mock_database(); $DB->expects($this->once()) ->method('update_record') - ->willReturn($this->returnSelf()) - ; + ->willReturn($this->returnSelf()); $DB->expects($this->never()) - ->method('insert_record') - ; + ->method('insert_record'); // Mock the tour. $tour = $this->getMockBuilder(tour::class) ->onlyMethods([ - 'to_record', - 'reload', - ]) - ->getMock() - ; + 'to_record', + 'reload', + ]) + ->getMock(); $tour->expects($this->once()) - ->method('to_record') - ; + ->method('to_record'); $tour->expects($this->once()) - ->method('reload') - ; + ->method('reload'); $rc = new \ReflectionClass(tour::class); @@ -328,7 +314,7 @@ class tour_test extends \advanced_testcase { /** * Ensure that non-dirty, forced tours are persisted. */ - public function test_persist_force() { + public function test_persist_force(): void { global $DB; // Mock the database. @@ -336,29 +322,24 @@ class tour_test extends \advanced_testcase { $DB->expects($this->once()) ->method('update_record') - ->willReturn($this->returnSelf()) - ; + ->willReturn($this->returnSelf()); $DB->expects($this->never()) - ->method('insert_record') - ; + ->method('insert_record'); // Mock the tour. $tour = $this->getMockBuilder(tour::class) ->onlyMethods([ - 'to_record', - 'reload', - ]) - ->getMock() - ; + 'to_record', + 'reload', + ]) + ->getMock(); $tour->expects($this->once()) - ->method('to_record') - ; + ->method('to_record'); $tour->expects($this->once()) - ->method('reload') - ; + ->method('reload'); $rc = new \ReflectionClass(tour::class); @@ -374,40 +355,40 @@ class tour_test extends \advanced_testcase { /** * Test setting config. */ - public function test_set_config() { + public function test_set_config(): void { $tour = new \tool_usertours\tour(); $tour->set_config('key', 'value'); $tour->set_config('another', [ - 'foo' => 'bar', - ]); + 'foo' => 'bar', + ]); $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('config'); $this->assertEquals((object) [ - 'key' => 'value', - 'another' => [ - 'foo' => 'bar', - ], - ], $rcp->getValue($tour)); + 'key' => 'value', + 'another' => [ + 'foo' => 'bar', + ], + ], $rcp->getValue($tour)); } /** * Test get_config with no keys provided. */ - public function test_get_config_no_keys() { + public function test_get_config_no_keys(): void { $tour = new \tool_usertours\tour(); $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('config'); $allvalues = (object) [ - 'some' => 'value', - 'another' => 42, - 'key' => [ - 'somethingelse', - ], - ]; + 'some' => 'value', + 'another' => 42, + 'key' => [ + 'somethingelse', + ], + ]; $rcp->setValue($tour, $allvalues); @@ -419,59 +400,59 @@ class tour_test extends \advanced_testcase { * * @return array */ - public function get_config_provider() { + public static function get_config_provider(): array { $allvalues = (object) [ - 'some' => 'value', - 'another' => 42, - 'key' => [ - 'somethingelse', - ], - ]; + 'some' => 'value', + 'another' => 42, + 'key' => [ + 'somethingelse', + ], + ]; return [ - 'No nitial config' => [ - null, - null, - null, - (object) [], - ], - 'All values' => [ - $allvalues, - null, - null, - $allvalues, - ], - 'Valid string value' => [ - $allvalues, - 'some', - null, - 'value', - ], - 'Valid array value' => [ - $allvalues, - 'key', - null, - ['somethingelse'], - ], - 'Invalid value' => [ - $allvalues, - 'notavalue', - null, - null, - ], - 'Configuration value' => [ - $allvalues, - 'placement', - null, - \tool_usertours\configuration::get_default_value('placement'), - ], - 'Invalid value with default' => [ - $allvalues, - 'notavalue', - 'somedefault', - 'somedefault', - ], - ]; + 'No nitial config' => [ + null, + null, + null, + (object) [], + ], + 'All values' => [ + $allvalues, + null, + null, + $allvalues, + ], + 'Valid string value' => [ + $allvalues, + 'some', + null, + 'value', + ], + 'Valid array value' => [ + $allvalues, + 'key', + null, + ['somethingelse'], + ], + 'Invalid value' => [ + $allvalues, + 'notavalue', + null, + null, + ], + 'Configuration value' => [ + $allvalues, + 'placement', + null, + \tool_usertours\configuration::get_default_value('placement'), + ], + 'Invalid value with default' => [ + $allvalues, + 'notavalue', + 'somedefault', + 'somedefault', + ], + ]; } /** @@ -483,7 +464,7 @@ class tour_test extends \advanced_testcase { * @param mixed $default The default value * @param mixed $expected The expected value */ - public function test_get_config_valid_keys($values, $key, $default, $expected) { + public function test_get_config_valid_keys($values, $key, $default, $expected): void { $tour = new \tool_usertours\tour(); $rc = new \ReflectionClass(tour::class); @@ -496,23 +477,20 @@ class tour_test extends \advanced_testcase { /** * Check that a tour which has never been persisted is removed correctly. */ - public function test_remove_non_persisted() { + public function test_remove_non_persisted(): void { $tour = $this->getMockBuilder(tour::class) ->onlyMethods([ - 'get_steps', - ]) - ->getMock() - ; + 'get_steps', + ]) + ->getMock(); $tour->expects($this->never()) - ->method('get_steps') - ; + ->method('get_steps'); // Mock the database. $DB = $this->mock_database(); $DB->expects($this->never()) - ->method('delete_records') - ; + ->method('delete_records'); $this->assertNull($tour->remove()); } @@ -520,15 +498,14 @@ class tour_test extends \advanced_testcase { /** * Check that a tour which has been persisted is removed correctly. */ - public function test_remove_persisted() { + public function test_remove_persisted(): void { $id = rand(1, 100); $tour = $this->getMockBuilder(tour::class) ->onlyMethods([ - 'get_steps', - ]) - ->getMock() - ; + 'get_steps', + ]) + ->getMock(); $rc = new \ReflectionClass(tour::class); $rcp = $rc->getProperty('id'); @@ -536,15 +513,13 @@ class tour_test extends \advanced_testcase { $step = $this->getMockBuilder(\tool_usertours\step::class) ->onlyMethods([ - 'remove', - ]) - ->getMock() - ; + 'remove', + ]) + ->getMock(); $tour->expects($this->once()) ->method('get_steps') - ->willReturn([$step]) - ; + ->willReturn([$step]); // Mock the database. $DB = $this->mock_database(); @@ -556,14 +531,12 @@ class tour_test extends \advanced_testcase { [$this->equalTo('user_preferences'), $this->equalTo(['name' => tour::TOUR_LAST_COMPLETED_BY_USER . $id])], [$this->equalTo('user_preferences'), $this->equalTo(['name' => tour::TOUR_REQUESTED_BY_USER . $id])] ) - ->willReturn(null) - ; + ->willReturn(null); $DB->expects($this->once()) ->method('get_records') ->with($this->equalTo('tool_usertours_tours'), $this->equalTo(null)) - ->willReturn([]) - ; + ->willReturn([]); $this->assertNull($tour->remove()); } @@ -571,7 +544,7 @@ class tour_test extends \advanced_testcase { /** * Teset that sortorder is reset according to sortorder with values from 0. */ - public function test_reset_step_sortorder() { + public function test_reset_step_sortorder(): void { $tour = new \tool_usertours\tour(); $mockdata = []; @@ -585,12 +558,10 @@ class tour_test extends \advanced_testcase { $DB = $this->mock_database(); $DB->expects($this->once()) ->method('get_records') - ->willReturn($mockdata) - ; + ->willReturn($mockdata); $setfield = $DB->expects($this->exactly(5)) - ->method('set_field') - ; + ->method('set_field'); call_user_func_array([$setfield, 'withConsecutive'], $expectations); $tour->reset_step_sortorder(); @@ -599,7 +570,7 @@ class tour_test extends \advanced_testcase { /** * Test that a disabled tour should never be shown to users. */ - public function test_should_show_for_user_disabled() { + public function test_should_show_for_user_disabled(): void { $tour = new \tool_usertours\tour(); $tour->set_enabled(false); @@ -611,40 +582,54 @@ class tour_test extends \advanced_testcase { * * @return array */ - public function should_show_for_user_provider() { + public static function should_show_for_user_provider(): array { $time = time(); return [ - 'Not seen by user at all' => [ - null, - null, - null, - true, - ], - 'Completed by user before majorupdatetime' => [ - $time - DAYSECS, - null, - $time, - true, - ], - 'Completed by user since majorupdatetime' => [ - $time, - null, - $time - DAYSECS, - false, - ], - 'Requested by user before current completion' => [ - $time, - $time - DAYSECS, - null, - false, - ], - 'Requested by user since completion' => [ - $time - DAYSECS, - $time, - null, - true, - ], - ]; + 'Not seen by user at all' => [ + null, + null, + null, + [], + true, + ], + 'Completed by user before majorupdatetime' => [ + $time - DAYSECS, + null, + $time, + [], + true, + ], + 'Completed by user since majorupdatetime' => [ + $time, + null, + $time - DAYSECS, + [], + false, + ], + 'Requested by user before current completion' => [ + $time, + $time - DAYSECS, + $time - MINSECS, + [], + false, + ], + 'Requested by user since completion' => [ + $time - DAYSECS, + $time, + 'null', + [], + true, + ], + 'Tour will show on each load' => [ + $time, + $time - DAYSECS, + null, + [ + 'showtourwhen' => tour::SHOW_TOUR_ON_EACH_PAGE_VISIT, + ], + true, + ], + ]; } /** @@ -654,30 +639,37 @@ class tour_test extends \advanced_testcase { * @param mixed $completiondate The user's completion date for this tour * @param mixed $requesteddate The user's last requested date for this tour * @param mixed $updateddate The date this tour was last updated + * @param mixed $config The tour config to apply * @param string $expectation The expected tour key */ - public function test_should_show_for_user($completiondate, $requesteddate, $updateddate, $expectation) { + public function test_should_show_for_user( + $completiondate, + $requesteddate, + $updateddate, + $config, + $expectation, + ): void { // Uses user preferences so we must be in a user context. $this->resetAfterTest(); $this->setAdminUser(); $tour = $this->getMockBuilder(tour::class) ->onlyMethods([ - 'get_id', - 'get_config', - 'is_enabled', - ]) - ->getMock() - ; + 'get_id', + 'is_enabled', + ]) + ->getMock(); $tour->method('is_enabled') - ->willReturn(true) - ; + ->willReturn(true); + + foreach ($config as $key => $value) { + $tour->set_config($key, $value); + } $id = rand(1, 100); $tour->method('get_id') - ->willReturn($id) - ; + ->willReturn($id); if ($completiondate !== null) { set_user_preference(\tool_usertours\tour::TOUR_LAST_COMPLETED_BY_USER . $id, $completiondate); @@ -688,10 +680,7 @@ class tour_test extends \advanced_testcase { } if ($updateddate !== null) { - $tour->expects($this->once()) - ->method('get_config') - ->willReturn($updateddate) - ; + $tour->set_config('majorupdatetime', $updateddate); } $this->assertEquals($expectation, $tour->should_show_for_user()); @@ -702,44 +691,47 @@ class tour_test extends \advanced_testcase { * * @return array */ - public function get_tour_key_provider() { + public static function get_tour_key_provider(): array { $id = rand(1, 100); $time = time(); return [ 'No initial values' => [ - $id, - [null, $time], - $this->greaterThanOrEqual($time), - true, - null, - sprintf('tool_usertours_\d_%d_%s', $id, $time), - ], + $id, + [null, $time], + static::logicalOr( + new \PHPUnit\Framework\Constraint\IsEqual($time), + new \PHPUnit\Framework\Constraint\GreaterThan($time), + ), + true, + null, + sprintf('tool_usertours_\d_%d_%s', $id, $time), + ], 'Initial tour time, no user pref' => [ - $id, - [$time], - null, - false, - null, - sprintf('tool_usertours_\d_%d_%s', $id, $time), - ], + $id, + [$time], + null, + false, + null, + sprintf('tool_usertours_\d_%d_%s', $id, $time), + ], 'Initial tour time, with user reset lower' => [ - $id, - [$time], - null, - false, - $time - DAYSECS, - sprintf('tool_usertours_\d_%d_%s', $id, $time), - ], + $id, + [$time], + null, + false, + $time - DAYSECS, + sprintf('tool_usertours_\d_%d_%s', $id, $time), + ], 'Initial tour time, with user reset higher' => [ - $id, - [$time], - null, - false, - $time + DAYSECS, - sprintf('tool_usertours_\d_%d_%s', $id, $time + DAYSECS), - ], + $id, + [$time], + null, + false, + $time + DAYSECS, + sprintf('tool_usertours_\d_%d_%s', $id, $time + DAYSECS), + ], ]; } @@ -754,83 +746,74 @@ class tour_test extends \advanced_testcase { * @param mixed $userpref The value to set for the user preference * @param string $expectation The expected tour key */ - public function test_get_tour_key($id, $getconfig, $setconfig, $willpersist, $userpref, $expectation) { + public function test_get_tour_key($id, $getconfig, $setconfig, $willpersist, $userpref, $expectation): void { // Uses user preferences so we must be in a user context. $this->resetAfterTest(); $this->setAdminUser(); $tour = $this->getMockBuilder(tour::class) ->onlyMethods([ - 'get_config', - 'set_config', - 'get_id', - 'persist', - ]) - ->getMock() - ; + 'get_config', + 'set_config', + 'get_id', + 'persist', + ]) + ->getMock(); if ($getconfig) { $tour->expects($this->exactly(count($getconfig))) ->method('get_config') - ->will(call_user_func_array([$this, 'onConsecutiveCalls'], $getconfig)) - ; + ->will(call_user_func_array([$this, 'onConsecutiveCalls'], $getconfig)); } if ($setconfig) { $tour->expects($this->once()) ->method('set_config') ->with($this->equalTo('majorupdatetime'), $setconfig) - ->will($this->returnSelf()) - ; + ->will($this->returnSelf()); } else { $tour->expects($this->never()) - ->method('set_config') - ; + ->method('set_config'); } if ($willpersist) { $tour->expects($this->once()) - ->method('persist') - ; + ->method('persist'); } else { $tour->expects($this->never()) - ->method('persist') - ; + ->method('persist'); } $tour->expects($this->any()) ->method('get_id') - ->willReturn($id) - ; + ->willReturn($id); if ($userpref !== null) { set_user_preference(\tool_usertours\tour::TOUR_REQUESTED_BY_USER . $id, $userpref); } $this->assertMatchesRegularExpression( - '/' . $expectation . '/', - $tour->get_tour_key() - ); + '/' . $expectation . '/', + $tour->get_tour_key() + ); } /** * Ensure that the request_user_reset function sets an appropriate value for the tour. */ - public function test_requested_user_reset() { + public function test_requested_user_reset(): void { $tour = $this->getMockBuilder(tour::class) ->onlyMethods([ - 'get_id', - ]) - ->getMock() - ; + 'get_id', + ]) + ->getMock(); $id = rand(1, 100); $time = time(); $tour->expects($this->once()) ->method('get_id') - ->willReturn($id) - ; + ->willReturn($id); $tour->request_user_reset(); @@ -840,21 +823,19 @@ class tour_test extends \advanced_testcase { /** * Ensure that the request_user_reset function sets an appropriate value for the tour. */ - public function test_mark_user_completed() { + public function test_mark_user_completed(): void { $tour = $this->getMockBuilder(tour::class) ->onlyMethods([ - 'get_id', - ]) - ->getMock() - ; + 'get_id', + ]) + ->getMock(); $id = rand(1, 100); $time = time(); $tour->expects($this->once()) ->method('get_id') - ->willReturn($id) - ; + ->willReturn($id); $tour->mark_user_completed(); @@ -866,34 +847,34 @@ class tour_test extends \advanced_testcase { * * @return array */ - public function sortorder_first_last_provider() { + public static function sortorder_first_last_provider(): array { $topcount = rand(10, 100); return [ - 'Only tour => first + last' => [ - 0, - true, - 1, - true, - ], - 'First tour of many' => [ - 0, - true, - $topcount, - false, - ], - 'Last tour of many' => [ - $topcount - 1, - false, - $topcount, - true, - ], - 'Middle tour of many' => [ - 5, - false, - $topcount, - false, - ], - ]; + 'Only tour => first + last' => [ + 0, + true, + 1, + true, + ], + 'First tour of many' => [ + 0, + true, + $topcount, + false, + ], + 'Last tour of many' => [ + $topcount - 1, + false, + $topcount, + true, + ], + 'Middle tour of many' => [ + 5, + false, + $topcount, + false, + ], + ]; } /** @@ -905,7 +886,7 @@ class tour_test extends \advanced_testcase { * @param int $total The number of tours * @param bool $islast Whether this is the last tour */ - public function test_is_first_tour($sortorder, $isfirst, $total, $islast) { + public function test_is_first_tour($sortorder, $isfirst, $total, $islast): void { $tour = new \tool_usertours\tour(); $rc = new \ReflectionClass(tour::class); @@ -924,7 +905,7 @@ class tour_test extends \advanced_testcase { * @param int $total The number of tours * @param bool $islast Whether this is the last tour */ - public function test_is_last_tour_calculated($sortorder, $isfirst, $total, $islast) { + public function test_is_last_tour_calculated($sortorder, $isfirst, $total, $islast): void { $tour = new \tool_usertours\tour(); $rc = new \ReflectionClass(tour::class); @@ -935,8 +916,7 @@ class tour_test extends \advanced_testcase { $DB = $this->mock_database(); $DB->expects($this->once()) ->method('count_records') - ->willReturn($total) - ; + ->willReturn($total); $this->assertEquals($islast, $tour->is_last_tour()); } @@ -949,7 +929,7 @@ class tour_test extends \advanced_testcase { * @param int $total The number of tours * @param bool $islast Whether this is the last tour */ - public function test_is_last_tour_provided($sortorder, $isfirst, $total, $islast) { + public function test_is_last_tour_provided($sortorder, $isfirst, $total, $islast): void { $tour = new \tool_usertours\tour(); $rc = new \ReflectionClass(tour::class); @@ -961,8 +941,7 @@ class tour_test extends \advanced_testcase { $DB = $this->mock_database(); $DB->expects($this->never()) ->method('count_records') - ->willReturn(0) - ; + ->willReturn(0); $this->assertEquals($islast, $tour->is_last_tour($total)); } @@ -971,7 +950,7 @@ class tour_test extends \advanced_testcase { * * @return array */ - public function get_filter_values_provider() { + public static function get_filter_values_provider(): array { $cheese = ['cheddar', 'boursin', 'mozzarella']; $horses = ['coolie', 'dakota', 'leo', 'twiggy']; return [ @@ -997,7 +976,7 @@ class tour_test extends \advanced_testcase { 'Some config for several filters' => [ [ 'horses' => $horses, - 'cheese' => $cheese + 'cheese' => $cheese, ], 'horses', $horses, @@ -1013,7 +992,7 @@ class tour_test extends \advanced_testcase { * @param string $filtername The name of the filter being tested * @param array $expectedvalues The expected result */ - public function test_get_filter_values($fullconfig, $filtername, $expectedvalues) { + public function test_get_filter_values($fullconfig, $filtername, $expectedvalues): void { $tour = $this->getMockBuilder(tour::class) ->onlyMethods(['get_config']) ->getMock(); @@ -1030,7 +1009,7 @@ class tour_test extends \advanced_testcase { * * @return array */ - public function set_filter_values_provider() { + public static function set_filter_values_provider(): array { $cheese = ['cheddar', 'boursin', 'mozzarella']; $horses = ['coolie', 'dakota', 'leo', 'twiggy']; @@ -1071,7 +1050,7 @@ class tour_test extends \advanced_testcase { * @param array $newvalues The new values to store * @param array $expectedvalues The combined values */ - public function test_set_filter_values_merge($currentvalues, $filtername, $newvalues, $expectedvalues) { + public function test_set_filter_values_merge($currentvalues, $filtername, $newvalues, $expectedvalues): void { $tour = $this->getMockBuilder(tour::class) ->onlyMethods(['get_config', 'set_config']) ->getMock();