Permalink
Browse files

MDL-31175 backup: Fixed undefined in register_dependency

  • Loading branch information...
Sam Hemelryk
Sam Hemelryk committed Mar 1, 2012
1 parent 476626d commit 730394495753623e9a5398b9d7e870d75cbd8780
Showing with 18 additions and 1 deletion.
  1. +1 −1 backup/util/settings/base_setting.class.php
  2. +17 −0 backup/util/settings/simpletest/testsettings.php
@@ -294,7 +294,7 @@ public function register_dependency(setting_dependency $dependency) {
if ($this->is_circular_reference($dependency->get_dependent_setting())) {
$a = new stdclass();
$a->alreadydependent = $this->name;
- $a->main = $dependentsetting->get_name();
+ $a->main = $dependency->get_dependent_setting()->get_name();
throw new base_setting_exception('setting_circular_reference', $a);
}
$this->dependencies[$dependency->get_dependent_setting()->get_name()] = $dependency;
@@ -32,10 +32,12 @@
require_once($CFG->dirroot . '/backup/backup.class.php');
require_once($CFG->dirroot . '/backup/util/settings/base_setting.class.php');
require_once($CFG->dirroot . '/backup/util/settings/backup_setting.class.php');
+require_once($CFG->dirroot . '/backup/util/settings/setting_dependency.class.php');
require_once($CFG->dirroot . '/backup/util/settings/root/root_backup_setting.class.php');
require_once($CFG->dirroot . '/backup/util/settings/activity/activity_backup_setting.class.php');
require_once($CFG->dirroot . '/backup/util/settings/section/section_backup_setting.class.php');
require_once($CFG->dirroot . '/backup/util/settings/course/course_backup_setting.class.php');
+require_once($CFG->dirroot . '/backup/util/ui/backup_ui_setting.class.php');
/*
* setting tests (all)
@@ -209,6 +211,21 @@ function test_base_setting() {
$this->assertEqual($e->a->alreadydependent, 'test4');
}
+ $bs1 = new mock_base_setting('test1', base_setting::IS_INTEGER, null);
+ $bs2 = new mock_base_setting('test2', base_setting::IS_INTEGER, null);
+ $bs1->register_dependency(new setting_dependency_disabledif_empty($bs1, $bs2));
+ try {
+ // $bs1 is already dependent on $bs2 so this should fail.
+ $bs2->register_dependency(new setting_dependency_disabledif_empty($bs2, $bs1));
+ $this->assertTrue(false, 'base_setting_exception expected');
+ } catch (exception $e) {
+ $this->assertTrue($e instanceof base_setting_exception);
+ $this->assertEqual($e->errorcode, 'setting_circular_reference');
+ $this->assertTrue($e->a instanceof stdclass);
+ $this->assertEqual($e->a->main, 'test1');
+ $this->assertEqual($e->a->alreadydependent, 'test2');
+ }
+
// Create 3 settings and observe between them, last one must
// automatically inherit all the settings defined in the main one
$bs1 = new mock_base_setting('test1', base_setting::IS_INTEGER, null);

0 comments on commit 7303944

Please sign in to comment.