Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

mime_type_test.rb 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../../../test_helper', __FILE__)
  19. class Redmine::MimeTypeTest < ActiveSupport::TestCase
  20. def test_of
  21. to_test = {
  22. 'test.txt' => 'text/plain',
  23. 'test.c' => 'text/x-c',
  24. 'TEST.JPG' => 'image/jpeg',
  25. }
  26. to_test.each do |name, expected|
  27. assert_equal expected, Redmine::MimeType.of(name)
  28. end
  29. end
  30. def test_of_with_unknown_type
  31. assert_nil Redmine::MimeType.of('test.unk')
  32. end
  33. def test_css_class_of
  34. to_test = {
  35. 'test.txt' => 'text-plain',
  36. 'test.c' => 'text-x-c',
  37. 'TEST.JPG' => 'image-jpeg',
  38. }
  39. to_test.each do |name, expected|
  40. assert_equal expected, Redmine::MimeType.css_class_of(name)
  41. end
  42. end
  43. def test_css_class_of_with_unknown_type
  44. assert_nil Redmine::MimeType.css_class_of('test.unk')
  45. end
  46. def test_main_mimetype_of
  47. to_test = {
  48. 'test.txt' => 'text',
  49. 'test.c' => 'text',
  50. 'TEST.JPG' => 'image',
  51. }
  52. to_test.each do |name, expected|
  53. assert_equal expected, Redmine::MimeType.main_mimetype_of(name)
  54. end
  55. end
  56. def test_main_mimetype_of_with_unknown_type
  57. assert_nil Redmine::MimeType.main_mimetype_of('test.unk')
  58. end
  59. def test_is_type
  60. to_test = {
  61. ['text', 'test.unk'] => false,
  62. ['text', 'test.txt'] => true,
  63. ['text', 'test.c'] => true,
  64. ['image', 'TEST.JPG'] => true,
  65. }
  66. to_test.each do |args, expected|
  67. assert_equal expected, Redmine::MimeType.is_type?(*args)
  68. end
  69. end
  70. def test_should_default_to_mime_type_gem
  71. assert !Redmine::MimeType::EXTENSIONS.key?("zip")
  72. assert_equal "application/zip", Redmine::MimeType.of("file.zip")
  73. end
  74. end