diff --git a/lib/adminlib.php b/lib/adminlib.php index ac4f6ffa71e..eabb1a105eb 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -2466,7 +2466,7 @@ class admin_setting_configexecutable extends admin_setting_configfile { $default = $this->get_defaultsetting(); if ($data) { - if (file_exists($data) and is_executable($data)) { + if (file_exists($data) and !is_dir($data) and is_executable($data)) { $executable = ''; } else { $executable = ''; diff --git a/lib/tests/admintree_test.php b/lib/tests/admintree_test.php index e8389deafa9..623199f6cc0 100644 --- a/lib/tests/admintree_test.php +++ b/lib/tests/admintree_test.php @@ -111,6 +111,36 @@ class core_admintree_testcase extends advanced_testcase { $tree->add('root', new admin_category('bar', 'Bar'), ''); } + /** + * Testing whether a configexecutable setting is executable. + */ + public function test_admin_setting_configexecutable() { + global $CFG; + $this->resetAfterTest(); + + $executable = new admin_setting_configexecutable('test1', 'Text 1', 'Help Path', ''); + + // Check for an invalid path. + $result = $executable->output_html($CFG->dirroot . '/lib/tests/other/file_does_not_exist'); + $this->assertRegexp('/class="patherror"/', $result); + + // Check for a directory. + $result = $executable->output_html($CFG->dirroot); + $this->assertRegexp('/class="patherror"/', $result); + + // Check for a file which is not executable. + $result = $executable->output_html($CFG->dirroot . '/config.php'); + $this->assertRegexp('/class="patherror"/', $result); + + // Check for an executable file. + $result = $executable->output_html($CFG->dirroot . '/lib/tests/other/executable.php'); + $this->assertRegexp('/class="pathok"/', $result); + + // Check for no file specified. + $result = $executable->output_html(''); + $this->assertRegexp('/name="s__test1" value=""/', $result); + } + /** * Saving of values. */ diff --git a/lib/tests/other/executable.php b/lib/tests/other/executable.php new file mode 100755 index 00000000000..e69de29bb2d