Chris@1517
|
1 # Redmine - project management software
|
Chris@1517
|
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
|
Chris@1517
|
3 #
|
Chris@1517
|
4 # This program is free software; you can redistribute it and/or
|
Chris@1517
|
5 # modify it under the terms of the GNU General Public License
|
Chris@1517
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@1517
|
7 # of the License, or (at your option) any later version.
|
Chris@1517
|
8 #
|
Chris@1517
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@1517
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@1517
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@1517
|
12 # GNU General Public License for more details.
|
Chris@1517
|
13 #
|
Chris@1517
|
14 # You should have received a copy of the GNU General Public License
|
Chris@1517
|
15 # along with this program; if not, write to the Free Software
|
Chris@1517
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@1517
|
17
|
Chris@1517
|
18 require File.expand_path('../../../../../test_helper', __FILE__)
|
Chris@1517
|
19
|
Chris@1517
|
20 class Redmine::WikiFormatting::MarkdownFormatterTest < ActionView::TestCase
|
Chris@1517
|
21 if Object.const_defined?(:Redcarpet)
|
Chris@1517
|
22
|
Chris@1517
|
23 def setup
|
Chris@1517
|
24 @formatter = Redmine::WikiFormatting::Markdown::Formatter
|
Chris@1517
|
25 end
|
Chris@1517
|
26
|
Chris@1517
|
27 def test_syntax_error_in_image_reference_should_not_raise_exception
|
Chris@1517
|
28 assert @formatter.new("!>[](foo.png)").to_html
|
Chris@1517
|
29 end
|
Chris@1517
|
30
|
Chris@1517
|
31 # re-using the formatter after getting above error crashes the
|
Chris@1517
|
32 # ruby interpreter. This seems to be related to
|
Chris@1517
|
33 # https://github.com/vmg/redcarpet/issues/318
|
Chris@1517
|
34 def test_should_not_crash_redcarpet_after_syntax_error
|
Chris@1517
|
35 @formatter.new("!>[](foo.png)").to_html rescue nil
|
Chris@1517
|
36 assert @formatter.new("").to_html.present?
|
Chris@1517
|
37 end
|
Chris@1517
|
38
|
Chris@1517
|
39 def test_inline_style
|
Chris@1517
|
40 assert_equal "<p><strong>foo</strong></p>", @formatter.new("**foo**").to_html.strip
|
Chris@1517
|
41 end
|
Chris@1517
|
42
|
Chris@1517
|
43 def test_not_set_intra_emphasis
|
Chris@1517
|
44 assert_equal "<p>foo_bar_baz</p>", @formatter.new("foo_bar_baz").to_html.strip
|
Chris@1517
|
45 end
|
Chris@1517
|
46
|
Chris@1517
|
47 def test_wiki_links_should_be_preserved
|
Chris@1517
|
48 text = 'This is a wiki link: [[Foo]]'
|
Chris@1517
|
49 assert_include '[[Foo]]', @formatter.new(text).to_html
|
Chris@1517
|
50 end
|
Chris@1517
|
51
|
Chris@1517
|
52 def test_redmine_links_with_double_quotes_should_be_preserved
|
Chris@1517
|
53 text = 'This is a redmine link: version:"1.0"'
|
Chris@1517
|
54 assert_include 'version:"1.0"', @formatter.new(text).to_html
|
Chris@1517
|
55 end
|
Chris@1517
|
56
|
Chris@1517
|
57 def test_should_support_syntax_highligth
|
Chris@1517
|
58 text = <<-STR
|
Chris@1517
|
59 ~~~ruby
|
Chris@1517
|
60 def foo
|
Chris@1517
|
61 end
|
Chris@1517
|
62 ~~~
|
Chris@1517
|
63 STR
|
Chris@1517
|
64 assert_select_in @formatter.new(text).to_html, 'pre code.ruby.syntaxhl' do
|
Chris@1517
|
65 assert_select 'span.keyword', :text => 'def'
|
Chris@1517
|
66 end
|
Chris@1517
|
67 end
|
Chris@1517
|
68
|
Chris@1517
|
69 def test_external_links_should_have_external_css_class
|
Chris@1517
|
70 text = 'This is a [link](http://example.net/)'
|
Chris@1517
|
71 assert_equal '<p>This is a <a class="external" href="http://example.net/">link</a></p>', @formatter.new(text).to_html.strip
|
Chris@1517
|
72 end
|
Chris@1517
|
73
|
Chris@1517
|
74 def test_locals_links_should_not_have_external_css_class
|
Chris@1517
|
75 text = 'This is a [link](/issues)'
|
Chris@1517
|
76 assert_equal '<p>This is a <a href="/issues">link</a></p>', @formatter.new(text).to_html.strip
|
Chris@1517
|
77 end
|
Chris@1517
|
78
|
Chris@1517
|
79 end
|
Chris@1517
|
80 end
|