summaryrefslogtreecommitdiffstats
path: root/test/unit/lib/redmine/wiki_formatting
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/lib/redmine/wiki_formatting')
-rw-r--r--test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb57
-rw-r--r--test/unit/lib/redmine/wiki_formatting/common_mark/sanitization_filter_test.rb38
2 files changed, 82 insertions, 13 deletions
diff --git a/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb b/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb
index 79581a928..d9a84a2c2 100644
--- a/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb
+++ b/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb
@@ -163,39 +163,39 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase
# 0
<<~STR.chomp,
# Title
-
+
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
STR
# 1
<<~STR.chomp,
## Heading 2
-
+
~~~ruby
def foo
end
~~~
-
+
Morbi facilisis accumsan orci non pharetra.
-
+
~~~ ruby
def foo
end
~~~
-
+
```
Pre Content:
-
+
## Inside pre
-
+
<tag> inside pre block
-
+
Morbi facilisis accumsan orci non pharetra.
```
STR
# 2
<<~STR.chomp,
### Heading 3
-
+
Nulla nunc nisi, egestas in ornare vel, posuere ac libero.
STR
]
@@ -299,6 +299,45 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase
assert_equal expected.gsub(%r{[\r\n\t]}, ''), to_html(text).gsub(%r{[\r\n\t]}, '').rstrip
end
+ def test_should_render_alert_blocks
+ text = <<~MD
+ > [!note]
+ > This is a note.
+
+ > [!tip]
+ > This is a tip.
+
+ > [!warning]
+ > This is a warning.
+
+ > [!caution]
+ > This is a caution.
+
+ > [!important]
+ > This is a important.
+ MD
+
+ html = to_html(text)
+ %w[note tip warning caution important].each do |alert|
+ assert_include "<div class=\"markdown-alert markdown-alert-note\">\n<p class=\"markdown-alert-title\">Note</p>\n<p>This is a note.</p>\n</div>", html
+ end
+ end
+
+ def test_should_not_render_unknown_alert_type
+ text = <<~MD
+ > [!unknown]
+ > This should not become an alert.
+ MD
+
+ html = to_html(text)
+
+ assert_include "<blockquote>", 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)
diff --git a/test/unit/lib/redmine/wiki_formatting/common_mark/sanitization_filter_test.rb b/test/unit/lib/redmine/wiki_formatting/common_mark/sanitization_filter_test.rb
index 4c0282f2d..b2d19eab9 100644
--- a/test/unit/lib/redmine/wiki_formatting/common_mark/sanitization_filter_test.rb
+++ b/test/unit/lib/redmine/wiki_formatting/common_mark/sanitization_filter_test.rb
@@ -47,10 +47,14 @@ if Object.const_defined?(:Commonmarker)
end
def test_should_support_footnotes
- input = %(<a href="#fn-1" id="fnref-1">foo</a>)
- assert_equal input, filter(input)
- input = %(<ol><li id="fn-1">footnote</li></ol>)
- assert_equal input, filter(input)
+ [
+ %(<a href="#fn-1" id="fnref-1">foo</a>),
+ %(<a href="#fn-1" id="fnref-1-2">foo</a>),
+ %(<ol><li id="fn-1">footnote</li></ol>),
+ ].each do |input|
+ assert_equal input, filter(input)
+ assert_equal input, filter(input)
+ end
end
def test_should_remove_invalid_ids
@@ -71,6 +75,32 @@ if Object.const_defined?(:Commonmarker)
assert_equal %(<code>foo</code>), filter(input)
end
+ def test_should_allow_valid_alert_div_and_p_classes
+ html = <<~HTML
+ <div class="markdown-alert markdown-alert-tip">
+ <p class="markdown-alert-title">Tip</p>
+ <p>Useful tip.</p>
+ </div>
+ HTML
+
+ sanitized = filter(html)
+
+ assert_include 'class="markdown-alert markdown-alert-tip"', sanitized
+ assert_include 'class="markdown-alert-title"', sanitized
+ end
+
+ def test_should_remove_invalid_div_class
+ html = '<div class="bad-class">Text</div>'
+ sanitized = filter(html)
+ assert_not_includes 'bad-class', sanitized
+ end
+
+ def test_should_remove_invalid_p_class
+ html = '<p class="bad-class">Text</p>'
+ sanitized = filter(html)
+ assert_not_include 'bad-class', sanitized
+ end
+
def test_should_allow_links_with_safe_url_schemes
%w(http https ftp ssh foo).each do |scheme|
input = %(<a href="#{scheme}://example.org/">foo</a>)