Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

wiki_formatting_test.rb 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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::WikiFormattingTest < ActiveSupport::TestCase
  20. fixtures :issues
  21. def test_textile_formatter
  22. assert_equal Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting.formatter_for('textile')
  23. assert_equal Redmine::WikiFormatting::Textile::Helper, Redmine::WikiFormatting.helper_for('textile')
  24. end
  25. def test_null_formatter
  26. assert_equal Redmine::WikiFormatting::NullFormatter::Formatter, Redmine::WikiFormatting.formatter_for('')
  27. assert_equal Redmine::WikiFormatting::NullFormatter::Helper, Redmine::WikiFormatting.helper_for('')
  28. end
  29. def test_formats_for_select
  30. assert_include ['Textile', 'textile'], Redmine::WikiFormatting.formats_for_select
  31. end
  32. def test_should_link_urls_and_email_addresses
  33. raw = <<~DIFF
  34. This is a sample *text* with a link: http://www.redmine.org
  35. and an email address foo@example.net
  36. DIFF
  37. expected = <<~EXPECTED
  38. <p>This is a sample *text* with a link: <a class="external" href="http://www.redmine.org">http://www.redmine.org</a><br />
  39. and an email address <a class="email" href="mailto:foo@example.net">foo@example.net</a></p>
  40. EXPECTED
  41. assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
  42. end
  43. def test_should_link_email_with_slashes
  44. raw = 'foo/bar@example.net'
  45. expected = '<p><a class="email" href="mailto:foo/bar@example.net">foo/bar@example.net</a></p>'
  46. assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
  47. end
  48. def test_links_separated_with_line_break_should_link
  49. raw = <<~DIFF
  50. link: https://www.redmine.org
  51. http://www.redmine.org
  52. DIFF
  53. expected = <<~EXPECTED
  54. <p>link: <a class="external" href="https://www.redmine.org">https://www.redmine.org</a><br />
  55. <a class="external" href="http://www.redmine.org">http://www.redmine.org</a></p>
  56. EXPECTED
  57. assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
  58. end
  59. def test_supports_section_edit
  60. with_settings :text_formatting => 'textile' do
  61. assert_equal true, Redmine::WikiFormatting.supports_section_edit?
  62. end
  63. with_settings :text_formatting => '' do
  64. assert_equal false, Redmine::WikiFormatting.supports_section_edit?
  65. end
  66. end
  67. def test_hires_images_should_not_be_recognized_as_email_addresses
  68. raw = <<~DIFF
  69. Image: logo@2x.png
  70. DIFF
  71. expected = <<~EXPECTED
  72. <p>Image: logo@2x.png</p>
  73. EXPECTED
  74. assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
  75. end
  76. def test_cache_key_for_saved_object_should_no_be_nil
  77. assert_not_nil Redmine::WikiFormatting.cache_key_for('textile', 'Text', Issue.find(1), :description)
  78. end
  79. end