Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

wiki_formatting_test.rb 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../../../test_helper', __FILE__)
  18. class Redmine::WikiFormattingTest < ActiveSupport::TestCase
  19. fixtures :issues
  20. def test_textile_formatter
  21. assert_equal Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting.formatter_for('textile')
  22. assert_equal Redmine::WikiFormatting::Textile::Helper, Redmine::WikiFormatting.helper_for('textile')
  23. end
  24. def test_null_formatter
  25. assert_equal Redmine::WikiFormatting::NullFormatter::Formatter, Redmine::WikiFormatting.formatter_for('')
  26. assert_equal Redmine::WikiFormatting::NullFormatter::Helper, Redmine::WikiFormatting.helper_for('')
  27. end
  28. def test_formats_for_select
  29. assert_include ['Textile', 'textile'], Redmine::WikiFormatting.formats_for_select
  30. end
  31. def test_should_link_urls_and_email_addresses
  32. raw = <<-DIFF
  33. This is a sample *text* with a link: http://www.redmine.org
  34. and an email address foo@example.net
  35. DIFF
  36. expected = <<-EXPECTED
  37. <p>This is a sample *text* with a link: <a class="external" href="http://www.redmine.org">http://www.redmine.org</a><br />
  38. and an email address <a class="email" href="mailto:foo@example.net">foo@example.net</a></p>
  39. EXPECTED
  40. assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
  41. end
  42. def test_should_link_email_with_slashes
  43. raw = 'foo/bar@example.net'
  44. expected = '<p><a class="email" href="mailto:foo/bar@example.net">foo/bar@example.net</a></p>'
  45. assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
  46. end
  47. def test_links_separated_with_line_break_should_link
  48. raw = <<-DIFF
  49. link: https://www.redmine.org
  50. http://www.redmine.org
  51. DIFF
  52. expected = <<-EXPECTED
  53. <p>link: <a class="external" href="https://www.redmine.org">https://www.redmine.org</a><br />
  54. <a class="external" href="http://www.redmine.org">http://www.redmine.org</a></p>
  55. EXPECTED
  56. end
  57. def test_supports_section_edit
  58. with_settings :text_formatting => 'textile' do
  59. assert_equal true, Redmine::WikiFormatting.supports_section_edit?
  60. end
  61. with_settings :text_formatting => '' do
  62. assert_equal false, Redmine::WikiFormatting.supports_section_edit?
  63. end
  64. end
  65. def test_hires_images_should_not_be_recognized_as_email_addresses
  66. raw = <<-DIFF
  67. Image: logo@2x.png
  68. DIFF
  69. expected = <<-EXPECTED
  70. <p>Image: logo@2x.png</p>
  71. EXPECTED
  72. assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
  73. end
  74. def test_cache_key_for_saved_object_should_no_be_nil
  75. assert_not_nil Redmine::WikiFormatting.cache_key_for('textile', 'Text', Issue.find(1), :description)
  76. end
  77. end