Chris@1517: # Redmine - project management software Chris@1517: # Copyright (C) 2006-2014 Jean-Philippe Lang Chris@1517: # Chris@1517: # This program is free software; you can redistribute it and/or Chris@1517: # modify it under the terms of the GNU General Public License Chris@1517: # as published by the Free Software Foundation; either version 2 Chris@1517: # of the License, or (at your option) any later version. Chris@1517: # Chris@1517: # This program is distributed in the hope that it will be useful, Chris@1517: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1517: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1517: # GNU General Public License for more details. Chris@1517: # Chris@1517: # You should have received a copy of the GNU General Public License Chris@1517: # along with this program; if not, write to the Free Software Chris@1517: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1517: Chris@1517: require File.expand_path('../../../../../test_helper', __FILE__) Chris@1517: Chris@1517: class Redmine::WikiFormatting::MarkdownFormatterTest < ActionView::TestCase Chris@1517: if Object.const_defined?(:Redcarpet) Chris@1517: Chris@1517: def setup Chris@1517: @formatter = Redmine::WikiFormatting::Markdown::Formatter Chris@1517: end Chris@1517: Chris@1517: def test_syntax_error_in_image_reference_should_not_raise_exception Chris@1517: assert @formatter.new("!>[](foo.png)").to_html Chris@1517: end Chris@1517: Chris@1517: # re-using the formatter after getting above error crashes the Chris@1517: # ruby interpreter. This seems to be related to Chris@1517: # https://github.com/vmg/redcarpet/issues/318 Chris@1517: def test_should_not_crash_redcarpet_after_syntax_error Chris@1517: @formatter.new("!>[](foo.png)").to_html rescue nil Chris@1517: assert @formatter.new("").to_html.present? Chris@1517: end Chris@1517: Chris@1517: def test_inline_style Chris@1517: assert_equal "
foo
", @formatter.new("**foo**").to_html.strip Chris@1517: end Chris@1517: Chris@1517: def test_not_set_intra_emphasis Chris@1517: assert_equal "foo_bar_baz
", @formatter.new("foo_bar_baz").to_html.strip Chris@1517: end Chris@1517: Chris@1517: def test_wiki_links_should_be_preserved Chris@1517: text = 'This is a wiki link: [[Foo]]' Chris@1517: assert_include '[[Foo]]', @formatter.new(text).to_html Chris@1517: end Chris@1517: Chris@1517: def test_redmine_links_with_double_quotes_should_be_preserved Chris@1517: text = 'This is a redmine link: version:"1.0"' Chris@1517: assert_include 'version:"1.0"', @formatter.new(text).to_html Chris@1517: end Chris@1517: Chris@1517: def test_should_support_syntax_highligth Chris@1517: text = <<-STR Chris@1517: ~~~ruby Chris@1517: def foo Chris@1517: end Chris@1517: ~~~ Chris@1517: STR Chris@1517: assert_select_in @formatter.new(text).to_html, 'pre code.ruby.syntaxhl' do Chris@1517: assert_select 'span.keyword', :text => 'def' Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_external_links_should_have_external_css_class Chris@1517: text = 'This is a [link](http://example.net/)' Chris@1517: assert_equal 'This is a link
', @formatter.new(text).to_html.strip Chris@1517: end Chris@1517: Chris@1517: def test_locals_links_should_not_have_external_css_class Chris@1517: text = 'This is a [link](/issues)' Chris@1517: assert_equal 'This is a link
', @formatter.new(text).to_html.strip Chris@1517: end Chris@1517: Chris@1517: end Chris@1517: end