From 4807beaebf192dca34ea5661df0de0acb33e2e11 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sat, 22 Jan 2022 10:11:13 +0000 Subject: Explicitly specify text formatting in the tests (#35952). Patch by Go MAEDA. git-svn-id: http://svn.redmine.org/redmine/trunk@21386 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../lib/redmine/field_format/field_format_test.rb | 12 +- .../lib/redmine/wiki_formatting/macros_test.rb | 303 ++++++++++++--------- test/unit/mailer_test.rb | 4 +- 3 files changed, 191 insertions(+), 128 deletions(-) (limited to 'test/unit') diff --git a/test/unit/lib/redmine/field_format/field_format_test.rb b/test/unit/lib/redmine/field_format/field_format_test.rb index 8d8874b36..5bcda2156 100644 --- a/test/unit/lib/redmine/field_format/field_format_test.rb +++ b/test/unit/lib/redmine/field_format/field_format_test.rb @@ -39,8 +39,10 @@ class Redmine::FieldFormatTest < ActionView::TestCase field = IssueCustomField.new(:field_format => 'string', :text_formatting => 'full') custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "*foo*") - assert_equal "*foo*", field.format.formatted_custom_value(self, custom_value, false) - assert_include "foo", field.format.formatted_custom_value(self, custom_value, true) + with_settings :text_formatting => 'textile' do + assert_equal '*foo*', field.format.formatted_custom_value(self, custom_value, false) + assert_include 'foo', field.format.formatted_custom_value(self, custom_value, true) + end end def test_text_field_with_text_formatting_disabled_should_not_format_text @@ -55,8 +57,10 @@ class Redmine::FieldFormatTest < ActionView::TestCase field = IssueCustomField.new(:field_format => 'text', :text_formatting => 'full') custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "*foo*\nbar") - assert_equal "*foo*\nbar", field.format.formatted_custom_value(self, custom_value, false) - assert_include "foo", field.format.formatted_custom_value(self, custom_value, true) + with_settings :text_formatting => 'textile' do + assert_equal "*foo*\nbar", field.format.formatted_custom_value(self, custom_value, false) + assert_include 'foo', field.format.formatted_custom_value(self, custom_value, true) + end end def test_should_validate_url_pattern_with_safe_scheme diff --git a/test/unit/lib/redmine/wiki_formatting/macros_test.rb b/test/unit/lib/redmine/wiki_formatting/macros_test.rb index 39448df31..28be28d47 100644 --- a/test/unit/lib/redmine/wiki_formatting/macros_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/macros_test.rb @@ -50,10 +50,12 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest end end - assert_equal '

Foo: 0 () (Array)

', textilizable("{{foo}}") - assert_equal '

Foo: 0 () (Array)

', textilizable("{{foo()}}") - assert_equal '

Foo: 1 (arg1) (Array)

', textilizable("{{foo(arg1)}}") - assert_equal '

Foo: 2 (arg1,arg2) (Array)

', textilizable("{{foo(arg1, arg2)}}") + with_settings :text_formatting => 'textile' do + assert_equal '

Foo: 0 () (Array)

', textilizable('{{foo}}') + assert_equal '

Foo: 0 () (Array)

', textilizable('{{foo()}}') + assert_equal '

Foo: 1 (arg1) (Array)

', textilizable('{{foo(arg1)}}') + assert_equal '

Foo: 2 (arg1,arg2) (Array)

', textilizable('{{foo(arg1, arg2)}}') + end end def test_macro_registration_parse_args_set_to_false_should_disable_arguments_parsing @@ -63,9 +65,11 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest end end - assert_equal '

Bar: (args, more args) (String)

', textilizable("{{bar(args, more args)}}") - assert_equal '

Bar: () (String)

', textilizable("{{bar}}") - assert_equal '

Bar: () (String)

', textilizable("{{bar()}}") + with_settings :text_formatting => 'textile' do + assert_equal '

Bar: (args, more args) (String)

', textilizable('{{bar(args, more args)}}') + assert_equal '

Bar: () (String)

', textilizable('{{bar}}') + assert_equal '

Bar: () (String)

', textilizable('{{bar()}}') + end end def test_macro_registration_with_3_args_should_receive_text_argument @@ -75,16 +79,19 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest end end - assert_equal "

Baz: () (NilClass) ()

", textilizable("{{baz}}") - assert_equal "

Baz: () (NilClass) ()

", textilizable("{{baz()}}") - assert_equal "

Baz: () (String) (line1\nline2)

", textilizable("{{baz()\nline1\nline2\n}}") - assert_equal "

Baz: (arg1,arg2) (String) (line1\nline2)

", textilizable("{{baz(arg1, arg2)\nline1\nline2\n}}") + with_settings :text_formatting => 'textile' do + assert_equal '

Baz: () (NilClass) ()

', textilizable('{{baz}}') + assert_equal '

Baz: () (NilClass) ()

', textilizable('{{baz()}}') + assert_equal "

Baz: () (String) (line1\nline2)

", textilizable("{{baz()\nline1\nline2\n}}") + assert_equal "

Baz: (arg1,arg2) (String) (line1\nline2)

", textilizable("{{baz(arg1, arg2)\nline1\nline2\n}}") + end end def test_macro_name_with_upper_case - Redmine::WikiFormatting::Macros.macro(:UpperCase) {|obj, args| "Upper"} - - assert_equal "

Upper

", textilizable("{{UpperCase}}") + with_settings :text_formatting => 'textile' do + Redmine::WikiFormatting::Macros.macro(:UpperCase) {|obj, args| 'Upper'} + assert_equal '

Upper

', textilizable('{{UpperCase}}') + end end def test_multiple_macros_on_the_same_line @@ -92,27 +99,33 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest args.any? ? "args: #{args.join(',')}" : "no args" end - assert_equal '

no args no args

', textilizable("{{foo}} {{foo}}") - assert_equal '

args: a,b no args

', textilizable("{{foo(a,b)}} {{foo}}") - assert_equal '

args: a,b args: c,d

', textilizable("{{foo(a,b)}} {{foo(c,d)}}") - assert_equal '

no args args: c,d

', textilizable("{{foo}} {{foo(c,d)}}") + with_settings :text_formatting => 'textile' do + assert_equal '

no args no args

', textilizable('{{foo}} {{foo}}') + assert_equal '

args: a,b no args

', textilizable('{{foo(a,b)}} {{foo}}') + assert_equal '

args: a,b args: c,d

', textilizable('{{foo(a,b)}} {{foo(c,d)}}') + assert_equal '

no args args: c,d

', textilizable('{{foo}} {{foo(c,d)}}') + end end def test_macro_should_receive_the_object_as_argument_when_with_object_and_attribute issue = Issue.find(1) issue.description = "{{hello_world}}" - assert_equal( - '

Hello world! Object: Issue, Called with no argument and no block of text.

', - textilizable(issue, :description) - ) + with_settings :text_formatting => 'textile' do + assert_equal( + '

Hello world! Object: Issue, Called with no argument and no block of text.

', + textilizable(issue, :description) + ) + end end def test_macro_should_receive_the_object_as_argument_when_called_with_object_option - text = "{{hello_world}}" - assert_equal( - '

Hello world! Object: Issue, Called with no argument and no block of text.

', - textilizable(text, :object => Issue.find(1)) - ) + with_settings :text_formatting => 'textile' do + text = '{{hello_world}}' + assert_equal( + '

Hello world! Object: Issue, Called with no argument and no block of text.

', + textilizable(text, :object => Issue.find(1)) + ) + end end def test_extract_macro_options_should_with_args @@ -153,35 +166,47 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest end def test_exclamation_mark_should_not_run_macros - text = "!{{hello_world}}" - assert_equal '

{{hello_world}}

', textilizable(text) + with_settings :text_formatting => 'textile' do + text = '!{{hello_world}}' + assert_equal '

{{hello_world}}

', textilizable(text) + end end def test_exclamation_mark_should_escape_macros - text = "!{{hello_world()}}" - assert_equal '

{{hello_world(<tag>)}}

', textilizable(text) + with_settings :text_formatting => 'textile' do + text = '!{{hello_world()}}' + assert_equal '

{{hello_world(<tag>)}}

', textilizable(text) + end end def test_unknown_macros_should_not_be_replaced - text = "{{unknown}}" - assert_equal '

{{unknown}}

', textilizable(text) + with_settings :text_formatting => 'textile' do + text = '{{unknown}}' + assert_equal '

{{unknown}}

', textilizable(text) + end end def test_unknown_macros_should_parsed_as_text - text = "{{unknown(*test*)}}" - assert_equal '

{{unknown(test)}}

', textilizable(text) + with_settings :text_formatting => 'textile' do + text = '{{unknown(*test*)}}' + assert_equal '

{{unknown(test)}}

', textilizable(text) + end end def test_unknown_macros_should_be_escaped - text = "{{unknown()}}" - assert_equal '

{{unknown(<tag>)}}

', textilizable(text) + with_settings :text_formatting => 'textile' do + text = '{{unknown()}}' + assert_equal '

{{unknown(<tag>)}}

', textilizable(text) + end end def test_html_safe_macro_output_should_not_be_escaped - Redmine::WikiFormatting::Macros.macro :safe_macro do |obj, args| - "".html_safe + with_settings :text_formatting => 'textile' do + Redmine::WikiFormatting::Macros.macro :safe_macro do |obj, args| + ''.html_safe + end + assert_equal '

', textilizable('{{safe_macro}}') end - assert_equal '

', textilizable("{{safe_macro}}") end def test_macro_hello_world @@ -220,33 +245,39 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest def test_macro_collapse text = "{{collapse\n*Collapsed* block of text\n}}" with_locale 'en' do - result = textilizable(text) + with_settings :text_formatting => 'textile' do + result = textilizable(text) - assert_select_in result, 'div.collapsed-text' - assert_select_in result, 'strong', :text => 'Collapsed' - assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Show' - assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Hide' + assert_select_in result, 'div.collapsed-text' + assert_select_in result, 'strong', :text => 'Collapsed' + assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Show' + assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Hide' + end end end def test_macro_collapse_with_one_arg text = "{{collapse(Example)\n*Collapsed* block of text\n}}" - result = textilizable(text) + with_settings :text_formatting => 'textile' do + result = textilizable(text) - assert_select_in result, 'div.collapsed-text' - assert_select_in result, 'strong', :text => 'Collapsed' - assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Example' - assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Example' + assert_select_in result, 'div.collapsed-text' + assert_select_in result, 'strong', :text => 'Collapsed' + assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Example' + assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Example' + end end def test_macro_collapse_with_two_args text = "{{collapse(Show example, Hide example)\n*Collapsed* block of text\n}}" - result = textilizable(text) + with_settings :text_formatting => 'textile' do + result = textilizable(text) - assert_select_in result, 'div.collapsed-text' - assert_select_in result, 'strong', :text => 'Collapsed' - assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Show example' - assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Hide example' + assert_select_in result, 'div.collapsed-text' + assert_select_in result, 'strong', :text => 'Collapsed' + assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Show example' + assert_select_in result, 'a.collapsible.icon-expanded', :text => 'Hide example' + end end def test_macro_collapse_should_not_break_toc @@ -264,7 +295,9 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest expected_toc = '' - assert_include expected_toc, textilizable(text).gsub(/[\r\n]/, '') + with_settings :text_formatting => 'textile' do + assert_include expected_toc, textilizable(text).gsub(/[\r\n]/, '') + end end def test_macro_child_pages @@ -276,13 +309,15 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest "
  • Child 2
  • \n" \ "\n

    " @project = Project.find(1) - # child pages of the current wiki page - assert_equal expected, textilizable("{{child_pages}}", :object => WikiPage.find(2).content) - # child pages of another page - assert_equal expected, textilizable("{{child_pages(Another_page)}}", :object => WikiPage.find(1).content) - - @project = Project.find(2) - assert_equal expected, textilizable("{{child_pages(ecookbook:Another_page)}}", :object => WikiPage.find(1).content) + with_settings :text_formatting => 'textile' do + # child pages of the current wiki page + assert_equal expected, textilizable('{{child_pages}}', :object => WikiPage.find(2).content) + # child pages of another page + assert_equal expected, textilizable('{{child_pages(Another_page)}}', :object => WikiPage.find(1).content) + + @project = Project.find(2) + assert_equal expected, textilizable('{{child_pages(ecookbook:Another_page)}}', :object => WikiPage.find(1).content) + end end def test_macro_child_pages_with_parent_option @@ -297,18 +332,20 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest "\n\n\n

    " @project = Project.find(1) - # child pages of the current wiki page - assert_equal expected, textilizable("{{child_pages(parent=1)}}", :object => WikiPage.find(2).content) - # child pages of another page - assert_equal( - expected, - textilizable("{{child_pages(Another_page, parent=1)}}", :object => WikiPage.find(1).content) - ) - @project = Project.find(2) - assert_equal( - expected, - textilizable("{{child_pages(ecookbook:Another_page, parent=1)}}", :object => WikiPage.find(1).content) - ) + with_settings :text_formatting => 'textile' do + # child pages of the current wiki page + assert_equal expected, textilizable('{{child_pages(parent=1)}}', :object => WikiPage.find(2).content) + # child pages of another page + assert_equal( + expected, + textilizable('{{child_pages(Another_page, parent=1)}}', :object => WikiPage.find(1).content) + ) + @project = Project.find(2) + assert_equal( + expected, + textilizable('{{child_pages(ecookbook:Another_page, parent=1)}}', :object => WikiPage.find(1).content) + ) + end end def test_macro_child_pages_with_depth_option @@ -318,7 +355,9 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest "
  • Child 2
  • \n" \ "\n

    " @project = Project.find(1) - assert_equal expected, textilizable("{{child_pages(depth=1)}}", :object => WikiPage.find(2).content) + with_settings :text_formatting => 'textile' do + assert_equal expected, textilizable("{{child_pages(depth=1)}}", :object => WikiPage.find(2).content) + end end def test_macro_child_pages_without_wiki_page_should_fail @@ -326,39 +365,47 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest end def test_macro_thumbnail - link = link_to('testfile.PNG'.html_safe, - "/attachments/17", - :class => "thumbnail", - :title => "testfile.PNG") - assert_equal "

    #{link}

    ", - textilizable("{{thumbnail(testfile.png)}}", :object => Issue.find(14)) + with_settings :text_formatting => 'textile' do + link = link_to('testfile.PNG'.html_safe, + '/attachments/17', + :class => 'thumbnail', + :title => 'testfile.PNG') + assert_equal "

    #{link}

    ", + textilizable('{{thumbnail(testfile.png)}}', :object => Issue.find(14)) + end end def test_macro_thumbnail_with_full_path - link = link_to('testfile.PNG'.html_safe, - "http://test.host/attachments/17", - :class => "thumbnail", - :title => "testfile.PNG") - assert_equal "

    #{link}

    ", - textilizable("{{thumbnail(testfile.png)}}", :object => Issue.find(14), :only_path => false) + with_settings :text_formatting => 'textile' do + link = link_to('testfile.PNG'.html_safe, + 'http://test.host/attachments/17', + :class => 'thumbnail', + :title => 'testfile.PNG') + assert_equal "

    #{link}

    ", + textilizable('{{thumbnail(testfile.png)}}', :object => Issue.find(14), :only_path => false) + end end def test_macro_thumbnail_with_size - link = link_to('testfile.PNG'.html_safe, - "/attachments/17", - :class => "thumbnail", - :title => "testfile.PNG") - assert_equal "

    #{link}

    ", - textilizable("{{thumbnail(testfile.png, size=400)}}", :object => Issue.find(14)) + with_settings :text_formatting => 'textile' do + link = link_to('testfile.PNG'.html_safe, + '/attachments/17', + :class => 'thumbnail', + :title => 'testfile.PNG') + assert_equal "

    #{link}

    ", + textilizable('{{thumbnail(testfile.png, size=400)}}', :object => Issue.find(14)) + end end def test_macro_thumbnail_with_title - link = link_to('testfile.PNG'.html_safe, - "/attachments/17", - :class => "thumbnail", - :title => "Cool image") - assert_equal "

    #{link}

    ", - textilizable("{{thumbnail(testfile.png, title=Cool image)}}", :object => Issue.find(14)) + with_settings :text_formatting => 'textile' do + link = link_to('testfile.PNG'.html_safe, + '/attachments/17', + :class => 'thumbnail', + :title => 'Cool image') + assert_equal "

    #{link}

    ", + textilizable('{{thumbnail(testfile.png, title=Cool image)}}', :object => Issue.find(14)) + end end def test_macro_thumbnail_with_invalid_filename_should_fail @@ -387,20 +434,26 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest

    Hello world! Object: NilClass, Arguments: bar and no block of text.

    EXPECTED - assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(text).gsub(%r{[\r\n\t]}, '') + with_settings :text_formatting => 'textile' do + assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(text).gsub(%r{[\r\n\t]}, '') + end end def test_macros_should_be_escaped_in_pre_tags - text = "
    {{hello_world()}}
    " - assert_equal "
    {{hello_world(<tag>)}}
    ", textilizable(text) + with_settings :text_formatting => 'textile' do + text = '
    {{hello_world()}}
    ' + assert_equal '
    {{hello_world(<tag>)}}
    ', textilizable(text) + end end def test_macros_should_not_mangle_next_macros_outputs - text = '{{macro(2)}} !{{macro(2)}} {{hello_world(foo)}}' - assert_equal( - '

    {{macro(2)}} {{macro(2)}} Hello world! Object: NilClass, Arguments: foo and no block of text.

    ', - textilizable(text) - ) + with_settings :text_formatting => 'textile' do + text = '{{macro(2)}} !{{macro(2)}} {{hello_world(foo)}}' + assert_equal( + '

    {{macro(2)}} {{macro(2)}} Hello world! Object: NilClass, Arguments: foo and no block of text.

    ', + textilizable(text) + ) + end end def test_macros_with_text_should_not_mangle_following_macros @@ -421,26 +474,32 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest end def test_macro_should_support_phrase_modifiers - text = "*{{hello_world}}*" - assert_match %r|\A

    Hello world!.*

    \z|, textilizable(text) + with_settings :text_formatting => 'textile' do + text = '*{{hello_world}}*' + assert_match %r|\A

    Hello world!.*

    \z|, textilizable(text) + end end def test_issue_macro_should_not_render_link_if_not_visible - assert_equal "

    #123

    ", textilizable('{{issue(123)}}') + with_settings :text_formatting => 'textile' do + assert_equal '

    #123

    ', textilizable('{{issue(123)}}') + end end def test_issue_macro_should_render_link_to_issue issue = Issue.find(1) - assert_equal( - %{

    Bug #1: #{issue.subject}

    }, - textilizable("{{issue(1)}}") - ) - assert_equal( - %{

    eCookbook - } + - %{Bug #1: #{issue.subject}

    }, - textilizable("{{issue(1, project=true)}}") - ) + with_settings :text_formatting => 'textile' do + assert_equal( + %{

    Bug #1: #{issue.subject}

    }, + textilizable('{{issue(1)}}') + ) + assert_equal( + %{

    eCookbook - } + + %{Bug #1: #{issue.subject}

    }, + textilizable('{{issue(1, project=true)}}') + ) + end end end diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index 4e75ef874..7ee682c06 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -997,7 +997,7 @@ class MailerTest < ActiveSupport::TestCase end def test_layout_should_include_the_emails_header - with_settings :emails_header => "*Header content*" do + with_settings :emails_header => '*Header content*', :text_formatting => 'textile' do with_settings :plain_text_mail => 0 do assert Mailer.test_email(User.find(1)).deliver_now assert_select_email do @@ -1024,7 +1024,7 @@ class MailerTest < ActiveSupport::TestCase end def test_layout_should_include_the_emails_footer - with_settings :emails_footer => "*Footer content*" do + with_settings :emails_footer => '*Footer content*', :text_formatting => 'textile' do with_settings :plain_text_mail => 0 do assert Mailer.test_email(User.find(1)).deliver_now assert_select_email do -- cgit v1.2.3