/** * Tests is_defaulticon_allowed() function. */ public function test_is_defaulticon_allowed() { // You ARE allowed to set a default icon for a MIME type that hasn't // been used yet. $this->assertTrue(utils::is_defaulticon_allowed('application/x-frog')); // You AREN'T allowed to set default icon for text/plain as there is // already a type that has that set. $this->assertFalse(utils::is_defaulticon_allowed('text/plain')); // But you ARE still allowed to set it when actually editing txt, which // is the default. $this->assertTrue(utils::is_defaulticon_allowed('text/plain', 'txt')); }
public function validation($data, $files) { $errors = parent::validation($data, $files); // Check the extension isn't already in use. $oldextension = $data['oldextension']; $extension = trim($data['extension']); if (\tool_filetypes\utils::is_extension_invalid($extension, $oldextension)) { $errors['extension'] = get_string('error_extension', 'tool_filetypes', $extension); } // Check the 'default icon' setting doesn't conflict with an existing one. if (!empty($data['defaulticon']) && !\tool_filetypes\utils::is_defaulticon_allowed($data['mimetype'], $oldextension)) { $errors['defaulticon'] = get_string('error_defaulticon', 'tool_filetypes', $extension); } // If you choose 'lang' or 'custom' descriptiontype, you must fill something in the field. switch ($data['descriptiontype']) { case 'lang': if (!trim($data['corestring'])) { $errors['corestring'] = get_string('required'); } break; case 'custom': if (!trim($data['description'])) { $errors['description'] = get_string('required'); } break; } return $errors; }
public function validation($data, $files) { $errors = parent::validation($data, $files); // Check the extension isn't already in use. $oldextension = $data['oldextension']; $extension = trim($data['extension']); if (\tool_filetypes\utils::is_extension_invalid($extension, $oldextension)) { $errors['extension'] = get_string('error_extension', 'tool_filetypes', $extension); } // Check the 'default icon' setting doesn't conflict with an existing one. if (!empty($data['defaulticon']) && !\tool_filetypes\utils::is_defaulticon_allowed($data['mimetype'], $oldextension)) { $errors['defaulticon'] = get_string('error_defaulticon', 'tool_filetypes', $extension); } return $errors; }