Merge branch 'wip_MDL-41593_m28_preventexecdefault' of https://github.com/skodak/moodle

This commit is contained in:
Damyon Wiese 2014-10-21 13:11:27 +08:00
commit a6396272f8
2 changed files with 64 additions and 2 deletions

View File

@ -2441,13 +2441,22 @@ class admin_setting_configfile extends admin_setting_configtext {
'<div class="form-file defaultsnext"><input type="text" size="'.$this->size.'" id="'.$this->get_id().'" name="'.$this->get_full_name().'" value="'.s($data).'" />'.$executable.'</div>',
$this->description, true, '', $default, $query);
}
/**
* checks if execpatch has been disabled in config.php
* Checks if execpatch has been disabled in config.php
*/
public function write_setting($data) {
global $CFG;
if (!empty($CFG->preventexecpath)) {
return '';
if ($this->get_setting() === null) {
// Use default during installation.
$data = $this->get_defaultsetting();
if ($data === null) {
$data = '';
}
} else {
return '';
}
}
return parent::write_setting($data);
}

View File

@ -245,4 +245,57 @@ class core_admintree_testcase extends advanced_testcase {
return $count;
}
public function test_preventexecpath() {
$this->resetAfterTest();
set_config('preventexecpath', 0);
set_config('execpath', null, 'abc_cde');
$this->assertFalse(get_config('abc_cde', 'execpath'));
$setting = new admin_setting_configexecutable('abc_cde/execpath', 'some desc', '', '/xx/yy');
$setting->write_setting('/oo/pp');
$this->assertSame('/oo/pp', get_config('abc_cde', 'execpath'));
// Prevent changes.
set_config('preventexecpath', 1);
$setting->write_setting('/mm/nn');
$this->assertSame('/oo/pp', get_config('abc_cde', 'execpath'));
// Use default in install.
set_config('execpath', null, 'abc_cde');
$setting->write_setting('/mm/nn');
$this->assertSame('/xx/yy', get_config('abc_cde', 'execpath'));
// Use empty value if no default.
$setting = new admin_setting_configexecutable('abc_cde/execpath', 'some desc', '', null);
set_config('execpath', null, 'abc_cde');
$setting->write_setting('/mm/nn');
$this->assertSame('', get_config('abc_cde', 'execpath'));
// This also (most probably incorrectly) affects admin_setting_configfile.
set_config('preventexecpath', 0);
set_config('execpath', null, 'abc_cde');
$this->assertFalse(get_config('abc_cde', 'execpath'));
$setting = new admin_setting_configfile('abc_cde/execpath', 'some desc', '', '/xx/yy');
$setting->write_setting('/oo/pp');
$this->assertSame('/oo/pp', get_config('abc_cde', 'execpath'));
// Prevent changes.
set_config('preventexecpath', 1);
$setting->write_setting('/mm/nn');
$this->assertSame('/oo/pp', get_config('abc_cde', 'execpath'));
// Use default in install.
set_config('execpath', null, 'abc_cde');
$setting->write_setting('/mm/nn');
$this->assertSame('/xx/yy', get_config('abc_cde', 'execpath'));
// Use empty value if no default.
$setting = new admin_setting_configfile('abc_cde/execpath', 'some desc', '', null);
set_config('execpath', null, 'abc_cde');
$setting->write_setting('/mm/nn');
$this->assertSame('', get_config('abc_cde', 'execpath'));
}
}