Exemplo n.º 1
0
/**
 * Delete a file type with a confirmation box.
 *
 * @package tool_filetypes
 * @copyright 2014 The Open University
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require __DIR__ . '/../../../config.php';
require_once $CFG->libdir . '/adminlib.php';
admin_externalpage_setup('tool_filetypes');
$extension = required_param('extension', PARAM_ALPHANUMEXT);
$redirecturl = new \moodle_url('/admin/tool/filetypes/index.php');
if (optional_param('delete', 0, PARAM_INT)) {
    require_sesskey();
    // Delete the file type from the config.
    core_filetypes::delete_type($extension);
    redirect($redirecturl);
}
// Page settings.
$title = get_string('deletefiletypes', 'tool_filetypes');
$context = context_system::instance();
$PAGE->set_url(new \moodle_url('/admin/tool/filetypes/delete.php', array('extension' => $extension)));
$PAGE->navbar->add($title);
$PAGE->set_context($context);
$PAGE->set_pagelayout('admin');
$PAGE->set_title($SITE->fullname . ': ' . $title);
// Display the page.
echo $OUTPUT->header();
$message = get_string('delete_confirmation', 'tool_filetypes', $extension);
$deleteurl = new \moodle_url('delete.php', array('extension' => $extension, 'delete' => 1));
$yesbutton = new single_button($deleteurl, get_string('yes'));
Exemplo n.º 2
0
 /**
  * Check that the logic cleans up the variable by deleting parts that are
  * no longer needed.
  */
 public function test_cleanup()
 {
     global $CFG;
     $this->resetAfterTest();
     // The custom filetypes setting is empty to start with.
     $this->assertObjectNotHasAttribute('customfiletypes', $CFG);
     // Add a custom filetype, then delete it.
     core_filetypes::add_type('frog', 'application/x-frog', 'document');
     $this->assertObjectHasAttribute('customfiletypes', $CFG);
     core_filetypes::delete_type('frog');
     $this->assertObjectNotHasAttribute('customfiletypes', $CFG);
     // Change a standard filetype, then change it back.
     core_filetypes::update_type('asm', 'asm', 'text/plain', 'document');
     $this->assertObjectHasAttribute('customfiletypes', $CFG);
     core_filetypes::update_type('asm', 'asm', 'text/plain', 'sourcecode');
     $this->assertObjectNotHasAttribute('customfiletypes', $CFG);
     // Delete a standard filetype, then add it back (the same).
     core_filetypes::delete_type('asm');
     $this->assertObjectHasAttribute('customfiletypes', $CFG);
     core_filetypes::add_type('asm', 'text/plain', 'sourcecode');
     $this->assertObjectNotHasAttribute('customfiletypes', $CFG);
     // Revert a changed type.
     core_filetypes::update_type('asm', 'asm', 'text/plain', 'document');
     $this->assertObjectHasAttribute('customfiletypes', $CFG);
     core_filetypes::revert_type_to_default('asm');
     $this->assertObjectNotHasAttribute('customfiletypes', $CFG);
     // Revert a deleted type.
     core_filetypes::delete_type('asm');
     $this->assertObjectHasAttribute('customfiletypes', $CFG);
     core_filetypes::revert_type_to_default('asm');
     $this->assertObjectNotHasAttribute('customfiletypes', $CFG);
 }