mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
Merge branch 'MDL-64429' of https://github.com/paulholden/moodle
This commit is contained in:
commit
e0552f271b
@ -762,6 +762,13 @@ class manager {
|
||||
* @param int $direction
|
||||
*/
|
||||
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)) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$currentsortorder = $tour->get_sortorder();
|
||||
$targetsortorder = $currentsortorder + $direction;
|
||||
|
||||
@ -890,6 +897,9 @@ class manager {
|
||||
}
|
||||
$existingtourrecords->close();
|
||||
|
||||
// Ensure we correct the sortorder in any existing tours, prior to adding latest shipped tours.
|
||||
helper::reset_tour_sortorder();
|
||||
|
||||
foreach (array_reverse($shippedtours) as $filename => $version) {
|
||||
$filepath = $CFG->dirroot . "/{$CFG->admin}/tool/usertours/tours/" . $filename;
|
||||
$tourjson = file_get_contents($filepath);
|
||||
|
@ -61,5 +61,12 @@ function xmldb_tool_usertours_upgrade($oldversion) {
|
||||
// Automatically generated Moodle v3.8.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
if ($oldversion < 2020031900) {
|
||||
// Updating shipped tours will fix broken sortorder records in existing tours.
|
||||
manager::update_shipped_tours();
|
||||
|
||||
upgrade_plugin_savepoint(true, 2020031900, 'tool', 'usertours');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -122,6 +122,83 @@ class tool_usertours_manager_testcase extends advanced_testcase {
|
||||
$rcm->invokeArgs($manager, $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_move_tour
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function move_tour_provider() {
|
||||
$alltours = [
|
||||
['name' => 'Tour 1'],
|
||||
['name' => 'Tour 2'],
|
||||
['name' => 'Tour 3'],
|
||||
];
|
||||
|
||||
return [
|
||||
'Move up' => [
|
||||
$alltours,
|
||||
'Tour 2',
|
||||
\tool_usertours\helper::MOVE_UP,
|
||||
0,
|
||||
],
|
||||
'Move down' => [
|
||||
$alltours,
|
||||
'Tour 2',
|
||||
\tool_usertours\helper::MOVE_DOWN,
|
||||
2,
|
||||
],
|
||||
'Move up (first)' => [
|
||||
$alltours,
|
||||
'Tour 1',
|
||||
\tool_usertours\helper::MOVE_UP,
|
||||
0,
|
||||
],
|
||||
'Move down (last)' => [
|
||||
$alltours,
|
||||
'Tour 3',
|
||||
\tool_usertours\helper::MOVE_DOWN,
|
||||
2,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test moving tours (changing sortorder)
|
||||
*
|
||||
* @dataProvider move_tour_provider
|
||||
*
|
||||
* @param array $alltours
|
||||
* @param string $movetourname
|
||||
* @param int $direction
|
||||
* @param int $expectedsortorder
|
||||
* @return void
|
||||
*/
|
||||
public function test_move_tour($alltours, $movetourname, $direction, $expectedsortorder) {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Clear out existing tours so ours are the only ones, otherwise we can't predict the sortorder.
|
||||
$DB->delete_records('tool_usertours_tours');
|
||||
|
||||
foreach ($alltours as $tourconfig) {
|
||||
$this->helper_create_tour((object) $tourconfig);
|
||||
}
|
||||
|
||||
// Load our tour to move.
|
||||
$record = $DB->get_record('tool_usertours_tours', ['name' => $movetourname]);
|
||||
$tour = \tool_usertours\tour::load_from_record($record);
|
||||
|
||||
// Call protected method via reflection.
|
||||
$class = new ReflectionClass(\tool_usertours\manager::class);
|
||||
$method = $class->getMethod('_move_tour');
|
||||
$method->setAccessible(true);
|
||||
$method->invokeArgs(null, [$tour, $direction]);
|
||||
|
||||
// Assert expected sortorder.
|
||||
$this->assertEquals($expectedsortorder, $tour->get_sortorder());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data Provider for get_matching_tours tests.
|
||||
*
|
||||
|
@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2019120400; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2020031900; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2019111200; // Requires this Moodle version.
|
||||
$plugin->component = 'tool_usertours'; // Full name of the plugin (used for diagnostics).
|
||||
|
Loading…
x
Reference in New Issue
Block a user