/** * 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); }
/** * Tests the get_mimetype_description function. */ public function test_get_mimetype_description() { $this->resetAfterTest(); // Test example type (.doc). $this->assertEquals(get_string('application/msword', 'mimetypes'), get_mimetype_description(array('filename' => 'test.doc'))); // Test an unknown file type. $this->assertEquals(get_string('document/unknown', 'mimetypes'), get_mimetype_description(array('filename' => 'test.frog'))); // Test a custom filetype with no lang string specified. core_filetypes::add_type('frog', 'application/x-frog', 'document'); $this->assertEquals('application/x-frog', get_mimetype_description(array('filename' => 'test.frog'))); // Test custom description. core_filetypes::update_type('frog', 'frog', 'application/x-frog', 'document', array(), '', 'Froggy file'); $this->assertEquals('Froggy file', get_mimetype_description(array('filename' => 'test.frog'))); // Test custom description using multilang filter. filter_set_global_state('multilang', TEXTFILTER_ON); filter_set_applies_to_strings('multilang', true); core_filetypes::update_type('frog', 'frog', 'application/x-frog', 'document', array(), '', '<span lang="en" class="multilang">Green amphibian</span>' . '<span lang="fr" class="multilang">Amphibian vert</span>'); $this->assertEquals('Green amphibian', get_mimetype_description(array('filename' => 'test.frog'))); }
} if (empty($data->defaulticon)) { $data->defaulticon = 0; } if (empty($data->corestring)) { $data->corestring = ''; } if (empty($data->description)) { $data->description = ''; } if ($data->oldextension) { // Update an existing file type. core_filetypes::update_type($data->oldextension, $data->extension, $data->mimetype, $data->icon, $data->groups, $data->corestring, $data->description, (bool) $data->defaulticon); } else { // Add a new file type entry. core_filetypes::add_type($data->extension, $data->mimetype, $data->icon, $data->groups, $data->corestring, $data->description, (bool) $data->defaulticon); } redirect($backurl); } } // Page settings. $context = context_system::instance(); $PAGE->set_url(new \moodle_url('/admin/tool/filetypes/edit.php', array('oldextension' => $oldextension))); $PAGE->navbar->add($oldextension ? s($oldextension) : $title); $PAGE->set_context($context); $PAGE->set_pagelayout('admin'); $PAGE->set_title($SITE->fullname . ': ' . $title); // Display the page. echo $OUTPUT->header(); $mform->display(); echo $OUTPUT->footer();