This commit is contained in:
Jun Pataleta
2024-03-12 11:41:58 +08:00
50 changed files with 1230 additions and 1448 deletions
+3 -12
View File
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace tool_usertours;
/**
* Cache manager.
*
@@ -21,17 +23,6 @@
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @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;
}
+8 -19
View File
@@ -14,26 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Step configuration detail class.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @package tool_usertours
* @copyright 2024 Andrew Nicols <[email protected]>
* @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;
}
}
@@ -14,18 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The tool_usertours step_shown event.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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.
*/
@@ -14,18 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The tool_usertours tour_ended event.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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.
*/
@@ -14,18 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The tool_usertours tour_reset event.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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.
*/
@@ -14,18 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The tool_usertours tour_started event.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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.
*/
+95 -71
View File
@@ -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
),
]);
}
}
+75 -87
View File
@@ -14,29 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tour helper.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @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();
});
@@ -14,18 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
}
}
}
@@ -14,13 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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;
@@ -13,29 +13,19 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Access Date filter.
*
* @package tool_usertours
* @copyright 2019 Tom Dickman <[email protected]>
* @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 <[email protected]>
* @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;
}
}
}
@@ -14,24 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Filter base.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -14,24 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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
*/
@@ -14,24 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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
*/
@@ -14,24 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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
*/
@@ -14,24 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Theme filter.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @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.
@@ -14,24 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Theme filter.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -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.
@@ -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);
@@ -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'));
@@ -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(),
@@ -14,23 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Target base.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace tool_usertours\local\target;
/**
* Block target.
*
@@ -21,21 +23,7 @@
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @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)
);
}
/**
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace tool_usertours\local\target;
/**
* Selector target.
*
@@ -21,21 +23,7 @@
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @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)
);
}
/**
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace tool_usertours\local\target;
/**
* A step designed to be orphaned.
*
@@ -21,19 +23,6 @@
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @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.
+9 -17
View File
@@ -14,18 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tour manager.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @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;
}
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace tool_usertours\output;
/**
* Renderer.
*
@@ -21,16 +23,5 @@
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends \plugin_renderer_base {
}
+18 -13
View File
@@ -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(),
];
+4 -14
View File
@@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace tool_usertours\output;
use tool_usertours\tour as toursource;
/**
* Tour renderable.
*
@@ -21,21 +25,7 @@
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tour implements \renderable {
/**
* @var The tour instance.
*/
@@ -14,25 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for tool_usertours.
*
* @package tool_usertours
* @copyright 2018 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @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.
*
+18 -24
View File
@@ -14,6 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace tool_usertours;
use context_system;
use stdClass;
/**
* Step class.
*
@@ -21,22 +26,7 @@
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @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<identifier>([^::]*))::(?P<component>([^@@]*))@@%',
function(array $matches) {
$content = preg_replace_callback(
'%@@PIXICON::(?P<identifier>([^::]*))::(?P<component>([^@@]*))@@%',
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
);
+2 -12
View File
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace tool_usertours;
/**
* Target class.
*
@@ -21,19 +23,7 @@
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class target {
/**
* @var TARGET_SELECTOR The target is a CSS selector.
*/
+47 -22
View File
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace tool_usertours;
/**
* Tour class.
*
@@ -21,21 +23,7 @@
* @copyright 2016 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @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);
}
}
+2 -2
View File
@@ -31,5 +31,5 @@ $pluginmanager = new \tool_usertours\manager();
$PAGE->set_context(context_system::instance());
$pluginmanager->execute(
$action
);
$action
);
+3 -3
View File
@@ -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,
]
],
],
);
];
+6 -6
View File
@@ -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,
),
);
],
];
+10 -10
View File
@@ -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,
),
);
],
];
@@ -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?';
@@ -24,9 +24,9 @@ use tool_usertours\local\filter\accessdate;
* @package tool_usertours
* @copyright 2019 Tom Dickman <[email protected]>
* @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));
}
}
@@ -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')
);
}
@@ -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"
+21 -21
View File
@@ -27,6 +27,7 @@ require_once(__DIR__ . '/helper_trait.php');
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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();
+3 -13
View File
@@ -14,35 +14,25 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Tests for helper.
*
* @package tool_usertours
* @copyright 2022 Huong Nguyen <[email protected]>
* @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 <[email protected]>
* @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));
}
}
+1 -11
View File
@@ -14,16 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Helpers for unit tests.
*
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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) {
+118 -116
View File
@@ -28,6 +28,7 @@ require_once(__DIR__ . '/helper_trait.php');
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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();
@@ -14,18 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for the tool_usertours implementation of the privacy API.
*
* @package tool_usertours
* @category test
* @copyright 2018 Andrew Nicols <[email protected]>
* @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 <[email protected]>
* @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();
@@ -22,9 +22,9 @@ namespace tool_usertours;
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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);
+254 -300
View File
@@ -27,9 +27,9 @@ require_once($CFG->libdir . '/formslib.php');
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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@@<br>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@@<br>Test<br>@@PIXICON::tour/tour_myhomepage::tool_usertours@@';
$stepcontent =
'@@PIXICON::tour/tour_mycourses::tool_usertours@@<br>Test<br>@@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('<img', $stepcontent);
@@ -22,15 +22,15 @@ namespace tool_usertours;
* @package tool_usertours
* @copyright 2016 Andrew Nicols <[email protected]>
* @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;
File diff suppressed because it is too large Load Diff