# frozen_string_literal: true # Redmine - project management software # Copyright (C) 2006- Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. require_relative '../../../../../test_helper' class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase if Object.const_defined?(:Commonmarker) def setup @formatter = Redmine::WikiFormatting::CommonMark::Formatter end def to_html(text) @formatter.new(text).to_html end def test_should_render_hard_breaks html ="
foo
\nbar
foo
\nbar
foo
", to_html("**foo**") end def test_not_set_intra_emphasis assert_equal "foo_bar_baz
", to_html("foo_bar_baz") end def test_wiki_links_should_be_preserved text = 'This is a wiki link: [[Foo]]' assert_include '[[Foo]]', to_html(text) end def test_redmine_links_with_double_quotes_should_be_preserved text = 'This is a redmine link: version:"1.0"' assert_include 'version:"1.0"', to_html(text) end def test_links_by_id_should_be_preserved text = "[project#3]" assert_equal "#{text}
", to_html(text) end def test_links_to_users_should_be_preserved text = "[@login]" assert_equal "#{text}
", to_html(text) text = "[user:login]" assert_equal "#{text}
", to_html(text) text = "user:user@example.org" assert_equal "#{text}
", to_html(text) text = "[user:user@example.org]" assert_equal "#{text}
", to_html(text) text = "@user@example.org" assert_equal "#{text}
", to_html(text) text = "[@user@example.org]" assert_equal "#{text}
", to_html(text) end def test_files_with_at_should_not_end_up_as_mailto_links text = "printscreen@2x.png" assert_equal "#{text}
", to_html(text) text = "[printscreen@2x.png]" assert_equal "#{text}
", to_html(text) end def test_should_support_syntax_highlight text = <<~STR ~~~ruby def foo end ~~~ STR assert_select_in to_html(text), 'pre code.ruby.syntaxhl' do assert_select 'span.k', :text => 'def' assert_select "[data-language='ruby']" end end def test_should_support_syntax_highlight_for_language_with_special_chars text = <<~STR ~~~c++ int main() { } ~~~ STR assert_select_in to_html(text), 'pre' do assert_select 'code[class=?]', "c++ syntaxhl" assert_select 'span.kt', :text => 'int' assert_select "[data-language=?]", "c++" end end def test_external_links_should_have_external_css_class text = 'This is a [link](http://example.net/)' assert_equal 'This is a link
', to_html(text) end def test_locals_links_should_not_have_external_css_class text = 'This is a [link](/issues)' assert_equal 'This is a link
', to_html(text) end def test_markdown_should_not_require_surrounded_empty_line text = <<-STR This is a list: * One * Two STR assert_equal "This is a list:
\nThis is some text1.
This is the foot note ↩
This text should be emphasized
', to_html(text) end def test_should_strike_through_text text = 'This ~~text~~ should be striked through' assert_equal 'This text should be striked through
http://www.redmine.org/projects/redmine/issues?utf8=✓
'], ['[Letters](https://yandex.ru/search/?text=кол-во)', ''], ["www.example.org", ''], ["user@example.org", ''] ].each do |text, html| assert_equal html, to_html(text) end end def test_should_support_html_tables text = 'Cell |
Cell |
sit
amet <style>.foo { color: #fff; }</style> <script>alert("hello world");</script>
Task list:
#{alert.capitalize}
\nThis is a #{alert}.
\n", html assert_include "[!unknown]", html assert_include "This should not become an alert.", html assert_not_include 'markdown-alert', html end private def assert_section_with_hash(expected, text, index) result = @formatter.new(text).get_section(index) assert_kind_of Array, result assert_equal 2, result.size assert_equal expected, result.first, "section content did not match" assert_equal ActiveSupport::Digest.hexdigest(expected), result.last, "section hash did not match" end end end