mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-73546-master' of https://github.com/sarjona/moodle
This commit is contained in:
commit
7be7bb5164
@ -94,6 +94,24 @@ class load extends base {
|
||||
* the preset available settings.
|
||||
*/
|
||||
public function show(): void {
|
||||
$this->display_preset(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a preset information (name, description, settings different from the current configuration...).
|
||||
*/
|
||||
public function preview(): void {
|
||||
$this->display_preset(false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to prepare the information to preview/load the preset.
|
||||
*
|
||||
* @param bool $displayform Whether the form should be displayed in the page or not.
|
||||
* @param bool $raiseexception Whether the exception should be raised or not when the preset doesn't exist. When it's set
|
||||
* to false, a message is displayed, instead of raising the exception.
|
||||
*/
|
||||
protected function display_preset(bool $displayform = true, bool $raiseexception = true) {
|
||||
global $DB, $OUTPUT;
|
||||
|
||||
$data = new stdClass();
|
||||
@ -101,7 +119,12 @@ class load extends base {
|
||||
|
||||
// Preset data.
|
||||
if (!$preset = $DB->get_record('adminpresets', ['id' => $data->id])) {
|
||||
if ($raiseexception) {
|
||||
throw new moodle_exception('errornopreset', 'core_adminpresets');
|
||||
} else {
|
||||
$this->outputs = get_string('errornopreset', 'core_adminpresets');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Print preset basic data.
|
||||
@ -125,6 +148,7 @@ class load extends base {
|
||||
$applieddata->settings = $applied;
|
||||
$applieddata->beforeapplying = true;
|
||||
$application->appliedchanges = $applieddata;
|
||||
if ($displayform) {
|
||||
if (empty($applied)) {
|
||||
// Display a warning when no settings will be applied.
|
||||
$applieddata->message = get_string('nosettingswillbeapplied', 'tool_admin_presets');
|
||||
@ -138,9 +162,9 @@ class load extends base {
|
||||
$this->moodleform = new load_form($url);
|
||||
$this->moodleform->set_data($data);
|
||||
}
|
||||
}
|
||||
|
||||
$this->outputs .= $OUTPUT->render_from_template('tool_admin_presets/settings_application', $application);
|
||||
|
||||
}
|
||||
|
||||
protected function get_explanatory_description(): ?string {
|
||||
|
@ -51,6 +51,33 @@ class load_test extends \advanced_testcase {
|
||||
$action->show();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the behaviour of preview() method when the preset id doesn't exist.
|
||||
*
|
||||
* @covers ::preview
|
||||
*/
|
||||
public function test_load_preview_unexisting_preset(): void {
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create some presets.
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_adminpresets');
|
||||
$presetid = $generator->create_preset();
|
||||
|
||||
// Initialise the parameters and create the load class.
|
||||
$_POST['action'] = 'load';
|
||||
$_POST['mode'] = 'preview';
|
||||
$_POST['id'] = $presetid * 2; // Unexisting preset identifier.
|
||||
|
||||
$action = new load();
|
||||
$action->preview();
|
||||
$outputs = $generator->access_protected($action, 'outputs');
|
||||
// In that case, no exception should be raised and the text of no preset found should be displayed.
|
||||
$this->assertEquals(get_string('errornopreset', 'core_adminpresets'), $outputs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the behaviour of execute() method.
|
||||
*
|
||||
|
@ -27,7 +27,7 @@ $string['disabledwithvalue'] = 'Disabled ({$a})';
|
||||
$string['enabled'] = 'Enabled';
|
||||
$string['errordeleting'] = 'Error deleting from database.';
|
||||
$string['errorinserting'] = 'Error inserting into database.';
|
||||
$string['errornopreset'] = 'It doesn\'t exists a preset with that name.';
|
||||
$string['errornopreset'] = 'It doesn\'t exist a preset with that name.';
|
||||
$string['fullpreset'] = 'Full';
|
||||
$string['fullpresetdescription'] = 'All the Starter features plus External (LTI) tool, SCORM, Workshop, Analytics, Badges, Competencies, Learning plans and lots more.';
|
||||
$string['markedasadvanced'] = 'marked as advanced';
|
||||
|
Loading…
x
Reference in New Issue
Block a user