Skip to content

Commit

Permalink
rename mbz field plugin_set_version to plugin_release_set_version, ru…
Browse files Browse the repository at this point in the history
…n a test in separate process
  • Loading branch information
Glutamat42 committed Sep 30, 2024
1 parent 4c0ea1f commit d2c3005
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions backup/moodle2/backup_local_adler_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ protected function define_course_plugin_structure(): backup_plugin_element {

// Define each element separated
$pluginwrapper = new backup_nested_element($this->get_recommended_name(), null, [
'plugin_set_version',
'plugin_release_set_version',
]);

// Moodle does not allow names in nested elements that are used in the root element, therefore "score" is not allowed
Expand All @@ -23,7 +23,7 @@ protected function define_course_plugin_structure(): backup_plugin_element {

// Define sources
// version number according to https://github.com/ProjektAdLer/moodle-docker/blob/main/plugin-releases.json
$pluginwrapper->set_source_array([['plugin_set_version' => '4.0.0']]);
$pluginwrapper->set_source_array([['plugin_release_set_version' => '4.0.0']]);
$adler_course->set_source_table('local_adler_course', array('course_id' => backup::VAR_COURSEID));
// Define id annotations

Expand Down
20 changes: 10 additions & 10 deletions backup/moodle2/restore_local_adler_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ class restore_local_adler_plugin extends restore_local_plugin {
// define_module_plugin_structure, define_grade_item_plugin_structure, define_question_plugin_structure
protected $db;

private $plugin_set_version;
private $plugin_release_set_version;
private $log;

public function __construct($name, $plugin, $restore) {
global $DB;
parent::__construct($name, $plugin, $restore);
$this->db = $DB;
$this->log = new logger('local_adler', self::class);
$this->plugin_set_version = null;
$this->plugin_release_set_version = null;
}

protected function define_course_plugin_structure(): array {
return [
new restore_path_element('plugin_set_version', $this->get_pathfor('/')),
new restore_path_element('plugin_release_set_version', $this->get_pathfor('/')),
new restore_path_element('adler_course', $this->get_pathfor('/adler_course'))
];
}

public function process_plugin_set_version($data) {
public function process_plugin_release_set_version($data) {
$data = (object)$data;

if (property_exists($data, 'plugin_set_version') ) {
if (version_compare($data->plugin_set_version, '4.0.0', '<')) {
throw new moodle_exception('invalid_plugin_set_version', 'local_adler', '', null, 'plugin_set_version is below 3.2.0');
if (property_exists($data, 'plugin_release_set_version') ) {
if (version_compare($data->plugin_release_set_version, '4.0.0', '<')) {
throw new moodle_exception('invalid_plugin_release_set_version', 'local_adler', '', null, 'plugin_release_set_version is below 3.2.0');
}
$this->plugin_set_version = $data->plugin_set_version;
$this->plugin_release_set_version = $data->plugin_release_set_version;
}
}

Expand Down Expand Up @@ -137,8 +137,8 @@ public function process_adler_module($data) {
* @throws not_an_adler_course_exception
*/
public function after_restore_course() {
$this->log->info('Restoring course with plugin set version ' . $this->plugin_set_version);
if (empty($this->plugin_set_version)) {
$this->log->info('Restoring course with plugin set version ' . $this->plugin_release_set_version);
if (empty($this->plugin_release_set_version)) {
try {
(new upgrade_3_2_0_to_4_0_0_completionlib($this->task->get_courseid()))->execute();
} catch (not_an_adler_course_exception $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace local_adler\local\upgrade;

use cm_info;
use dml_exception;
use local_adler\helpers;
use local_adler\local\db\moodle_core_repository;
Expand Down
4 changes: 2 additions & 2 deletions tests/backup/moodle2/backup_adler_plugin_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function test_backup_course_not_adler_course() {
/**
* # ANF-ID: [MVP1]
*/
public function test_plugin_set_version_property() {
public function test_plugin_release_set_version_property() {
// Create score item with generator
$adler_course_object = $this
->getDataGenerator()
Expand All @@ -218,6 +218,6 @@ public function test_plugin_set_version_property() {
$xml = $this->get_xml_from_backup($bc, 'course');

// Validate xml values
$this->assertMatchesRegularExpression('/^\d+\.\d+\.\d+$/', (string)$xml->plugin_local_adler_course->plugin_set_version, 'plugin_set_version should be a valid semantic version');
$this->assertMatchesRegularExpression('/^\d+\.\d+\.\d+$/', (string)$xml->plugin_local_adler_course->plugin_release_set_version, 'plugin_release_set_version should be a valid semantic version');
}
}
11 changes: 6 additions & 5 deletions tests/backup/moodle2/restore_adler_plugin_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ public function test_define_course_plugin_structure() {

// verify
$this->assertCount(2, $paths);
$this->assertEquals('adler_course', $paths[0]->get_name());
$this->assertStringContainsString('adler_course', $paths[0]->get_path());
$this->assertEquals('plugin_release_set_version', $paths[0]->get_name());
$this->assertEquals('adler_course', $paths[1]->get_name());
}

/**
Expand Down Expand Up @@ -401,6 +401,7 @@ public function provide_test_call_upgrade_3_2_0_to_4_0_0_completionlib_data() {

/**
* @dataProvider provide_test_call_upgrade_3_2_0_to_4_0_0_completionlib_data
* @runInSeparateProcess
*/
public function test_call_upgrade_3_2_0_to_4_0_0_completionlib($version) {
// setup mock
Expand All @@ -413,20 +414,20 @@ public function test_call_upgrade_3_2_0_to_4_0_0_completionlib($version) {

if ($version === '1.1.0') {
$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('invalid_plugin_set_version');
$this->expectExceptionMessage('invalid_plugin_release_set_version');
}

// setup data
list($data, $stub) = $this->setUpCourse();
if ($version !== null) {
$data->plugin_set_version = $version;
$data->plugin_release_set_version = $version;
}

// create test object
$plugin = new restore_local_adler_plugin('local', 'adler', $stub);

// call the method to test
$plugin->process_plugin_set_version($data);
$plugin->process_plugin_release_set_version($data);
$plugin->after_restore_course();
}
}

0 comments on commit d2c3005

Please sign in to comment.