Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

html_parser_test.rb 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 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::WikiFormatting::HtmlParserTest < ActiveSupport::TestCase
  20. def setup
  21. @parser = Redmine::WikiFormatting::HtmlParser
  22. end
  23. def test_convert_line_breaks
  24. assert_equal "A html snippet with\na new line.",
  25. @parser.to_text('<p>A html snippet with<br>a new line.</p>')
  26. end
  27. def test_should_remove_style_tags_from_body
  28. assert_equal "Text",
  29. @parser.to_text('<html><body><style>body {font-size: 0.8em;}</style>Text</body></html>')
  30. end
  31. def test_should_remove_preceding_whitespaces
  32. to_test = {
  33. "<div> blocks with</div>\n<p>\n preceding whitespaces\n</p>" => "blocks with\n\npreceding whitespaces",
  34. "<div>blocks without</div>\n<p>\npreceding whitespaces\n</p>" => "blocks without\n\npreceding whitespaces",
  35. "<span> span with</span>\n<span> preceding whitespaces</span>" => "span with preceding whitespaces",
  36. "<span>span without</span>\n<span>preceding whitespaces</span>" => "span without preceding whitespaces"
  37. }
  38. to_test.each do |html, expected|
  39. assert_equal expected, @parser.to_text(html)
  40. end
  41. end
  42. end