Project

General

Profile

Defect #43730 » 0002-add-tests-for-block-level-macro-content.diff

Alexander Meindl, 2026-07-28 18:00

View differences:

w/test/unit/lib/redmine/wiki_formatting/macros_test.rb
end
end
BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE =
%r{<p(?:\s[^>]*)?>(?:(?!</p>).)*<(?:div|h[1-6]|hr|ol|pre|table|ul)[\s/>]}m
def test_macro_returning_block_level_content_should_not_be_wrapped_in_paragraph
text = <<~RAW
{{collapse(Show example, Hide example)
h2. Heading
Some text
}}
RAW
%w[textile common_mark].each do |format|
with_settings :text_formatting => format do
assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable(text)
end
end
end
def test_include_macro_should_not_be_wrapped_in_paragraph
@project = Project.find(1)
%w[textile common_mark].each do |format|
with_settings :text_formatting => format do
assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable('{{include(Another page)}}')
end
end
end
# Example 1 of #43730: text between collapses in the same paragraph
def test_macro_multiple_collapse_with_text_between_should_not_generate_block_inside_p
text = <<~RAW
1 {{collapse(1)
content 1
}}
2 {{collapse(2)
content 2
}}
3 {{collapse(3)
content 3
}}
RAW
with_settings :text_formatting => 'textile' do
assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable(text)
end
end
# Example 2 of #43730: adjacent collapses with no text between
def test_macro_multiple_collapse_adjacent_should_not_generate_block_inside_p
text = <<~RAW
{{collapse(1)
content 1
}}
{{collapse(2)
content 2
}}
RAW
with_settings :text_formatting => 'textile' do
assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable(text)
end
end
# Example 3 of #43730: multiple groups of collapses separated by a blank line
def test_macro_multiple_collapse_groups_should_not_generate_block_inside_p
text = <<~RAW
1 {{collapse(1)
content 1
}}
2 {{collapse(2)
content 2
}}
3 {{collapse(3)
content 3
}}
RAW
with_settings :text_formatting => 'textile' do
assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable(text)
end
end
def test_macro_returning_inline_content_should_keep_its_paragraph
with_settings :text_formatting => 'textile' do
assert_match %r{<p>Some text: <a}, textilizable('Some text: {{issue(1)}}')
end
end
def test_text_without_macro_should_not_be_altered
with_settings :text_formatting => 'textile' do
assert_equal '<p>Some text</p>', textilizable('Some text').strip
end
end
def test_macro_child_pages
expected =
"<p><ul class=\"pages-hierarchy\">\n" \
(14-14/15)