diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 434775e59..58c51559a 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -1701,31 +1701,33 @@ class IssuesControllerTest < Redmine::ControllerTest end def test_index_with_last_notes_column - get( - :index, - :params => { - :set_filter => 1, - :c => %w(subject last_notes) - } - ) - assert_response :success - assert_select 'table.issues thead th', 4 # columns: chekbox + id + subject + with_settings :text_formatting => 'textile' do + get( + :index, + :params => { + :set_filter => 1, + :c => %w(subject last_notes) + } + ) + assert_response :success + assert_select 'table.issues thead th', 4 # columns: chekbox + id + subject - assert_select 'td.last_notes[colspan="4"]', :text => 'Some notes with Redmine links: #2, r2.' - assert_select( - 'td.last_notes[colspan="4"]', - :text => 'A comment with inline image: and a reference to #1 and r2.' - ) - get( - :index, - :params => { - :set_filter => 1, - :c => %w(subject last_notes), - :format => 'pdf' - } - ) - assert_response :success - assert_equal 'application/pdf', response.media_type + assert_select 'td.last_notes[colspan="4"]', :text => 'Some notes with Redmine links: #2, r2.' + assert_select( + 'td.last_notes[colspan="4"]', + :text => 'A comment with inline image: and a reference to #1 and r2.' + ) + get( + :index, + :params => { + :set_filter => 1, + :c => %w(subject last_notes), + :format => 'pdf' + } + ) + assert_response :success + assert_equal 'application/pdf', response.media_type + end end def test_index_with_last_notes_column_should_display_private_notes_with_permission_only @@ -2876,20 +2878,22 @@ class IssuesControllerTest < Redmine::ControllerTest end def test_show_atom - get( - :show, - :params => { - :id => 2, - :format => 'atom' - } - ) - assert_response :success - assert_equal 'application/atom+xml', response.media_type - # Inline image - assert_select( - 'content', - :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) - ) + with_settings :text_formatting => 'textile' do + get( + :show, + :params => { + :id => 2, + :format => 'atom' + } + ) + assert_response :success + assert_equal 'application/atom+xml', response.media_type + # Inline image + assert_select( + 'content', + :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) + ) + end end def test_show_export_to_pdf diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index a26793a20..92491dc98 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -96,26 +96,28 @@ class ProjectsControllerTest < Redmine::ControllerTest end def test_index_as_list_should_format_column_value - get :index, :params => { - :c => ['name', 'status', 'short_description', 'homepage', 'parent_id', 'identifier', 'is_public', 'created_on', 'cf_3'], - :display_type => 'list' - } - assert_response :success + with_settings :text_formatting => 'textile' do + get :index, :params => { + :c => ['name', 'status', 'short_description', 'homepage', 'parent_id', 'identifier', 'is_public', 'created_on', 'cf_3'], + :display_type => 'list' + } + assert_response :success - project = Project.find(1) - assert_select 'table.projects' do - assert_select 'tr[id=?]', 'project-1' do - assert_select 'td.name a[href=?]', '/projects/ecookbook', :text => 'eCookbook' - assert_select 'td.status', :text => 'active' - assert_select 'td.short_description', :text => 'Recipes management application' - assert_select 'td.homepage a.external', :text => 'http://ecookbook.somenet.foo/' - assert_select 'td.identifier', :text => 'ecookbook' - assert_select 'td.is_public', :text => 'Yes' - assert_select 'td.created_on', :text => format_time(project.created_on) - assert_select 'td.cf_3.list', :text => 'Stable' - end - assert_select 'tr[id=?]', 'project-4' do - assert_select 'td.parent_id a[href=?]', '/projects/ecookbook', :text => 'eCookbook' + project = Project.find(1) + assert_select 'table.projects' do + assert_select 'tr[id=?]', 'project-1' do + assert_select 'td.name a[href=?]', '/projects/ecookbook', :text => 'eCookbook' + assert_select 'td.status', :text => 'active' + assert_select 'td.short_description', :text => 'Recipes management application' + assert_select 'td.homepage a.external', :text => 'http://ecookbook.somenet.foo/' + assert_select 'td.identifier', :text => 'ecookbook' + assert_select 'td.is_public', :text => 'Yes' + assert_select 'td.created_on', :text => format_time(project.created_on) + assert_select 'td.cf_3.list', :text => 'Stable' + end + assert_select 'tr[id=?]', 'project-4' do + assert_select 'td.parent_id a[href=?]', '/projects/ecookbook', :text => 'eCookbook' + end end end end diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 0ac5ff248..588896134 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -30,13 +30,15 @@ class WikiControllerTest < Redmine::ControllerTest end def test_show_start_page - get :show, :params => {:project_id => 'ecookbook'} - assert_response :success + with_settings :text_formatting => 'textile' do + get :show, :params => {:project_id => 'ecookbook'} + assert_response :success - assert_select 'h1', :text => /CookBook documentation/ - # child_pages macro - assert_select 'ul.pages-hierarchy>li>a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', - :text => 'Page with an inline image' + assert_select 'h1', :text => /CookBook documentation/ + # child_pages macro + assert_select 'ul.pages-hierarchy>li>a[href=?]', '/projects/ecookbook/wiki/Page_with_an_inline_image', + :text => 'Page with an inline image' + end end def test_export_link @@ -55,13 +57,15 @@ class WikiControllerTest < Redmine::ControllerTest end def test_show_page_with_name - get :show, :params => {:project_id => 1, :id => 'Another_page'} - assert_response :success + with_settings :text_formatting => 'textile' do + get :show, :params => {:project_id => 1, :id => 'Another_page'} + assert_response :success - assert_select 'h1', :text => /Another page/ - # Included page with an inline image - assert_select 'p', :text => /This is an inline image/ - assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo' + assert_select 'h1', :text => /Another page/ + # Included page with an inline image + assert_select 'p', :text => /This is an inline image/ + assert_select 'img[src=?][alt=?]', '/attachments/download/3/logo.gif', 'This is a logo' + end end def test_show_old_version @@ -147,19 +151,23 @@ class WikiControllerTest < Redmine::ControllerTest end def test_show_should_display_section_edit_links - @request.session[:user_id] = 2 - get :show, :params => {:project_id => 1, :id => 'Page with sections'} + with_settings :text_formatting => 'textile' do + @request.session[:user_id] = 2 + get :show, :params => {:project_id => 1, :id => 'Page with sections'} - assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0 - assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' - assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3' + assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=1', 0 + assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' + assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=3' + end end def test_show_current_version_should_display_section_edit_links - @request.session[:user_id] = 2 - get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 3} + with_settings :text_formatting => 'textile' do + @request.session[:user_id] = 2 + get :show, :params => {:project_id => 1, :id => 'Page with sections', :version => 3} - assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' + assert_select 'a[href=?]', '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' + end end def test_show_old_version_should_not_display_section_edit_links @@ -353,17 +361,19 @@ class WikiControllerTest < Redmine::ControllerTest end def test_edit_section - @request.session[:user_id] = 2 - get :edit, :params => {:project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2} + with_settings :text_formatting => 'textile' do + @request.session[:user_id] = 2 + get :edit, :params => {:project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2} - assert_response :success + assert_response :success - page = WikiPage.find_by_title('Page_with_sections') - section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) + page = WikiPage.find_by_title('Page_with_sections') + section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) - assert_select 'textarea[name=?]', 'content[text]', :text => section - assert_select 'input[name=section][type=hidden][value="2"]' - assert_select 'input[name=section_hash][type=hidden][value=?]', hash + assert_select 'textarea[name=?]', 'content[text]', :text => section + assert_select 'input[name=section][type=hidden][value="2"]' + assert_select 'input[name=section_hash][type=hidden][value=?]', hash + end end def test_edit_invalid_section_should_respond_with_404 @@ -589,57 +599,61 @@ class WikiControllerTest < Redmine::ControllerTest end def test_update_section - @request.session[:user_id] = 2 - page = WikiPage.find_by_title('Page_with_sections') - section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) - text = page.content.text - - assert_no_difference 'WikiPage.count' do - assert_no_difference 'WikiContent.count' do - assert_difference 'WikiContentVersion.count' do - put :update, :params => { - :project_id => 1, - :id => 'Page_with_sections', - :content => { - :text => "New section content", - :version => 3 - }, - :section => 2, - :section_hash => hash - } + with_settings :text_formatting => 'textile' do + @request.session[:user_id] = 2 + page = WikiPage.find_by(title: 'Page_with_sections') + section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) + text = page.content.text + + assert_no_difference 'WikiPage.count' do + assert_no_difference 'WikiContent.count' do + assert_difference 'WikiContentVersion.count' do + put :update, :params => { + :project_id => 1, + :id => 'Page_with_sections', + :content => { + :text => 'New section content', + :version => 3 + }, + :section => 2, + :section_hash => hash + } + end end end + assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2' + assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, 'New section content'), page.reload.content.text end - assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2' - assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text end def test_update_section_should_allow_stale_page_update - @request.session[:user_id] = 2 - page = WikiPage.find_by_title('Page_with_sections') - section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) - text = page.content.text - - assert_no_difference 'WikiPage.count' do - assert_no_difference 'WikiContent.count' do - assert_difference 'WikiContentVersion.count' do - put :update, :params => { - :project_id => 1, - :id => 'Page_with_sections', - :content => { - :text => "New section content", - :version => 2 # Current version is 3 - }, - :section => 2, - :section_hash => hash - } + with_settings :text_formatting => 'textile' do + @request.session[:user_id] = 2 + page = WikiPage.find_by(title: 'Page_with_sections') + section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2) + text = page.content.text + + assert_no_difference 'WikiPage.count' do + assert_no_difference 'WikiContent.count' do + assert_difference 'WikiContentVersion.count' do + put :update, :params => { + :project_id => 1, + :id => 'Page_with_sections', + :content => { + :text => 'New section content', + :version => 2 # Current version is 3 + }, + :section => 2, + :section_hash => hash + } + end end end + assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2' + page.reload + assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, 'New section content'), page.content.text + assert_equal 4, page.content.version end - assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections#section-2' - page.reload - assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text - assert_equal 4, page.content.version end def test_update_section_should_not_allow_stale_section_update @@ -669,33 +683,37 @@ class WikiControllerTest < Redmine::ControllerTest end def test_preview - @request.session[:user_id] = 2 - post :preview, :params => { - :project_id => 1, - :id => 'CookBook_documentation', - :content => { - :comments => '', - :text => 'this is a *previewed text*', - :version => 3 - } - }, :xhr => true - assert_response :success - assert_select 'strong', :text => /previewed text/ + with_settings :text_formatting => 'textile' do + @request.session[:user_id] = 2 + post :preview, :params => { + :project_id => 1, + :id => 'CookBook_documentation', + :content => { + :comments => '', + :text => 'this is a *previewed text*', + :version => 3 + } + }, :xhr => true + assert_response :success + assert_select 'strong', :text => /previewed text/ + end end def test_preview_new_page - @request.session[:user_id] = 2 - post :preview, :params => { - :project_id => 1, - :id => 'New page', - :content => { - :text => 'h1. New page', - :comments => '', - :version => 0 - } - }, :xhr => true - assert_response :success - assert_select 'h1', :text => /New page/ + with_settings :text_formatting => 'textile' do + @request.session[:user_id] = 2 + post :preview, :params => { + :project_id => 1, + :id => 'New page', + :content => { + :text => 'h1. New page', + :comments => '', + :version => 0 + } + }, :xhr => true + assert_response :success + assert_select 'h1', :text => /New page/ + end end def test_history @@ -1134,25 +1152,29 @@ class WikiControllerTest < Redmine::ControllerTest end def test_show_html - @request.session[:user_id] = 2 - get :show, :params => {:project_id => 1, :format => 'html'} - assert_response :success + with_settings :text_formatting => 'textile' do + @request.session[:user_id] = 2 + get :show, :params => {:project_id => 1, :format => 'html'} + assert_response :success - assert_equal 'text/html', @response.media_type - assert_equal "attachment; filename=\"CookBook_documentation.html\"; filename*=UTF-8''CookBook_documentation.html", - @response.headers['Content-Disposition'] - assert_select 'h1', :text => /CookBook documentation/ + assert_equal 'text/html', @response.media_type + assert_equal "attachment; filename=\"CookBook_documentation.html\"; filename*=UTF-8''CookBook_documentation.html", + @response.headers['Content-Disposition'] + assert_select 'h1', :text => /CookBook documentation/ + end end def test_show_versioned_html - @request.session[:user_id] = 2 - get :show, :params => {:project_id => 1, :format => 'html', :version => 2} - assert_response :success + with_settings :text_formatting => 'textile' do + @request.session[:user_id] = 2 + get :show, :params => {:project_id => 1, :format => 'html', :version => 2} + assert_response :success - assert_equal 'text/html', @response.media_type - assert_equal "attachment; filename=\"CookBook_documentation.html\"; filename*=UTF-8''CookBook_documentation.html", - @response.headers['Content-Disposition'] - assert_select 'h1', :text => /CookBook documentation v2/ + assert_equal 'text/html', @response.media_type + assert_equal "attachment; filename=\"CookBook_documentation.html\"; filename*=UTF-8''CookBook_documentation.html", + @response.headers['Content-Disposition'] + assert_select 'h1', :text => /CookBook documentation v2/ + end end def test_show_txt diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index f67a615e5..defb68bf9 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -115,7 +115,9 @@ class ApplicationHelperTest < Redmine::HelperTest 'http://www.redmine.org/example-' => 'http://www.redmine.org/example-', } - to_test.each {|text, result| assert_equal "
#{result}
", textilizable(text)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + end end def test_auto_links_with_non_ascii_characters @@ -123,7 +125,9 @@ class ApplicationHelperTest < Redmine::HelperTest "http://foo.bar/#{@russian_test}" => %|http://foo.bar/#{@russian_test}| } - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + end end def test_auto_mailto @@ -131,7 +135,9 @@ class ApplicationHelperTest < Redmine::HelperTest 'test@foo.bar' => 'test@foo.bar', 'test@www.foo.bar' => 'test@www.foo.bar', } - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + end end def test_inline_images @@ -153,7 +159,9 @@ class ApplicationHelperTest < Redmine::HelperTest 'with query string !http://foo.bar/image.cgi?a=1&b=2!' => 'with query string ' } - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + end end def test_inline_images_inside_tags @@ -164,8 +172,10 @@ class ApplicationHelperTest < Redmine::HelperTest p=. !bar.gif! RAW - assert textilizable(raw).include?('') - assert textilizable(raw).include?('') + with_settings :text_formatting => 'textile' do + assert textilizable(raw).include?('') + assert textilizable(raw).include?('') + end end def test_attached_images @@ -181,7 +191,9 @@ class ApplicationHelperTest < Redmine::HelperTest '', } attachments = Attachment.all - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text, :attachments => attachments)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text, :attachments => attachments)} + end end def test_attached_images_on_issue @@ -196,8 +208,10 @@ class ApplicationHelperTest < Redmine::HelperTest !attached_on_journal.png!' RAW - assert textilizable(raw, :object => journal).include?("") - assert textilizable(raw, :object => journal).include?("") + with_settings :text_formatting => 'textile' do + assert textilizable(raw, :object => journal).include?("") + assert textilizable(raw, :object => journal).include?("") + end end def test_attached_images_with_textile_and_non_ascii_filename @@ -232,11 +246,13 @@ class ApplicationHelperTest < Redmine::HelperTest def test_attached_images_with_hires_naming attachment = Attachment.generate!(:filename => 'image@2x.png') - assert_equal( - %(), - textilizable("!image@2x.png!", :attachments => [attachment]) - ) + with_settings :text_formatting => 'textile' do + assert_equal( + %(), + textilizable("!image@2x.png!", :attachments => [attachment]) + ) + end end def test_attached_images_filename_extension @@ -296,7 +312,9 @@ class ApplicationHelperTest < Redmine::HelperTest } attachments = [a1, a2, a3, a4] - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text, :attachments => attachments)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text, :attachments => attachments)} + end end def test_attached_images_should_read_later @@ -320,7 +338,9 @@ class ApplicationHelperTest < Redmine::HelperTest 'Inline image: ', } attachments = [a1, a2] - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text, :attachments => attachments)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text, :attachments => attachments)} + end ensure set_tmp_attachments_directory end @@ -351,7 +371,9 @@ class ApplicationHelperTest < Redmine::HelperTest 'http://foo.bar/page?p=1&t=z&s=-', 'This is an intern "link":/foo/bar-' => 'This is an intern link' } - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + end end def test_textile_external_links_with_non_ascii_characters @@ -359,7 +381,9 @@ class ApplicationHelperTest < Redmine::HelperTest %|This is a "link":http://foo.bar/#{@russian_test}| => %|This is a link| } - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + end end def test_redmine_links @@ -549,15 +573,19 @@ class ApplicationHelperTest < Redmine::HelperTest 'user:foobar' => 'user:foobar', } @project = Project.find(1) - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text), "#{text} failed"} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text), "#{text} failed"} + end end def test_link_to_note_within_the_same_page - issue = Issue.find(1) - assert_equal '', textilizable('#note-14', :object => issue) + with_settings :text_formatting => 'textile' do + issue = Issue.find(1) + assert_equal '', textilizable('#note-14', :object => issue) - journal = Journal.find(2) - assert_equal '', textilizable('#note-2', :object => journal) + journal = Journal.find(2) + assert_equal '', textilizable('#note-2', :object => journal) + end end def test_user_links_with_email_as_login_name_should_not_be_parsed_textile @@ -603,10 +631,12 @@ class ApplicationHelperTest < Redmine::HelperTest def test_should_not_parse_redmine_links_inside_link raw = "r1 should not be parsed in http://example.com/url-r1/" html = 'http://example.com/url-r1/' - assert_match( - %r{r1 should not be parsed in #{html}
}, - textilizable(raw, :project => Project.find(1)) - ) + with_settings :text_formatting => 'textile' do + assert_match( + %r{r1 should not be parsed in #{html}
}, + textilizable(raw, :project => Project.find(1)) + ) + end end def test_redmine_links_with_a_different_project_before_current_project @@ -615,8 +645,10 @@ class ApplicationHelperTest < Redmine::HelperTest @project = Project.find(3) result1 = link_to("1.4.4", "/versions/#{vp1.id}", :class => "version") result2 = link_to("1.4.4", "/versions/#{vp3.id}", :class => "version") - assert_equal "#{result1} #{result2}
", - textilizable("ecookbook:version:1.4.4 version:1.4.4") + with_settings :text_formatting => 'textile' do + assert_equal "#{result1} #{result2}
", + textilizable('ecookbook:version:1.4.4 version:1.4.4') + end end def test_escaped_redmine_links_should_not_be_parsed @@ -633,7 +665,9 @@ class ApplicationHelperTest < Redmine::HelperTest 'source:/some/file' ] @project = Project.find(1) - to_test.each {|text| assert_equal "#{text}
", textilizable("!" + text), "#{text} failed"} + with_settings :text_formatting => 'textile' do + to_test.each {|text| assert_equal "#{text}
", textilizable("!#{text}"), "#{text} failed"} + end end def test_cross_project_redmine_links @@ -667,8 +701,10 @@ class ApplicationHelperTest < Redmine::HelperTest 'invalid:source:/some/file' => 'invalid:source:/some/file', } @project = Project.find(3) - to_test.each do |text, result| - assert_equal "#{result}
", textilizable(text), "#{text} failed" + with_settings :text_formatting => 'textile' do + to_test.each do |text, result| + assert_equal "#{result}
", textilizable(text), "#{text} failed" + end end end @@ -677,7 +713,9 @@ class ApplicationHelperTest < Redmine::HelperTest link = link_to("Test & Show.txt", "/versions/#{v.id}", :class => "version") @project = v.project - assert_equal "#{link}
", textilizable('version:"Test & Show.txt"') + with_settings :text_formatting => 'textile' do + assert_equal "#{link}
", textilizable('version:"Test & Show.txt"') + end end def test_link_to_issue_subject @@ -767,7 +805,9 @@ class ApplicationHelperTest < Redmine::HelperTest } @project = Project.find(1) - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text), "#{text} failed"} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text), "#{text} failed"} + end end def test_cross_project_multiple_repositories_redmine_links @@ -824,7 +864,9 @@ class ApplicationHelperTest < Redmine::HelperTest 'invalid:source:invalid|some/file' => 'invalid:source:invalid|some/file', } @project = Project.find(3) - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text), "#{text} failed"} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text), "#{text} failed"} + end end def test_redmine_links_git_commit @@ -853,7 +895,9 @@ class ApplicationHelperTest < Redmine::HelperTest to_test = { 'commit:abcd' => changeset_link, } - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + end end # TODO: Bazaar commit id contains mail address, so it contains '@' and '_'. @@ -896,17 +940,21 @@ class ApplicationHelperTest < Redmine::HelperTest 'r123' => changeset_link_rev, 'commit:abcd' => changeset_link_commit, } - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + end end def test_attachment_links text = 'attachment:error281.txt' result = link_to("error281.txt", "/attachments/1", :class => "attachment") - assert_equal "#{result}
", - textilizable(text, - :attachments => Issue.find(3).attachments), - "#{text} failed" + with_settings :text_formatting => 'textile' do + assert_equal "#{result}
", + textilizable(text, + :attachments => Issue.find(3).attachments), + "#{text} failed" + end end def test_attachment_link_should_link_to_latest_attachment @@ -914,8 +962,10 @@ class ApplicationHelperTest < Redmine::HelperTest a2 = Attachment.generate!(:filename => "test.txt") result = link_to("test.txt", "/attachments/#{a2.id}", :class => "attachment") - assert_equal "#{result}
", - textilizable('attachment:test.txt', :attachments => [a1, a2]) + with_settings :text_formatting => 'textile' do + assert_equal "#{result}
", + textilizable('attachment:test.txt', :attachments => [a1, a2]) + end end def test_attachment_links_to_images_with_email_format_should_not_be_parsed @@ -1031,7 +1081,9 @@ class ApplicationHelperTest < Redmine::HelperTest '[[private-child:Wiki]]' => '[[private-child:Wiki]]', } @project = Project.find(1) - to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + end end def test_wiki_links_with_special_characters_should_work_in_textile @@ -1124,8 +1176,10 @@ class ApplicationHelperTest < Redmine::HelperTest :class => "wiki-page new"), } @project = Project.find(1) - to_test.each do |text, result| - assert_equal "#{result}
", textilizable(text, :wiki_links => :local) + with_settings :text_formatting => 'textile' do + to_test.each do |text, result| + assert_equal "#{result}
", textilizable(text, :wiki_links => :local) + end end end @@ -1184,9 +1238,11 @@ class ApplicationHelperTest < Redmine::HelperTest :class => "wiki-page new"), } @project = Project.find(1) - to_test.each do |text, result| - assert_equal "#{result}
", - textilizable(WikiContent.new(:text => text, :page => page), :text) + with_settings :text_formatting => 'textile' do + to_test.each do |text, result| + assert_equal "#{result}
", + textilizable(WikiContent.new(:text => text, :page => page), :text) + end end end @@ -1228,8 +1284,10 @@ class ApplicationHelperTest < Redmine::HelperTest :class => "wiki-page new"), } @project = Project.find(1) - to_test.each do |text, result| - assert_equal "#{result}
", textilizable(text, :wiki_links => :anchor) + with_settings :text_formatting => 'textile' do + to_test.each do |text, result| + assert_equal "#{result}
", textilizable(text, :wiki_links => :anchor) + end end end @@ -1254,7 +1312,9 @@ class ApplicationHelperTest < Redmine::HelperTest 'text
' => 'text
',
'text' => '
text', } - to_test.each {|text, result| assert_equal result, textilizable(text)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal result, textilizable(text)} + end end def test_allowed_html_tags @@ -1263,7 +1323,9 @@ class ApplicationHelperTest < Redmine::HelperTest "
After
EXPECTED - assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') + with_settings :text_formatting => 'textile' do + assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') + end end def test_pre_content_should_not_parse_wiki_and_redmine_links @@ -1315,7 +1379,9 @@ class ApplicationHelperTest < Redmine::HelperTest EXPECTED @project = Project.find(1) - assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') + with_settings :text_formatting => 'textile' do + assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') + end end def test_non_closing_pre_blocks_should_be_closed @@ -1327,7 +1393,9 @@ class ApplicationHelperTest < Redmine::HelperTest EXPECTED @project = Project.find(1) - assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') + with_settings :text_formatting => 'textile' do + assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') + end end def test_unbalanced_closing_pre_tag_should_not_error @@ -1346,7 +1414,9 @@ class ApplicationHelperTest < Redmine::HelperTest expected = <<~EXPECTED/* Hello */document.write("Hello World!");
EXPECTED
- assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
+ with_settings :text_formatting => 'textile' do
+ assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
+ end
end
def test_syntax_highlight_ampersand_in_textile
@@ -1383,7 +1453,9 @@ class ApplicationHelperTest < Redmine::HelperTest
"#{result}
", textilizable(text)} + with_settings :text_formatting => 'textile' do + to_test.each {|text, result| assert_equal "#{result}
", textilizable(text)} + end end def test_wiki_horizontal_rule - assert_equal 'Dashes: ---
', textilizable('Dashes: ---') + with_settings :text_formatting => 'textile' do + assert_equal 'Dashes: ---
', textilizable('Dashes: ---') + end end def test_headings @@ -1409,7 +1485,9 @@ class ApplicationHelperTest < Redmine::HelperTest expected = %|\ninline code
¶' \
- 'inline code
¶' \
+ 'text
', textilizable("*text*", :formatting => true) + with_settings :text_formatting => 'textile' do + assert_equal 'text
', textilizable("*text*", :formatting => true) + end end def test_parse_redmine_links_should_handle_a_tag_without_attributes diff --git a/test/integration/attachments_test.rb b/test/integration/attachments_test.rb index e98d780fa..547c2242b 100644 --- a/test/integration/attachments_test.rb +++ b/test/integration/attachments_test.rb @@ -90,28 +90,30 @@ class AttachmentsTest < Redmine::IntegrationTest token = ajax_upload('myupload.jpg', 'JPEG content') - post( - '/issues/preview', - :params => { - :issue => {:tracker_id => 1, :project_id => 'ecookbook'}, - :text => 'Inline upload: !myupload.jpg!', - :attachments => { - '1' => { - :filename => 'myupload.jpg', - :description => 'My uploaded file', - :token => token + with_settings :text_formatting => 'textile' do + post( + '/issues/preview', + :params => { + :issue => {:tracker_id => 1, :project_id => 'ecookbook'}, + :text => 'Inline upload: !myupload.jpg!', + :attachments => { + '1' => { + :filename => 'myupload.jpg', + :description => 'My uploaded file', + :token => token + } } } - } - ) - assert_response :success + ) + assert_response :success - attachment_path = response.body.match(%r{ '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 a7940cae8..12d4da496 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({{hello_world(<tag>)}}
', textilizable(text) + with_settings :text_formatting => 'textile' do + text = '!{{hello_world({{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({{unknown(<tag>)}}
', textilizable(text) + with_settings :text_formatting => 'textile' do + text = '{{unknown({{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| - "#{link}
", - textilizable("{{thumbnail(testfile.png)}}", :object => Issue.find(14)) + with_settings :text_formatting => 'textile' do + link = link_to(''.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(''.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(''.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(''.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(''.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(''.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(''.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::HelperTestHello 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|\AHello world!.*
\z|, textilizable(text) + with_settings :text_formatting => 'textile' do + text = '*{{hello_world}}*' + assert_match %r|\AHello 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 dc56eba3b..143768085 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