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
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
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
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
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
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
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
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
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
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
'http://www.redmine.org/example-' =>
'<a class="external" href="http://www.redmine.org/example-">http://www.redmine.org/example-</a>',
}
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ end
end
def test_auto_links_with_non_ascii_characters
"http://foo.bar/#{@russian_test}" =>
%|<a class="external" href="http://foo.bar/#{@russian_test}">http://foo.bar/#{@russian_test}</a>|
}
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ end
end
def test_auto_mailto
'test@foo.bar' => '<a class="email" href="mailto:test@foo.bar">test@foo.bar</a>',
'test@www.foo.bar' => '<a class="email" href="mailto:test@www.foo.bar">test@www.foo.bar</a>',
}
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ end
end
def test_inline_images
'with query string !http://foo.bar/image.cgi?a=1&b=2!' =>
'with query string <img src="http://foo.bar/image.cgi?a=1&b=2" alt="" />'
}
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ end
end
def test_inline_images_inside_tags
p=. !bar.gif!
RAW
- assert textilizable(raw).include?('<img src="foo.png" alt="" />')
- assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
+ with_settings :text_formatting => 'textile' do
+ assert textilizable(raw).include?('<img src="foo.png" alt="" />')
+ assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
+ end
end
def test_attached_images
'<a href="http://foo.bar/"><img src="/attachments/download/3/logo.gif" title="This is a logo" alt="This is a logo" loading="lazy" /></a>',
}
attachments = Attachment.all
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
+ end
end
def test_attached_images_on_issue
!attached_on_journal.png!'
RAW
- assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_1.id}/attached_on_issue.png\" alt=\"\" loading=\"lazy\" />")
- assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_2.id}/attached_on_journal.png\" alt=\"\" loading=\"lazy\" />")
+ with_settings :text_formatting => 'textile' do
+ assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_1.id}/attached_on_issue.png\" alt=\"\" loading=\"lazy\" />")
+ assert textilizable(raw, :object => journal).include?("<img src=\"/attachments/download/#{attachment_2.id}/attached_on_journal.png\" alt=\"\" loading=\"lazy\" />")
+ end
end
def test_attached_images_with_textile_and_non_ascii_filename
def test_attached_images_with_hires_naming
attachment = Attachment.generate!(:filename => 'image@2x.png')
- assert_equal(
- %(<p><img src="/attachments/download/#{attachment.id}/image@2x.png" ) +
- %(srcset="/attachments/download/#{attachment.id}/image@2x.png 2x" alt="" loading="lazy" /></p>),
- textilizable("!image@2x.png!", :attachments => [attachment])
- )
+ with_settings :text_formatting => 'textile' do
+ assert_equal(
+ %(<p><img src="/attachments/download/#{attachment.id}/image@2x.png" ) +
+ %(srcset="/attachments/download/#{attachment.id}/image@2x.png 2x" alt="" loading="lazy" /></p>),
+ textilizable("!image@2x.png!", :attachments => [attachment])
+ )
+ end
end
def test_attached_images_filename_extension
}
attachments = [a1, a2, a3, a4]
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
+ end
end
def test_attached_images_should_read_later
'Inline image: <img src="/attachments/download/' + a2.id.to_s + '/testfile.PNG" alt="" loading="lazy" />',
}
attachments = [a1, a2]
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments)}
+ end
ensure
set_tmp_attachments_directory
end
'<a class="external" href="http://foo.bar/page?p=1&t=z&s=-">http://foo.bar/page?p=1&t=z&s=-</a>',
'This is an intern "link":/foo/bar-' => 'This is an intern <a href="/foo/bar-">link</a>'
}
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ end
end
def test_textile_external_links_with_non_ascii_characters
%|This is a "link":http://foo.bar/#{@russian_test}| =>
%|This is a <a href="http://foo.bar/#{@russian_test}" class="external">link</a>|
}
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ end
end
def test_redmine_links
'user:foobar' => 'user:foobar',
}
@project = Project.find(1)
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
+ end
end
def test_link_to_note_within_the_same_page
- issue = Issue.find(1)
- assert_equal '<p><a href="#note-14">#note-14</a></p>', textilizable('#note-14', :object => issue)
+ with_settings :text_formatting => 'textile' do
+ issue = Issue.find(1)
+ assert_equal '<p><a href="#note-14">#note-14</a></p>', textilizable('#note-14', :object => issue)
- journal = Journal.find(2)
- assert_equal '<p><a href="#note-2">#note-2</a></p>', textilizable('#note-2', :object => journal)
+ journal = Journal.find(2)
+ assert_equal '<p><a href="#note-2">#note-2</a></p>', textilizable('#note-2', :object => journal)
+ end
end
def test_user_links_with_email_as_login_name_should_not_be_parsed_textile
def test_should_not_parse_redmine_links_inside_link
raw = "r1 should not be parsed in http://example.com/url-r1/"
html = '<a class="external" href="http://example.com/url-r1/">http://example.com/url-r1/</a>'
- assert_match(
- %r{<p><a class="changeset".*>r1</a> should not be parsed in #{html}</p>},
- textilizable(raw, :project => Project.find(1))
- )
+ with_settings :text_formatting => 'textile' do
+ assert_match(
+ %r{<p><a class="changeset".*>r1</a> should not be parsed in #{html}</p>},
+ textilizable(raw, :project => Project.find(1))
+ )
+ end
end
def test_redmine_links_with_a_different_project_before_current_project
@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 "<p>#{result1} #{result2}</p>",
- textilizable("ecookbook:version:1.4.4 version:1.4.4")
+ with_settings :text_formatting => 'textile' do
+ assert_equal "<p>#{result1} #{result2}</p>",
+ textilizable('ecookbook:version:1.4.4 version:1.4.4')
+ end
end
def test_escaped_redmine_links_should_not_be_parsed
'source:/some/file'
]
@project = Project.find(1)
- to_test.each {|text| assert_equal "<p>#{text}</p>", textilizable("!" + text), "#{text} failed"}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text| assert_equal "<p>#{text}</p>", textilizable("!#{text}"), "#{text} failed"}
+ end
end
def test_cross_project_redmine_links
'invalid:source:/some/file' => 'invalid:source:/some/file',
}
@project = Project.find(3)
- to_test.each do |text, result|
- assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"
+ with_settings :text_formatting => 'textile' do
+ to_test.each do |text, result|
+ assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"
+ end
end
end
link = link_to("Test & Show.txt", "/versions/#{v.id}", :class => "version")
@project = v.project
- assert_equal "<p>#{link}</p>", textilizable('version:"Test & Show.txt"')
+ with_settings :text_formatting => 'textile' do
+ assert_equal "<p>#{link}</p>", textilizable('version:"Test & Show.txt"')
+ end
end
def test_link_to_issue_subject
}
@project = Project.find(1)
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
+ end
end
def test_cross_project_multiple_repositories_redmine_links
'invalid:source:invalid|some/file' => 'invalid:source:invalid|some/file',
}
@project = Project.find(3)
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed"}
+ end
end
def test_redmine_links_git_commit
to_test = {
'commit:abcd' => changeset_link,
}
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ end
end
# TODO: Bazaar commit id contains mail address, so it contains '@' and '_'.
'r123' => changeset_link_rev,
'commit:abcd' => changeset_link_commit,
}
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ end
end
def test_attachment_links
text = 'attachment:error281.txt'
result = link_to("error281.txt", "/attachments/1",
:class => "attachment")
- assert_equal "<p>#{result}</p>",
- textilizable(text,
- :attachments => Issue.find(3).attachments),
- "#{text} failed"
+ with_settings :text_formatting => 'textile' do
+ assert_equal "<p>#{result}</p>",
+ textilizable(text,
+ :attachments => Issue.find(3).attachments),
+ "#{text} failed"
+ end
end
def test_attachment_link_should_link_to_latest_attachment
a2 = Attachment.generate!(:filename => "test.txt")
result = link_to("test.txt", "/attachments/#{a2.id}",
:class => "attachment")
- assert_equal "<p>#{result}</p>",
- textilizable('attachment:test.txt', :attachments => [a1, a2])
+ with_settings :text_formatting => 'textile' do
+ assert_equal "<p>#{result}</p>",
+ textilizable('attachment:test.txt', :attachments => [a1, a2])
+ end
end
def test_attachment_links_to_images_with_email_format_should_not_be_parsed
'[[private-child:Wiki]]' => '[[private-child:Wiki]]',
}
@project = Project.find(1)
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ end
end
def test_wiki_links_with_special_characters_should_work_in_textile
:class => "wiki-page new"),
}
@project = Project.find(1)
- to_test.each do |text, result|
- assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local)
+ with_settings :text_formatting => 'textile' do
+ to_test.each do |text, result|
+ assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :local)
+ end
end
end
:class => "wiki-page new"),
}
@project = Project.find(1)
- to_test.each do |text, result|
- assert_equal "<p>#{result}</p>",
- textilizable(WikiContent.new(:text => text, :page => page), :text)
+ with_settings :text_formatting => 'textile' do
+ to_test.each do |text, result|
+ assert_equal "<p>#{result}</p>",
+ textilizable(WikiContent.new(:text => text, :page => page), :text)
+ end
end
end
:class => "wiki-page new"),
}
@project = Project.find(1)
- to_test.each do |text, result|
- assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor)
+ with_settings :text_formatting => 'textile' do
+ to_test.each do |text, result|
+ assert_equal "<p>#{result}</p>", textilizable(text, :wiki_links => :anchor)
+ end
end
end
'<pre><code class=""onmouseover="alert(1)">text</code></pre>' => '<pre><code>text</code></pre>',
'<pre class=""onmouseover="alert(1)">text</pre>' => '<pre>text</pre>',
}
- 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
"<notextile>no *textile* formatting</notextile>" => "no *textile* formatting",
"<notextile>this is <tag>a tag</tag></notextile>" => "this is <tag>a tag</tag>"
}
- 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_pre_tags
</pre>
<p>After</p>
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
</pre>
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
</code></pre>
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
expected = <<~EXPECTED
<pre><code class="ECMA_script syntaxhl" data-language=\"ECMA_script\"><span class="cm">/* Hello */</span><span class="nb">document</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="dl">"</span><span class="s2">Hello World!</span><span class="dl">"</span><span class="p">);</span></code></pre>
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
"<td>#{link2}</td>" +
"</tr><tr><td>Cell 21</td><td>#{link3}</td></tr>"
@project = Project.find(1)
- assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '')
+ with_settings :text_formatting => 'textile' do
+ assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '')
+ end
end
def test_text_formatting
'a *H* umane *W* eb *T* ext *G* enerator' =>
'a <strong>H</strong> umane <strong>W</strong> eb <strong>T</strong> ext <strong>G</strong> enerator',
}
- to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ with_settings :text_formatting => 'textile' do
+ to_test.each {|text, result| assert_equal "<p>#{result}</p>", textilizable(text)}
+ end
end
def test_wiki_horizontal_rule
- assert_equal '<hr />', textilizable('---')
- assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
+ with_settings :text_formatting => 'textile' do
+ assert_equal '<hr />', textilizable('---')
+ assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
+ end
end
def test_headings
expected =
%|<a name="Some-heading"></a>\n<h1 >Some heading| +
%|<a href="#Some-heading" class="wiki-anchor">¶</a></h1>|
- assert_equal expected, textilizable(raw)
+ with_settings :text_formatting => 'textile' do
+ assert_equal expected, textilizable(raw)
+ end
end
def test_headings_with_special_chars
expected =
%|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5| +
%|<a href="##{anchor}" class="wiki-anchor">¶</a></h1>|
- assert_equal expected, textilizable(raw)
+ with_settings :text_formatting => 'textile' do
+ assert_equal expected, textilizable(raw)
+ end
end
def test_headings_in_wiki_single_page_export_should_be_prepended_with_page_title
expected =
%|<a name="Page_Title_Some-heading"></a>\n<h1 >Some heading| +
%|<a href="#Page_Title_Some-heading" class="wiki-anchor">¶</a></h1>|
- assert_equal expected, textilizable(content, :text, :wiki_links => :anchor)
+ with_settings :text_formatting => 'textile' do
+ assert_equal expected, textilizable(content, :text, :wiki_links => :anchor)
+ end
end
def test_table_of_content
'</ul>'
@project = Project.find(1)
- assert textilizable(raw).delete("\n").include?(expected)
+ with_settings :text_formatting => 'textile' do
+ assert textilizable(raw).delete("\n").include?(expected)
+ end
end
def test_table_of_content_should_generate_unique_anchors
'</li>' +
'</ul>'
@project = Project.find(1)
- result = textilizable(raw).delete("\n")
- assert_include expected, result
- assert_include '<a name="Subtitle">', result
- assert_include '<a name="Subtitle-2">', result
+ with_settings :text_formatting => 'textile' do
+ result = textilizable(raw).delete("\n")
+ assert_include expected, result
+ assert_include '<a name="Subtitle">', result
+ assert_include '<a name="Subtitle-2">', result
+ end
end
def test_table_of_content_should_contain_included_page_headings
'<li><a href="#Child-page-1">Child page 1</a></li>' +
'</ul>'
@project = Project.find(1)
- assert textilizable(raw).delete("\n").include?(expected)
+ with_settings :text_formatting => 'textile' do
+ assert textilizable(raw).delete("\n").include?(expected)
+ end
end
def test_toc_with_textile_formatting_should_be_parsed
RAW
@project = Project.find(1)
set_language_if_valid 'en'
- result =
- textilizable(
- raw,
- :edit_section_links =>
- {:controller => 'wiki', :action => 'edit',
- :project_id => '1', :id => 'Test'}
- ).delete("\n")
- # heading that contains inline code
- assert_match(
- Regexp.new(
- '<div class="contextual heading-2" title="Edit this section" id="section-4">' \
- '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=4">' \
- 'Edit this section' \
- '</a></div>' \
- '<a name="Subtitle-with-inline-code"></a>' \
- '<h2 >Subtitle with ' \
- '<code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">¶</a>' \
- '</h2>'
- ),
- result
- )
- # last heading
- assert_match(
- Regexp.new(
- '<div class="contextual heading-2" title="Edit this section" id="section-5">' \
- '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=5">' \
- 'Edit this section' \
- '</a></div>' \
- '<a name="Subtitle-after-pre-tag"></a>' \
- '<h2 >Subtitle after pre tag' \
- '<a href="#Subtitle-after-pre-tag" class="wiki-anchor">¶</a></h2>'
- ),
- result
- )
+ with_settings :text_formatting => 'textile' do
+ result =
+ textilizable(
+ raw,
+ :edit_section_links =>
+ {:controller => 'wiki', :action => 'edit',
+ :project_id => '1', :id => 'Test'}
+ ).delete("\n")
+ # heading that contains inline code
+ assert_match(
+ Regexp.new(
+ '<div class="contextual heading-2" title="Edit this section" id="section-4">' \
+ '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=4">' \
+ 'Edit this section' \
+ '</a></div>' \
+ '<a name="Subtitle-with-inline-code"></a>' \
+ '<h2 >Subtitle with ' \
+ '<code>inline code</code><a href="#Subtitle-with-inline-code" class="wiki-anchor">¶</a>' \
+ '</h2>'
+ ),
+ result
+ )
+ # last heading
+ assert_match(
+ Regexp.new(
+ '<div class="contextual heading-2" title="Edit this section" id="section-5">' \
+ '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=5">' \
+ 'Edit this section' \
+ '</a></div>' \
+ '<a name="Subtitle-after-pre-tag"></a>' \
+ '<h2 >Subtitle after pre tag' \
+ '<a href="#Subtitle-after-pre-tag" class="wiki-anchor">¶</a></h2>'
+ ),
+ result
+ )
+ end
end
def test_default_formatter
end
def test_textilizable_with_formatting_set_to_true_should_format_text
- assert_equal '<p><strong>text</strong></p>', textilizable("*text*", :formatting => true)
+ with_settings :text_formatting => 'textile' do
+ assert_equal '<p><strong>text</strong></p>', textilizable("*text*", :formatting => true)
+ end
end
def test_parse_redmine_links_should_handle_a_tag_without_attributes
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{<img src="(/attachments/download/\d+/myupload.jpg)"})[1]
- assert_not_nil token, "No attachment path found in response:\n#{response.body}"
+ attachment_path = response.body.match(%r{<img src="(/attachments/download/\d+/myupload.jpg)"})[1]
+ assert_not_nil token, "No attachment path found in response:\n#{response.body}"
- get attachment_path
- assert_response :success
- assert_equal 'JPEG content', response.body
+ get attachment_path
+ assert_response :success
+ assert_equal 'JPEG content', response.body
+ end
end
def test_upload_and_resubmit_after_validation_failure
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 "<strong>foo</strong>", 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 '<strong>foo</strong>', field.format.formatted_custom_value(self, custom_value, true)
+ end
end
def test_text_field_with_text_formatting_disabled_should_not_format_text
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 "<strong>foo</strong>", 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 '<strong>foo</strong>', field.format.formatted_custom_value(self, custom_value, true)
+ end
end
def test_should_validate_url_pattern_with_safe_scheme
end
end
- assert_equal '<p>Foo: 0 () (Array)</p>', textilizable("{{foo}}")
- assert_equal '<p>Foo: 0 () (Array)</p>', textilizable("{{foo()}}")
- assert_equal '<p>Foo: 1 (arg1) (Array)</p>', textilizable("{{foo(arg1)}}")
- assert_equal '<p>Foo: 2 (arg1,arg2) (Array)</p>', textilizable("{{foo(arg1, arg2)}}")
+ with_settings :text_formatting => 'textile' do
+ assert_equal '<p>Foo: 0 () (Array)</p>', textilizable('{{foo}}')
+ assert_equal '<p>Foo: 0 () (Array)</p>', textilizable('{{foo()}}')
+ assert_equal '<p>Foo: 1 (arg1) (Array)</p>', textilizable('{{foo(arg1)}}')
+ assert_equal '<p>Foo: 2 (arg1,arg2) (Array)</p>', textilizable('{{foo(arg1, arg2)}}')
+ end
end
def test_macro_registration_parse_args_set_to_false_should_disable_arguments_parsing
end
end
- assert_equal '<p>Bar: (args, more args) (String)</p>', textilizable("{{bar(args, more args)}}")
- assert_equal '<p>Bar: () (String)</p>', textilizable("{{bar}}")
- assert_equal '<p>Bar: () (String)</p>', textilizable("{{bar()}}")
+ with_settings :text_formatting => 'textile' do
+ assert_equal '<p>Bar: (args, more args) (String)</p>', textilizable('{{bar(args, more args)}}')
+ assert_equal '<p>Bar: () (String)</p>', textilizable('{{bar}}')
+ assert_equal '<p>Bar: () (String)</p>', textilizable('{{bar()}}')
+ end
end
def test_macro_registration_with_3_args_should_receive_text_argument
end
end
- assert_equal "<p>Baz: () (NilClass) ()</p>", textilizable("{{baz}}")
- assert_equal "<p>Baz: () (NilClass) ()</p>", textilizable("{{baz()}}")
- assert_equal "<p>Baz: () (String) (line1\nline2)</p>", textilizable("{{baz()\nline1\nline2\n}}")
- assert_equal "<p>Baz: (arg1,arg2) (String) (line1\nline2)</p>", textilizable("{{baz(arg1, arg2)\nline1\nline2\n}}")
+ with_settings :text_formatting => 'textile' do
+ assert_equal '<p>Baz: () (NilClass) ()</p>', textilizable('{{baz}}')
+ assert_equal '<p>Baz: () (NilClass) ()</p>', textilizable('{{baz()}}')
+ assert_equal "<p>Baz: () (String) (line1\nline2)</p>", textilizable("{{baz()\nline1\nline2\n}}")
+ assert_equal "<p>Baz: (arg1,arg2) (String) (line1\nline2)</p>", 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 "<p>Upper</p>", textilizable("{{UpperCase}}")
+ with_settings :text_formatting => 'textile' do
+ Redmine::WikiFormatting::Macros.macro(:UpperCase) {|obj, args| 'Upper'}
+ assert_equal '<p>Upper</p>', textilizable('{{UpperCase}}')
+ end
end
def test_multiple_macros_on_the_same_line
args.any? ? "args: #{args.join(',')}" : "no args"
end
- assert_equal '<p>no args no args</p>', textilizable("{{foo}} {{foo}}")
- assert_equal '<p>args: a,b no args</p>', textilizable("{{foo(a,b)}} {{foo}}")
- assert_equal '<p>args: a,b args: c,d</p>', textilizable("{{foo(a,b)}} {{foo(c,d)}}")
- assert_equal '<p>no args args: c,d</p>', textilizable("{{foo}} {{foo(c,d)}}")
+ with_settings :text_formatting => 'textile' do
+ assert_equal '<p>no args no args</p>', textilizable('{{foo}} {{foo}}')
+ assert_equal '<p>args: a,b no args</p>', textilizable('{{foo(a,b)}} {{foo}}')
+ assert_equal '<p>args: a,b args: c,d</p>', textilizable('{{foo(a,b)}} {{foo(c,d)}}')
+ assert_equal '<p>no args args: c,d</p>', 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(
- '<p>Hello world! Object: Issue, Called with no argument and no block of text.</p>',
- textilizable(issue, :description)
- )
+ with_settings :text_formatting => 'textile' do
+ assert_equal(
+ '<p>Hello world! Object: Issue, Called with no argument and no block of text.</p>',
+ textilizable(issue, :description)
+ )
+ end
end
def test_macro_should_receive_the_object_as_argument_when_called_with_object_option
- text = "{{hello_world}}"
- assert_equal(
- '<p>Hello world! Object: Issue, Called with no argument and no block of text.</p>',
- textilizable(text, :object => Issue.find(1))
- )
+ with_settings :text_formatting => 'textile' do
+ text = '{{hello_world}}'
+ assert_equal(
+ '<p>Hello world! Object: Issue, Called with no argument and no block of text.</p>',
+ textilizable(text, :object => Issue.find(1))
+ )
+ end
end
def test_extract_macro_options_should_with_args
end
def test_exclamation_mark_should_not_run_macros
- text = "!{{hello_world}}"
- assert_equal '<p>{{hello_world}}</p>', textilizable(text)
+ with_settings :text_formatting => 'textile' do
+ text = '!{{hello_world}}'
+ assert_equal '<p>{{hello_world}}</p>', textilizable(text)
+ end
end
def test_exclamation_mark_should_escape_macros
- text = "!{{hello_world(<tag>)}}"
- assert_equal '<p>{{hello_world(<tag>)}}</p>', textilizable(text)
+ with_settings :text_formatting => 'textile' do
+ text = '!{{hello_world(<tag>)}}'
+ assert_equal '<p>{{hello_world(<tag>)}}</p>', textilizable(text)
+ end
end
def test_unknown_macros_should_not_be_replaced
- text = "{{unknown}}"
- assert_equal '<p>{{unknown}}</p>', textilizable(text)
+ with_settings :text_formatting => 'textile' do
+ text = '{{unknown}}'
+ assert_equal '<p>{{unknown}}</p>', textilizable(text)
+ end
end
def test_unknown_macros_should_parsed_as_text
- text = "{{unknown(*test*)}}"
- assert_equal '<p>{{unknown(<strong>test</strong>)}}</p>', textilizable(text)
+ with_settings :text_formatting => 'textile' do
+ text = '{{unknown(*test*)}}'
+ assert_equal '<p>{{unknown(<strong>test</strong>)}}</p>', textilizable(text)
+ end
end
def test_unknown_macros_should_be_escaped
- text = "{{unknown(<tag>)}}"
- assert_equal '<p>{{unknown(<tag>)}}</p>', textilizable(text)
+ with_settings :text_formatting => 'textile' do
+ text = '{{unknown(<tag>)}}'
+ assert_equal '<p>{{unknown(<tag>)}}</p>', textilizable(text)
+ end
end
def test_html_safe_macro_output_should_not_be_escaped
- Redmine::WikiFormatting::Macros.macro :safe_macro do |obj, args|
- "<tag>".html_safe
+ with_settings :text_formatting => 'textile' do
+ Redmine::WikiFormatting::Macros.macro :safe_macro do |obj, args|
+ '<tag>'.html_safe
+ end
+ assert_equal '<p><tag></p>', textilizable('{{safe_macro}}')
end
- assert_equal '<p><tag></p>', textilizable("{{safe_macro}}")
end
def test_macro_hello_world
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
expected_toc =
'<ul class="toc"><li><strong>Table of contents</strong></li>' \
'<li><a href="#Title">Title</a><ul><li><a href="#Heading">Heading</a></li></ul></li></ul>'
- 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
"<li><a href=\"/projects/ecookbook/wiki/Child_2\">Child 2</a></li>\n" \
"</ul>\n</p>"
@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
"</ul>\n</li>\n</ul>\n</p>"
@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
"<li><a href=\"/projects/ecookbook/wiki/Child_2\">Child 2</a></li>\n" \
"</ul>\n</p>"
@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
end
def test_macro_thumbnail
- link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17/200" />'.html_safe,
- "/attachments/17",
- :class => "thumbnail",
- :title => "testfile.PNG")
- assert_equal "<p>#{link}</p>",
- textilizable("{{thumbnail(testfile.png)}}", :object => Issue.find(14))
+ with_settings :text_formatting => 'textile' do
+ link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17/200" />'.html_safe,
+ '/attachments/17',
+ :class => 'thumbnail',
+ :title => 'testfile.PNG')
+ assert_equal "<p>#{link}</p>",
+ textilizable('{{thumbnail(testfile.png)}}', :object => Issue.find(14))
+ end
end
def test_macro_thumbnail_with_full_path
- link = link_to('<img alt="testfile.PNG" src="http://test.host/attachments/thumbnail/17/200" />'.html_safe,
- "http://test.host/attachments/17",
- :class => "thumbnail",
- :title => "testfile.PNG")
- assert_equal "<p>#{link}</p>",
- textilizable("{{thumbnail(testfile.png)}}", :object => Issue.find(14), :only_path => false)
+ with_settings :text_formatting => 'textile' do
+ link = link_to('<img alt="testfile.PNG" src="http://test.host/attachments/thumbnail/17/200" />'.html_safe,
+ 'http://test.host/attachments/17',
+ :class => 'thumbnail',
+ :title => 'testfile.PNG')
+ assert_equal "<p>#{link}</p>",
+ textilizable('{{thumbnail(testfile.png)}}', :object => Issue.find(14), :only_path => false)
+ end
end
def test_macro_thumbnail_with_size
- link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17/400" />'.html_safe,
- "/attachments/17",
- :class => "thumbnail",
- :title => "testfile.PNG")
- assert_equal "<p>#{link}</p>",
- textilizable("{{thumbnail(testfile.png, size=400)}}", :object => Issue.find(14))
+ with_settings :text_formatting => 'textile' do
+ link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17/400" />'.html_safe,
+ '/attachments/17',
+ :class => 'thumbnail',
+ :title => 'testfile.PNG')
+ assert_equal "<p>#{link}</p>",
+ textilizable('{{thumbnail(testfile.png, size=400)}}', :object => Issue.find(14))
+ end
end
def test_macro_thumbnail_with_title
- link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17/200" />'.html_safe,
- "/attachments/17",
- :class => "thumbnail",
- :title => "Cool image")
- assert_equal "<p>#{link}</p>",
- textilizable("{{thumbnail(testfile.png, title=Cool image)}}", :object => Issue.find(14))
+ with_settings :text_formatting => 'textile' do
+ link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17/200" />'.html_safe,
+ '/attachments/17',
+ :class => 'thumbnail',
+ :title => 'Cool image')
+ assert_equal "<p>#{link}</p>",
+ textilizable('{{thumbnail(testfile.png, title=Cool image)}}', :object => Issue.find(14))
+ end
end
def test_macro_thumbnail_with_invalid_filename_should_fail
<p>Hello world! Object: NilClass, Arguments: bar and no block of text.</p>
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 = "<pre>{{hello_world(<tag>)}}</pre>"
- assert_equal "<pre>{{hello_world(<tag>)}}</pre>", textilizable(text)
+ with_settings :text_formatting => 'textile' do
+ text = '<pre>{{hello_world(<tag>)}}</pre>'
+ assert_equal '<pre>{{hello_world(<tag>)}}</pre>', textilizable(text)
+ end
end
def test_macros_should_not_mangle_next_macros_outputs
- text = '{{macro(2)}} !{{macro(2)}} {{hello_world(foo)}}'
- assert_equal(
- '<p>{{macro(2)}} {{macro(2)}} Hello world! Object: NilClass, Arguments: foo and no block of text.</p>',
- textilizable(text)
- )
+ with_settings :text_formatting => 'textile' do
+ text = '{{macro(2)}} !{{macro(2)}} {{hello_world(foo)}}'
+ assert_equal(
+ '<p>{{macro(2)}} {{macro(2)}} Hello world! Object: NilClass, Arguments: foo and no block of text.</p>',
+ textilizable(text)
+ )
+ end
end
def test_macros_with_text_should_not_mangle_following_macros
end
def test_macro_should_support_phrase_modifiers
- text = "*{{hello_world}}*"
- assert_match %r|\A<p><strong>Hello world!.*</strong></p>\z|, textilizable(text)
+ with_settings :text_formatting => 'textile' do
+ text = '*{{hello_world}}*'
+ assert_match %r|\A<p><strong>Hello world!.*</strong></p>\z|, textilizable(text)
+ end
end
def test_issue_macro_should_not_render_link_if_not_visible
- assert_equal "<p>#123</p>", textilizable('{{issue(123)}}')
+ with_settings :text_formatting => 'textile' do
+ assert_equal '<p>#123</p>', textilizable('{{issue(123)}}')
+ end
end
def test_issue_macro_should_render_link_to_issue
issue = Issue.find(1)
- assert_equal(
- %{<p><a class="issue tracker-1 status-1 priority-4 priority-lowest behind-schedule" } +
- %{href="/issues/1">Bug #1</a>: #{issue.subject}</p>},
- textilizable("{{issue(1)}}")
- )
- assert_equal(
- %{<p>eCookbook - } +
- %{<a class="issue tracker-1 status-1 priority-4 priority-lowest behind-schedule" } +
- %{href="/issues/1">Bug #1</a>: #{issue.subject}</p>},
- textilizable("{{issue(1, project=true)}}")
- )
+ with_settings :text_formatting => 'textile' do
+ assert_equal(
+ %{<p><a class="issue tracker-1 status-1 priority-4 priority-lowest behind-schedule" } +
+ %{href="/issues/1">Bug #1</a>: #{issue.subject}</p>},
+ textilizable('{{issue(1)}}')
+ )
+ assert_equal(
+ %{<p>eCookbook - } +
+ %{<a class="issue tracker-1 status-1 priority-4 priority-lowest behind-schedule" } +
+ %{href="/issues/1">Bug #1</a>: #{issue.subject}</p>},
+ textilizable('{{issue(1, project=true)}}')
+ )
+ end
end
end
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
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