Redmine 4.1.1

This commit is contained in:
Manuel Cillero 2020-11-22 21:20:06 +01:00
parent 33e7b881a5
commit 3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -62,7 +64,7 @@ class Redmine::CipheringTest < ActiveSupport::TestCase
assert_equal 'clear', r.password
end
end
def test_ciphered_password_with_no_cipher_key_configured_should_be_returned_ciphered
Redmine::Configuration.with 'database_cipher_key' => 'secret' do
r = Repository::Subversion.create!(:password => 'clear', :url => 'file:///tmp', :identifier => 'svn')

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -21,8 +23,8 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
def test_to_utf8_by_setting_from_latin1
with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
s1 = "Texte encod\xc3\xa9".force_encoding("UTF-8")
s2 = "Texte encod\xe9".force_encoding("ASCII-8BIT")
s1 = 'Texte encodé'
s2 = "Texte encod\xe9".b
s3 = s2.dup.force_encoding("UTF-8")
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
@ -31,8 +33,8 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
def test_to_utf8_by_setting_from_euc_jp
with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3".force_encoding("UTF-8")
s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3".force_encoding("ASCII-8BIT")
s1 = 'レッドマイン'
s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3".b
s3 = s2.dup.force_encoding("UTF-8")
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
@ -41,8 +43,8 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
def test_to_utf8_by_setting_should_be_converted_all_latin1
with_settings :repositories_encodings => 'ISO-8859-1' do
s1 = "\xc3\x82\xc2\x80".force_encoding("UTF-8")
s2 = "\xC2\x80".force_encoding("ASCII-8BIT")
s1 = "Â\u0080"
s2 = "\xC2\x80".b
s3 = s2.dup.force_encoding("UTF-8")
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
@ -55,7 +57,7 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
end
def test_to_utf8_by_setting_returns_ascii_as_utf8
s1 = "ASCII".force_encoding("UTF-8")
s1 = 'ASCII'
s2 = s1.dup.force_encoding("ISO-8859-1")
str1 = Redmine::CodesetUtil.to_utf8_by_setting(s1)
str2 = Redmine::CodesetUtil.to_utf8_by_setting(s2)
@ -67,8 +69,7 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped
with_settings :repositories_encodings => '' do
# s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
s1 = "Texte encod\xe9 en ISO-8859-1.".force_encoding("ASCII-8BIT")
s1 = "Texte encod\xe9 en ISO-8859-1.".b
str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
assert str.valid_encoding?
assert_equal "UTF-8", str.encoding.to_s
@ -78,7 +79,7 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped_ja_jis
with_settings :repositories_encodings => 'ISO-2022-JP' do
s1 = "test\xb5\xfetest\xb5\xfe".force_encoding("ASCII-8BIT")
s1 = "test\xb5\xfetest\xb5\xfe".b
str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
assert str.valid_encoding?
assert_equal "UTF-8", str.encoding.to_s
@ -87,18 +88,18 @@ class Redmine::CodesetUtilTest < ActiveSupport::TestCase
end
test "#replace_invalid_utf8 should replace invalid utf8" do
s1 = "\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xE3\x81\xFF".force_encoding("UTF-8")
s1 = "こんにち\xE3\x81\xFF"
s2 = Redmine::CodesetUtil.replace_invalid_utf8(s1)
assert s2.valid_encoding?
assert_equal "UTF-8", s2.encoding.to_s
assert_equal "\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1??".force_encoding("UTF-8"), s2
assert_equal 'こんにち??', s2
end
test "#to_utf8 should replace invalid non utf8" do
s1 = "\xa4\xb3\xa4\xf3\xa4\xcb\xa4\xc1\xa4".force_encoding("EUC-JP")
s1 = (+"\xa4\xb3\xa4\xf3\xa4\xcb\xa4\xc1\xa4").force_encoding("EUC-JP")
s2 = Redmine::CodesetUtil.to_utf8(s1, "EUC-JP")
assert s2.valid_encoding?
assert_equal "UTF-8", s2.encoding.to_s
assert_equal "\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1?".force_encoding("UTF-8"), s2
assert_equal 'こんにち?', s2
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -18,14 +20,28 @@
require File.expand_path('../../../../../test_helper', __FILE__)
class CsvTest < ActiveSupport::TestCase
BOM = "\xEF\xBB\xBF".force_encoding('UTF-8')
include Redmine::I18n
def test_should_include_bom_when_utf8_encoded
with_locale 'sk' do
string = Redmine::Export::CSV.generate {|csv| csv << %w(Foo Bar)}
assert_equal 'UTF-8', string.encoding.name
assert string.starts_with?(BOM)
assert string.starts_with?("\xEF\xBB\xBF")
end
end
def test_generate_should_return_strings_with_given_encoding
with_locale 'en' do
string = Redmine::Export::CSV.generate({encoding: 'ISO-8859-3'}) {|csv| csv << %w(Foo Bar)}
assert_equal 'ISO-8859-3', string.encoding.name
assert_not_equal l(:general_csv_encoding), string.encoding.name
end
end
def test_generate_should_return_strings_with_general_csv_encoding_if_invalid_encoding_is_given
with_locale 'en' do
string = Redmine::Export::CSV.generate({encoding: 'invalid-encoding-name'}) {|csv| csv << %w(Foo Bar)}
assert_equal l(:general_csv_encoding), string.encoding.name
end
end
end

View file

@ -0,0 +1,50 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../../test_helper', __FILE__)
class IssuesPdfHelperTest < ActiveSupport::TestCase
fixtures :users, :projects, :roles, :members, :member_roles,
:enabled_modules, :issues, :trackers, :enumerations
include Redmine::Export::PDF::IssuesPdfHelper
def test_fetch_row_values_should_round_float_values
query = IssueQuery.new(:project => Project.find(1), :name => '_')
query.column_names = [:subject, :spent_hours]
issue = Issue.find(2)
user = User.find(1)
time_entry = TimeEntry.create!(:spent_on => Date.today, :hours => 4.3432, :user => user, :author => user,
:project_id => 1, :issue => issue, :activity => TimeEntryActivity.first)
results = fetch_row_values(issue, query, 0)
assert_equal ["2", "Add ingredients categories", "4.34"], results
end
def test_fetch_row_values_should_be_able_to_handle_parent_issue_subject
query = IssueQuery.new(:project => Project.find(1), :name => '_')
query.column_names = [:subject, 'parent.subject']
issue = Issue.find(2)
issue.parent = Issue.find(1)
issue.save!
results = fetch_row_values(issue, query, 0)
assert_equal ['2', 'Add ingredients categories', 'Cannot print recipes'], results
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -27,16 +29,16 @@ class PdfTest < ActiveSupport::TestCase
end
def test_rdm_pdf_iconv_cannot_convert_ja_cp932
utf8_txt_1 = "\xe7\x8b\x80\xe6\x85\x8b"
utf8_txt_2 = "\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
utf8_txt_3 = "\xe7\x8b\x80\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
utf8_txt_1 = '狀態'
utf8_txt_2 = '狀態狀'
utf8_txt_3 = '狀狀態狀'
["CP932", "SJIS"].each do |encoding|
txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_1, encoding)
txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_2, encoding)
txt_3 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_3, encoding)
assert_equal "?\x91\xd4".force_encoding("ASCII-8BIT"), txt_1
assert_equal "?\x91\xd4?".force_encoding("ASCII-8BIT"), txt_2
assert_equal "??\x91\xd4?".force_encoding("ASCII-8BIT"), txt_3
assert_equal "?\x91\xd4".b, txt_1
assert_equal "?\x91\xd4?".b, txt_2
assert_equal "??\x91\xd4?".b, txt_3
assert_equal "ASCII-8BIT", txt_1.encoding.to_s
assert_equal "ASCII-8BIT", txt_2.encoding.to_s
assert_equal "ASCII-8BIT", txt_3.encoding.to_s
@ -44,8 +46,8 @@ class PdfTest < ActiveSupport::TestCase
end
def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_en
str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8")
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
str1 = "Texte encod\xE9 en ISO-8859-1"
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".b
txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, 'UTF-8')
txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, 'UTF-8')
assert_equal "ASCII-8BIT", txt_1.encoding.to_s
@ -55,8 +57,8 @@ class PdfTest < ActiveSupport::TestCase
end
def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_ja
str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8")
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
str1 = "Texte encod\xE9 en ISO-8859-1"
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".b
encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" )
txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, encoding)
txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, encoding)
@ -67,10 +69,9 @@ class PdfTest < ActiveSupport::TestCase
end
def test_attach
set_fixtures_attachments_directory
["CP932", "SJIS"].each do |encoding|
set_fixtures_attachments_directory
str2 = "\x83e\x83X\x83g".force_encoding("ASCII-8BIT")
str2 = "\x83e\x83X\x83g".b
a1 = Attachment.find(17)
a2 = Attachment.find(19)
@ -97,8 +98,8 @@ class PdfTest < ActiveSupport::TestCase
assert_nil aa1
aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding)
assert_nil aa2
set_tmp_attachments_directory
end
ensure
set_tmp_attachments_directory
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -25,6 +27,7 @@ class Redmine::AttachmentFieldFormatTest < ActionView::TestCase
fixtures :users
def setup
User.current = nil
set_language_if_valid 'en'
set_tmp_attachments_directory
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -23,6 +25,7 @@ class AttachmentFormatVisibilityTest < ActionView::TestCase
:roles, :members, :member_roles,
:users, :email_addresses,
:trackers, :issue_statuses, :enumerations, :issue_categories,
:custom_fields, :custom_fields_trackers,
:versions, :issues
def setup

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -73,7 +75,7 @@ class Redmine::FieldFormatTest < ActionView::TestCase
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "bar")
assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
assert_equal '<a class="external" href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_text_field_with_url_pattern_and_value_containing_a_space_should_format_as_link
@ -81,7 +83,7 @@ class Redmine::FieldFormatTest < ActionView::TestCase
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "foo bar")
assert_equal "foo bar", field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo/foo%20bar">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
assert_equal '<a class="external" href="http://foo/foo%20bar">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_text_field_with_url_pattern_should_not_encode_url_pattern
@ -89,7 +91,7 @@ class Redmine::FieldFormatTest < ActionView::TestCase
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "1")
assert_equal "1", field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo/bar#anchor">1</a>', field.format.formatted_custom_value(self, custom_value, true)
assert_equal '<a class="external" href="http://foo/bar#anchor">1</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_text_field_with_url_pattern_should_encode_values
@ -97,6 +99,6 @@ class Redmine::FieldFormatTest < ActionView::TestCase
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "foo bar")
assert_equal "foo bar", field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo/foo%20bar#anchor">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
assert_equal '<a class="external" href="http://foo/foo%20bar#anchor">foo bar</a>', field.format.formatted_custom_value(self, custom_value, true)
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -29,7 +31,7 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "bar")
assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
assert_equal '<a class="external" href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_link_field_should_substitute_object_id_in_url
@ -40,7 +42,7 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo/10">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
assert_equal '<a class="external" href="http://foo/10">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_link_field_should_substitute_project_id_in_url
@ -53,7 +55,7 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo/52">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
assert_equal '<a class="external" href="http://foo/52">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_link_field_should_substitute_project_identifier_in_url
@ -66,7 +68,7 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo/foo_project-00">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
assert_equal '<a class="external" href="http://foo/foo_project-00">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_link_field_should_substitute_regexp_groups
@ -74,7 +76,7 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "56-142")
assert_equal "56-142", field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo/142/56">56-142</a>', field.format.formatted_custom_value(self, custom_value, true)
assert_equal '<a class="external" href="http://foo/142/56">56-142</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_link_field_without_url_pattern_should_link_to_value
@ -82,7 +84,7 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "http://foo/bar")
assert_equal "http://foo/bar", field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo/bar">http://foo/bar</a>', field.format.formatted_custom_value(self, custom_value, true)
assert_equal '<a class="external" href="http://foo/bar">http://foo/bar</a>', field.format.formatted_custom_value(self, custom_value, true)
end
def test_link_field_without_url_pattern_should_link_to_value_with_http_by_default
@ -90,6 +92,6 @@ class Redmine::LinkFieldFormatTest < ActionView::TestCase
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "foo.bar")
assert_equal "foo.bar", field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo.bar">foo.bar</a>', field.format.formatted_custom_value(self, custom_value, true)
assert_equal '<a class="external" href="http://foo.bar">foo.bar</a>', field.format.formatted_custom_value(self, custom_value, true)
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -142,14 +144,14 @@ class Redmine::ListFieldFormatTest < ActionView::TestCase
def test_field_with_url_pattern_should_link_value
field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
formatted = field.format.formatted_value(self, field, 'foo', Issue.new, true)
assert_equal '<a href="http://localhost/foo">foo</a>', formatted
assert_equal '<a class="external" href="http://localhost/foo">foo</a>', formatted
assert formatted.html_safe?
end
def test_field_with_url_pattern_and_multiple_values_should_link_values
field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
formatted = field.format.formatted_value(self, field, ['foo', 'bar'], Issue.new, true)
assert_equal '<a href="http://localhost/bar">bar</a>, <a href="http://localhost/foo">foo</a>', formatted
assert_equal '<a class="external" href="http://localhost/bar">bar</a>, <a class="external" href="http://localhost/foo">foo</a>', formatted
assert formatted.html_safe?
end

View file

@ -1,35 +1,37 @@
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../test_helper', __FILE__)
require 'redmine/field_format'
class Redmine::NumericFieldFormatTest < ActionView::TestCase
include ApplicationHelper
def setup
User.current = nil
end
def test_integer_field_with_url_pattern_should_format_as_link
field = IssueCustomField.new(:field_format => 'int', :url_pattern => 'http://foo/%value%')
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "3")
assert_equal 3, field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a href="http://foo/3">3</a>', field.format.formatted_custom_value(self, custom_value, true)
end
end
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../test_helper', __FILE__)
require 'redmine/field_format'
class Redmine::NumericFieldFormatTest < ActionView::TestCase
include ApplicationHelper
def setup
User.current = nil
end
def test_integer_field_with_url_pattern_should_format_as_link
field = IssueCustomField.new(:field_format => 'int', :url_pattern => 'http://foo/%value%')
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "3")
assert_equal 3, field.format.formatted_custom_value(self, custom_value, false)
assert_equal '<a class="external" href="http://foo/3">3</a>', field.format.formatted_custom_value(self, custom_value, true)
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -22,7 +24,8 @@ class Redmine::UserFieldFormatTest < ActionView::TestCase
fixtures :projects, :roles, :users, :members, :member_roles,
:trackers,
:issue_statuses, :issue_categories, :issue_relations, :workflows,
:enumerations
:enumerations,
:custom_fields, :custom_fields_trackers, :custom_fields_projects
def setup
User.current = nil
@ -78,6 +81,15 @@ class Redmine::UserFieldFormatTest < ActionView::TestCase
assert_equal ['Dave Lopper'], field.possible_values_options(project).map(&:first)
end
def test_possible_values_options_should_return_project_members_and_me_if_logged_in
::I18n.locale = 'en'
User.current = User.find(2)
field = IssueCustomField.new(:field_format => 'user')
project = Project.find(1)
assert_equal ['<< me >>', 'Dave Lopper', 'John Smith'], field.possible_values_options(project).map(&:first)
end
def test_value_from_keyword_should_return_user_id
field = IssueCustomField.new(:field_format => 'user')
project = Project.find(1)

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -22,7 +24,8 @@ class Redmine::VersionFieldFormatTest < ActionView::TestCase
fixtures :projects, :versions, :trackers,
:roles, :users, :members, :member_roles,
:issue_statuses, :issue_categories, :issue_relations, :workflows,
:enumerations
:enumerations, :custom_fields, :custom_fields_trackers,
:enabled_modules
def setup
super
@ -70,7 +73,7 @@ class Redmine::VersionFieldFormatTest < ActionView::TestCase
assert_equal expected, field.possible_values_options(project).map(&:first)
end
def test_possible_values_options_should_return_system_shared_versions_without_project
field = IssueCustomField.new(:field_format => 'version')
version = Version.generate!(:project => Project.find(1), :status => 'open', :sharing => 'system')

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -45,7 +47,7 @@ class CalendarTest < ActiveSupport::TestCase
[1, 6, 7].each do |day|
with_settings :start_of_week => day do
c = Redmine::Helpers::Calendar.new(Date.today, :en, :month)
assert_equal day , c.startdt.cwday
assert_equal day, c.startdt.cwday
assert_equal (day + 5) % 7 + 1, c.enddt.cwday
end
end

View file

@ -1,37 +1,39 @@
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../test_helper', __FILE__)
class DiffTest < ActiveSupport::TestCase
def test_diff
diff = Redmine::Helpers::Diff.new("foo", "bar")
assert_not_nil diff
end
def test_dont_double_escape
# 3 cases to test in the before: first word, last word, everything inbetween
before = "<stuff> with html & special chars</danger>"
# all words in after are treated equal
after = "other stuff <script>alert('foo');</alert>"
computed_diff = Redmine::Helpers::Diff.new(before, after).to_html
expected_diff = '<span class="diff_in">&lt;stuff&gt; with html &amp; special chars&lt;/danger&gt;</span> <span class="diff_out">other stuff &lt;script&gt;alert(&#39;foo&#39;);&lt;/alert&gt;</span>'
assert_equal computed_diff, expected_diff
end
end
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../test_helper', __FILE__)
class DiffTest < ActiveSupport::TestCase
def test_diff
diff = Redmine::Helpers::Diff.new("foo", "bar")
assert_not_nil diff
end
def test_dont_double_escape
# 3 cases to test in the before: first word, last word, everything inbetween
before = "<stuff> with html & special chars</danger>"
# all words in after are treated equal
after = "other stuff <script>alert('foo');</alert>"
computed_diff = Redmine::Helpers::Diff.new(before, after).to_html
expected_diff = '<span class="diff_in">&lt;stuff&gt; with html &amp; special chars&lt;/danger&gt;</span> <span class="diff_out">other stuff &lt;script&gt;alert(&#39;foo&#39;);&lt;/alert&gt;</span>'
assert_equal computed_diff, expected_diff
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -18,11 +20,14 @@
require File.expand_path('../../../../../test_helper', __FILE__)
class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
fixtures :projects, :trackers, :issue_statuses,
fixtures :projects, :trackers, :projects_trackers, :issue_statuses,
:enumerations, :users, :issue_categories
include ProjectsHelper
include IssuesHelper
include QueriesHelper
include AvatarsHelper
include ERB::Util
include Rails.application.routes.url_helpers
@ -152,7 +157,8 @@ class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
setup_subjects
@output_buffer = @gantt.subjects
assert_select "div.issue-subject", /#{@issue.subject}/
assert_select 'div.issue-subject[style*="left:44px"]'
# subject 56px: 44px + 12px(collapse/expand icon's width)
assert_select 'div.issue-subject[style*="left:56px"]'
end
test "#subjects issue assigned to a shared version of another project should be rendered" do
@ -200,9 +206,10 @@ class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
assert_select 'div.issue-subject[style*="left:44px"]', /#{@issue.subject}/
# children 64px
assert_select 'div.issue-subject[style*="left:64px"]', /child1/
assert_select 'div.issue-subject[style*="left:64px"]', /child2/
# grandchild 84px
assert_select 'div.issue-subject[style*="left:84px"]', /grandchild/, @output_buffer
# children 76px: 64px + 12px(collapse/expand icon's width)
assert_select 'div.issue-subject[style*="left:76px"]', /child2/
# grandchild 96px: 84px + 12px(collapse/expand icon's width)
assert_select 'div.issue-subject[style*="left:96px"]', /grandchild/, @output_buffer
end
test "#lines" do
@ -237,6 +244,17 @@ class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
assert_select "div.tooltip", /#{@issue.subject}/
end
test "#selected_column_content" do
create_gantt
issue = Issue.generate!
@gantt.query.column_names = [:assigned_to]
issue.update(:assigned_to_id => issue.assignable_users.first.id)
@project.issues << issue
# :column => assigned_to
@output_buffer = @gantt.selected_column_content({ :column => @gantt.query.columns.last })
assert_select "div.issue_assigned_to#assigned_to_issue_#{issue.id}"
end
test "#subject_for_project" do
create_gantt
@output_buffer = @gantt.subject_for_project(@project, :format => :html)
@ -298,7 +316,8 @@ class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
test "#subject should use the indent option to move the div to the right" do
create_gantt
@output_buffer = @gantt.subject('subject', :format => :html, :indent => 40)
assert_select 'div[style*="left:40"]'
# subject 52px: 40px(indent) + 12px(collapse/expand icon's width)
assert_select 'div[style*="left:52px"]'
end
test "#line_for_project" do
@ -314,7 +333,7 @@ class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
version = Version.generate!(:name => 'Foo', :project => @project)
version.stubs(:start_date).returns(today - 7)
version.stubs(:due_date).returns(today + 7)
version.stubs(:completed_percent).returns(30)
version.stubs(:visible_fixed_issues => stub(:completed_percent => 30))
@output_buffer = @gantt.line_for_version(version, :format => :html)
assert_select "div.version.label", :text => /Foo/
assert_select "div.version.label", :text => /30%/
@ -353,6 +372,20 @@ class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
assert_select 'div.task_late[style*="width:30px"]', 1
end
test "#line late line should be the same width as task_todo if start date and end date are the same day" do
create_gantt
@output_buffer = @gantt.line(today - 7, today - 7, 0, false, 'line', :format => :html, :zoom => 4)
assert_select 'div.task_late[style*="width:2px"]', 1
assert_select 'div.task_todo[style*="width:2px"]', 1
end
test "#line late line should be the same width as task_todo if start date and today are the same day" do
create_gantt
@output_buffer = @gantt.line(today, today, 0, false, 'line', :format => :html, :zoom => 4)
assert_select 'div.task_late[style*="width:2px"]', 1
assert_select 'div.task_todo[style*="width:2px"]', 1
end
test "#line done line should start from the starting point on the left" do
create_gantt
@output_buffer = @gantt.line(today - 7, today + 7, 30, false, 'line', :format => :html, :zoom => 4)
@ -418,6 +451,20 @@ class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
assert_select "div.label", :text => 'line'
end
test "#column_content_for_issue" do
create_gantt
@gantt.query.column_names = [:assigned_to]
issue = Issue.generate!
issue.update(:assigned_to_id => issue.assignable_users.first.id)
@project.issues << issue
# :column => assigned_to
options = { :column => @gantt.query.columns.last, :top => 64, :format => :html }
@output_buffer = @gantt.column_content_for_issue(issue, options)
assert_select "div.issue_assigned_to#assigned_to_issue_#{issue.id}"
assert_includes @output_buffer, column_content(options[:column], issue)
end
def test_sort_issues_no_date
project = Project.generate!
issue1 = Issue.generate!(:subject => "test", :project => project)
@ -435,7 +482,7 @@ class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
issues = [child3, child2, child1, issue2, issue1]
Redmine::Helpers::Gantt.sort_issues!(issues)
assert_equal [issue1.id, child1.id, child3.id, child2.id, issue2.id],
issues.map{|v| v.id}
issues.map{|v| v.id}
end
def test_sort_issues_root_only
@ -449,7 +496,7 @@ class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
issues = [issue4, issue3, issue2, issue1]
Redmine::Helpers::Gantt.sort_issues!(issues)
assert_equal [issue1.id, issue2.id, issue4.id, issue3.id],
issues.map{|v| v.id}
issues.map{|v| v.id}
end
def test_sort_issues_tree
@ -458,17 +505,17 @@ class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
issue2 = Issue.generate!(:subject => "test", :project => project,
:start_date => (today - 2))
issue1_child1 =
Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child',
:project => project)
Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child',
:project => project)
issue1_child2 =
Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child',
:project => project, :start_date => (today - 10))
Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child',
:project => project, :start_date => (today - 10))
issue1_child1_child1 =
Issue.generate!(:parent_issue_id => issue1_child1.id, :subject => 'child',
:project => project, :start_date => (today - 8))
Issue.generate!(:parent_issue_id => issue1_child1.id, :subject => 'child',
:project => project, :start_date => (today - 8))
issue1_child1_child2 =
Issue.generate!(:parent_issue_id => issue1_child1.id, :subject => 'child',
:project => project, :start_date => (today - 9))
Issue.generate!(:parent_issue_id => issue1_child1.id, :subject => 'child',
:project => project, :start_date => (today - 9))
issue1_child1_child1_logic = Redmine::Helpers::Gantt.sort_issue_logic(issue1_child1_child1)
assert_equal [[today - 10, issue1.id], [today - 9, issue1_child1.id],
[today - 8, issue1_child1_child1.id]],

View file

@ -0,0 +1,36 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../test_helper', __FILE__)
class URLTest < ActiveSupport::TestCase
include Redmine::Helpers::URL
def test_uri_with_safe_scheme
assert uri_with_safe_scheme?("http://example.com/")
assert uri_with_safe_scheme?("https://example.com/")
assert uri_with_safe_scheme?("ftp://example.com/index.html")
assert uri_with_safe_scheme?("mailto:root@example.com")
end
def test_uri_with_safe_scheme_invalid_component
assert_not uri_with_safe_scheme?("httpx://example.com/")
assert_not uri_with_safe_scheme?("mailto:root@")
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -186,4 +188,3 @@ class Redmine::Hook::ManagerTest < ActionView::TestCase
@view_hook_helper ||= TestHookHelperView.new(Rails.root.to_s + '/app/views')
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -68,7 +70,7 @@ class Redmine::I18nTest < ActiveSupport::TestCase
end
assert l('date.day_names').is_a?(Array)
assert_equal 7, l('date.day_names').size
assert l('date.month_names').is_a?(Array)
assert_equal 13, l('date.month_names').size
end
@ -163,8 +165,7 @@ class Redmine::I18nTest < ActiveSupport::TestCase
set_language_if_valid 'bs'
assert_equal "KM -1000,20", number_to_currency(-1000.2)
set_language_if_valid 'de'
euro_sign = "\xe2\x82\xac".force_encoding('UTF-8')
assert_equal "-1000,20 #{euro_sign}", number_to_currency(-1000.2)
assert_equal '-1000,20 €', number_to_currency(-1000.2)
end
def test_lu_should_not_error_when_user_language_is_an_empty_string
@ -189,8 +190,7 @@ class Redmine::I18nTest < ActiveSupport::TestCase
assert_nil options.detect {|option| option.size != 2}
assert_nil options.detect {|option| !option.first.is_a?(String) || !option.last.is_a?(String)}
assert_include ["English", "en"], options
ja = "Japanese (\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e)".force_encoding('UTF-8')
assert_include [ja, "ja"], options
assert_include ['Japanese (日本語)', "ja"], options
end
def test_languages_options_should_return_strings_with_utf8_encoding
@ -241,21 +241,18 @@ class Redmine::I18nTest < ActiveSupport::TestCase
def test_utf8
set_language_if_valid 'ja'
str_ja_yes = "\xe3\x81\xaf\xe3\x81\x84".force_encoding('UTF-8')
i18n_ja_yes = l(:general_text_Yes)
assert_equal str_ja_yes, i18n_ja_yes
assert_equal 'はい', i18n_ja_yes
assert_equal "UTF-8", i18n_ja_yes.encoding.to_s
end
def test_traditional_chinese_locale
set_language_if_valid 'zh-TW'
str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)".force_encoding('UTF-8')
assert_equal str_tw, l(:general_lang_name)
assert_equal 'Chinese/Traditional (繁體中文)', l(:general_lang_name)
end
def test_french_locale
set_language_if_valid 'fr'
str_fr = "French (Fran\xc3\xa7ais)".force_encoding('UTF-8')
assert_equal str_fr, l(:general_lang_name)
assert_equal 'French (Français)', l(:general_lang_name)
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -179,13 +181,12 @@ class Redmine::MenuManager::MapperTest < ActiveSupport::TestCase
menu.push :administration, { :controller => 'projects', :action => 'show'}, {:last => true}
menu.push :help, Redmine::Info.help_url, :last => true
end
assert_nothing_raised do
Redmine::MenuManager.map :test_menu do |menu|
menu.delete(:administration)
menu.delete(:help)
menu.push :test_overview, { :controller => 'projects', :action => 'show'}, {}
end
end
end
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -27,8 +29,10 @@ class Redmine::MenuManager::MenuHelperTest < Redmine::HelperTest
def setup
setup_with_controller
# Stub the current menu item in the controller
def current_menu_item
:index
self.class_eval do
def current_menu_item
:index
end
end
end
@ -90,20 +94,21 @@ class Redmine::MenuManager::MenuHelperTest < Redmine::HelperTest
def test_render_menu_node_with_children
User.current = User.find(2)
parent_node = Redmine::MenuManager::MenuItem.new(:parent_node,
'/test',
{
:children => Proc.new {|p|
children = []
3.times do |time|
children << Redmine::MenuManager::MenuItem.new("test_child_#{time}",
{:controller => 'issues', :action => 'index'},
{})
end
children
}
})
parent_node = Redmine::MenuManager::MenuItem.new(
:parent_node,
'/test',
{
:children => Proc.new {|p|
children = []
3.times do |time|
children << Redmine::MenuManager::MenuItem.new(
"test_child_#{time}",
{:controller => 'issues', :action => 'index'},
{})
end
children
}
})
@output_buffer = render_menu_node(parent_node, Project.find(1))
assert_select("li") do
@ -131,18 +136,20 @@ class Redmine::MenuManager::MenuHelperTest < Redmine::HelperTest
}
})
parent_node << Redmine::MenuManager::MenuItem.new(:child_node,
{:controller => 'issues', :action => 'index'},
{
:children => Proc.new {|p|
children = []
6.times do |time|
children << Redmine::MenuManager::MenuItem.new("test_dynamic_child_#{time}", {:controller => 'issues', :action => 'index'}, {})
end
children
}
})
parent_node << Redmine::MenuManager::MenuItem.new(
:child_node,
{:controller => 'issues', :action => 'index'},
{
:children =>
Proc.new {|p|
children = []
6.times do |time|
children << Redmine::MenuManager::MenuItem.new(
"test_dynamic_child_#{time}", {:controller => 'issues', :action => 'index'}, {})
end
children
}
})
@output_buffer = render_menu_node(parent_node, Project.find(1))
assert_select("li") do
@ -209,9 +216,8 @@ class Redmine::MenuManager::MenuHelperTest < Redmine::HelperTest
end
end
end
def test_render_empty_virtual_menu_node_with_children
def test_render_empty_virtual_menu_node_with_children
# only empty item with no click target
Redmine::MenuManager.map :menu1 do |menu|
menu.push(:parent_node, nil, { })
@ -219,9 +225,12 @@ class Redmine::MenuManager::MenuHelperTest < Redmine::HelperTest
# parent with unallowed unattached child
Redmine::MenuManager.map :menu2 do |menu|
menu.push(:parent_node, nil, {:children => Proc.new {|p|
[Redmine::MenuManager::MenuItem.new("test_child_unallowed", {:controller => 'issues', :action => 'new'}, {})]
} })
menu.push(:parent_node, nil,
{:children => Proc.new {|p|
[Redmine::MenuManager::MenuItem.new("test_child_unallowed",
{:controller => 'issues',
:action => 'new'}, {})]
}})
end
# parent with unallowed standard child

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -22,6 +24,7 @@ class Redmine::MimeTypeTest < ActiveSupport::TestCase
def test_of
to_test = {'test.txt' => 'text/plain',
'test.c' => 'text/x-c',
'TEST.JPG' => 'image/jpeg',
}
to_test.each do |name, expected|
assert_equal expected, Redmine::MimeType.of(name)
@ -35,6 +38,7 @@ class Redmine::MimeTypeTest < ActiveSupport::TestCase
def test_css_class_of
to_test = {'test.txt' => 'text-plain',
'test.c' => 'text-x-c',
'TEST.JPG' => 'image-jpeg',
}
to_test.each do |name, expected|
assert_equal expected, Redmine::MimeType.css_class_of(name)
@ -48,6 +52,7 @@ class Redmine::MimeTypeTest < ActiveSupport::TestCase
def test_main_mimetype_of
to_test = {'test.txt' => 'text',
'test.c' => 'text',
'TEST.JPG' => 'image',
}
to_test.each do |name, expected|
assert_equal expected, Redmine::MimeType.main_mimetype_of(name)
@ -62,6 +67,7 @@ class Redmine::MimeTypeTest < ActiveSupport::TestCase
to_test = {['text', 'test.unk'] => false,
['text', 'test.txt'] => true,
['text', 'test.c'] => true,
['image', 'TEST.JPG'] => true,
}
to_test.each do |args, expected|
assert_equal expected, Redmine::MimeType.is_type?(*args)
@ -69,7 +75,7 @@ class Redmine::MimeTypeTest < ActiveSupport::TestCase
end
def test_should_default_to_mime_type_gem
assert !Redmine::MimeType::EXTENSIONS.keys.include?("zip")
assert !Redmine::MimeType::EXTENSIONS.key?("zip")
assert_equal "application/zip", Redmine::MimeType.of("file.zip")
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -20,6 +22,9 @@ require File.expand_path('../../../../test_helper', __FILE__)
class Redmine::PluginTest < ActiveSupport::TestCase
def setup
@klass = Redmine::Plugin
# Change plugin directory for testing to default
# plugins/foo => test/fixtures/plugins/foo
@klass.directory = Rails.root.join('test/fixtures/plugins')
# In case some real plugins are installed
@klass.clear
end
@ -29,7 +34,7 @@ class Redmine::PluginTest < ActiveSupport::TestCase
end
def test_register
@klass.register :foo do
@klass.register :foo_plugin do
name 'Foo plugin'
url 'http://example.net/plugins/foo'
author 'John Smith'
@ -41,9 +46,9 @@ class Redmine::PluginTest < ActiveSupport::TestCase
assert_equal 1, @klass.all.size
plugin = @klass.find('foo')
plugin = @klass.find('foo_plugin')
assert plugin.is_a?(Redmine::Plugin)
assert_equal :foo, plugin.id
assert_equal :foo_plugin, plugin.id
assert_equal 'Foo plugin', plugin.name
assert_equal 'http://example.net/plugins/foo', plugin.url
assert_equal 'John Smith', plugin.author
@ -52,15 +57,23 @@ class Redmine::PluginTest < ActiveSupport::TestCase
assert_equal '0.0.1', plugin.version
end
def test_register_should_raise_error_if_plugin_directory_does_not_exist
e = assert_raises Redmine::PluginNotFound do
@klass.register(:bar_plugin) {}
end
assert_equal "Plugin not found. The directory for plugin bar_plugin should be #{Rails.root.join('test/fixtures/plugins/bar_plugin')}.", e.message
end
def test_installed
@klass.register(:foo) {}
assert_equal true, @klass.installed?(:foo)
@klass.register(:foo_plugin) {}
assert_equal true, @klass.installed?(:foo_plugin)
assert_equal false, @klass.installed?(:bar)
end
def test_menu
assert_difference 'Redmine::MenuManager.items(:project_menu).size' do
@klass.register :foo do
@klass.register :foo_plugin do
menu :project_menu, :foo_menu_item, '/foo', :caption => 'Foo'
end
end
@ -75,7 +88,7 @@ class Redmine::PluginTest < ActiveSupport::TestCase
def test_delete_menu_item
Redmine::MenuManager.map(:project_menu).push(:foo_menu_item, '/foo', :caption => 'Foo')
assert_difference 'Redmine::MenuManager.items(:project_menu).size', -1 do
@klass.register :foo do
@klass.register :foo_plugin do
delete_menu_item :project_menu, :foo_menu_item
end
end
@ -86,18 +99,18 @@ class Redmine::PluginTest < ActiveSupport::TestCase
def test_directory_with_override
@klass.register(:foo) do
directory '/path/to/foo'
directory 'test/fixtures/plugins/foo_plugin'
end
assert_equal '/path/to/foo', @klass.find('foo').directory
assert_equal 'test/fixtures/plugins/foo_plugin', @klass.find('foo').directory
end
def test_directory_without_override
@klass.register(:foo) {}
assert_equal File.join(@klass.directory, 'foo'), @klass.find('foo').directory
@klass.register(:other_plugin) {}
assert_equal File.join(@klass.directory, 'other_plugin'), @klass.find('other_plugin').directory
end
def test_requires_redmine
plugin = Redmine::Plugin.register(:foo) {}
plugin = Redmine::Plugin.register(:foo_plugin) {}
Redmine::VERSION.stubs(:to_a).returns([2, 1, 3, "stable", 10817])
# Specific version without hash
assert plugin.requires_redmine('2.1.3')
@ -146,41 +159,50 @@ class Redmine::PluginTest < ActiveSupport::TestCase
def test_requires_redmine_plugin
test = self
other_version = '0.5.0'
@klass.register :other do
@klass.register :other_plugin do
name 'Other'
version other_version
end
@klass.register :foo do
test.assert requires_redmine_plugin(:other, :version_or_higher => '0.1.0')
test.assert requires_redmine_plugin(:other, :version_or_higher => other_version)
test.assert requires_redmine_plugin(:other, other_version)
@klass.register :foo_plugin do
test.assert requires_redmine_plugin(:other_plugin, :version_or_higher => '0.1.0')
test.assert requires_redmine_plugin(:other_plugin, :version_or_higher => other_version)
test.assert requires_redmine_plugin(:other_plugin, other_version)
test.assert_raise Redmine::PluginRequirementError do
requires_redmine_plugin(:other, :version_or_higher => '99.0.0')
requires_redmine_plugin(:other_plugin, :version_or_higher => '99.0.0')
end
test.assert requires_redmine_plugin(:other, :version => other_version)
test.assert requires_redmine_plugin(:other, :version => [other_version, '99.0.0'])
test.assert requires_redmine_plugin(:other_plugin, :version => other_version)
test.assert requires_redmine_plugin(:other_plugin, :version => [other_version, '99.0.0'])
test.assert_raise Redmine::PluginRequirementError do
requires_redmine_plugin(:other, :version => '99.0.0')
requires_redmine_plugin(:other_plugin, :version => '99.0.0')
end
test.assert_raise Redmine::PluginRequirementError do
requires_redmine_plugin(:other, :version => ['98.0.0', '99.0.0'])
requires_redmine_plugin(:other_plugin, :version => ['98.0.0', '99.0.0'])
end
# Missing plugin
test.assert_raise Redmine::PluginNotFound do
test.assert_raise Redmine::PluginRequirementError do
requires_redmine_plugin(:missing, :version_or_higher => '0.1.0')
end
test.assert_raise Redmine::PluginNotFound do
test.assert_raise Redmine::PluginRequirementError do
requires_redmine_plugin(:missing, '0.1.0')
end
test.assert_raise Redmine::PluginNotFound do
test.assert_raise Redmine::PluginRequirementError do
requires_redmine_plugin(:missing, :version => '0.1.0')
end
end
end
def test_settings_warns_about_possible_partial_collision
@klass.register(:foo) { settings :partial => 'foo/settings' }
@klass.register(:foo_plugin) { settings :partial => 'foo/settings' }
Rails.logger.expects(:warn)
@klass.register(:bar) { settings :partial => 'foo/settings' }
@klass.register(:other_plugin) { settings :partial => 'foo/settings' }
end
def test_migrate_redmine_plugin
@klass.register :foo_plugin do
name 'Foo plugin'
version '0.0.1'
end
assert Redmine::Plugin.migrate('foo_plugin')
end
end

View file

@ -0,0 +1,145 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../test_helper', __FILE__)
class Redmine::ProjectJumpBoxTest < ActiveSupport::TestCase
fixtures :users, :projects, :user_preferences
def setup
@user = User.find_by_login 'dlopper'
@ecookbook = Project.find 'ecookbook'
@onlinestore = Project.find 'onlinestore'
end
def test_should_filter_bookmarked_projects
pjb = Redmine::ProjectJumpBox.new @user
pjb.bookmark_project @ecookbook
assert_equal 1, pjb.bookmarked_projects.size
assert_equal 0, pjb.bookmarked_projects('online').size
assert_equal 1, pjb.bookmarked_projects('ecook').size
end
def test_should_not_include_bookmark_in_recently_used_list
pjb = Redmine::ProjectJumpBox.new @user
pjb.project_used @ecookbook
assert_equal 1, pjb.recently_used_projects.size
pjb.bookmark_project @ecookbook
assert_equal 0, pjb.recently_used_projects.size
end
def test_should_filter_recently_used_projects
pjb = Redmine::ProjectJumpBox.new @user
pjb.project_used @ecookbook
assert_equal 1, pjb.recently_used_projects.size
assert_equal 0, pjb.recently_used_projects('online').size
assert_equal 1, pjb.recently_used_projects('ecook').size
end
def test_should_limit_recently_used_projects
pjb = Redmine::ProjectJumpBox.new @user
pjb.project_used @ecookbook
pjb.project_used Project.find 'onlinestore'
@user.pref.recently_used_projects = 1
assert_equal 1, pjb.recently_used_projects.size
assert_equal 1, pjb.recently_used_projects('online').size
assert_equal 0, pjb.recently_used_projects('ecook').size
end
def test_should_record_recently_used_projects_order
pjb = Redmine::ProjectJumpBox.new @user
other = Project.find 'onlinestore'
pjb.project_used @ecookbook
pjb.project_used other
pjb = Redmine::ProjectJumpBox.new @user
assert_equal 2, pjb.recently_used_projects.size
assert_equal [other, @ecookbook], pjb.recently_used_projects
pjb.project_used other
pjb = Redmine::ProjectJumpBox.new @user
assert_equal 2, pjb.recently_used_projects.size
assert_equal [other, @ecookbook], pjb.recently_used_projects
pjb.project_used @ecookbook
pjb = Redmine::ProjectJumpBox.new @user
assert_equal 2, pjb.recently_used_projects.size
assert_equal [@ecookbook, other], pjb.recently_used_projects
end
def test_should_unbookmark_project
pjb = Redmine::ProjectJumpBox.new @user
assert pjb.bookmarked_projects.blank?
# same instance should reflect new data
pjb.bookmark_project @ecookbook
assert pjb.bookmark?(@ecookbook)
refute pjb.bookmark?(@onlinestore)
assert_equal 1, pjb.bookmarked_projects.size
assert_equal @ecookbook, pjb.bookmarked_projects.first
# new instance should reflect new data as well
pjb = Redmine::ProjectJumpBox.new @user
assert pjb.bookmark?(@ecookbook)
refute pjb.bookmark?(@onlinestore)
assert_equal 1, pjb.bookmarked_projects.size
assert_equal @ecookbook, pjb.bookmarked_projects.first
pjb.bookmark_project @ecookbook
pjb = Redmine::ProjectJumpBox.new @user
assert_equal 1, pjb.bookmarked_projects.size
assert_equal @ecookbook, pjb.bookmarked_projects.first
pjb.delete_project_bookmark @onlinestore
pjb = Redmine::ProjectJumpBox.new @user
assert_equal 1, pjb.bookmarked_projects.size
assert_equal @ecookbook, pjb.bookmarked_projects.first
pjb.delete_project_bookmark @ecookbook
pjb = Redmine::ProjectJumpBox.new @user
assert pjb.bookmarked_projects.blank?
end
def test_should_update_recents_list
pjb = Redmine::ProjectJumpBox.new @user
assert pjb.recently_used_projects.blank?
pjb.project_used @ecookbook
pjb = Redmine::ProjectJumpBox.new @user
assert_equal 1, pjb.recently_used_projects.size
assert_equal @ecookbook, pjb.recently_used_projects.first
pjb.project_used @ecookbook
pjb = Redmine::ProjectJumpBox.new @user
assert_equal 1, pjb.recently_used_projects.size
assert_equal @ecookbook, pjb.recently_used_projects.first
pjb.project_used @onlinestore
assert_equal 2, pjb.recently_used_projects.size
assert_equal @onlinestore, pjb.recently_used_projects.first
assert_equal @ecookbook, pjb.recently_used_projects.last
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,60 +0,0 @@
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../../test_helper', __FILE__)
class DarcsAdapterTest < ActiveSupport::TestCase
REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
if File.directory?(REPOSITORY_PATH)
def setup
@adapter = Redmine::Scm::Adapters::DarcsAdapter.new(REPOSITORY_PATH)
end
def test_darcsversion
to_test = { "1.0.9 (release)\n" => [1,0,9] ,
"2.2.0 (release)\n" => [2,2,0] }
to_test.each do |s, v|
test_darcsversion_for(s, v)
end
end
def test_revisions
id1 = '20080308225258-98289-761f654d669045eabee90b91b53a21ce5593cadf.gz'
revs = @adapter.revisions('', nil, nil, {:with_path => true})
assert_equal 6, revs.size
assert_equal id1, revs[5].scmid
paths = revs[5].paths
assert_equal 5, paths.size
assert_equal 'A', paths[0][:action]
assert_equal '/README', paths[0][:path]
assert_equal 'A', paths[1][:action]
assert_equal '/images', paths[1][:path]
end
private
def test_darcsversion_for(darcsversion, version)
@adapter.class.expects(:darcs_binary_version_from_command_line).returns(darcsversion)
assert_equal version, @adapter.class.darcs_binary_version
end
else
puts "Darcs test repository NOT FOUND. Skipping unit tests !!!"
def test_fake; assert true end
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -35,8 +37,9 @@ class FilesystemAdapterTest < ActiveSupport::TestCase
end
# If y try to use "..", the path is ignored
["/../","dir/../", "..", "../", "/..", "dir/.."].each do |path|
assert_equal ["dir", "japanese", "test"], @adapter.entries(path).collect(&:name),
".. must be ignored in path argument"
assert_equal(
["dir", "japanese", "test"], @adapter.entries(path).collect(&:name),
".. must be ignored in path argument")
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -20,9 +22,6 @@ require File.expand_path('../../../../../../test_helper', __FILE__)
class GitAdapterTest < ActiveSupport::TestCase
REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
FELIX_HEX = "Felix Sch\xC3\xA4fer"
CHAR_1_HEX = "\xc3\x9c"
## Git, Mercurial and CVS path encodings are binary.
## Subversion supports URL encoding for path.
## Redmine Mercurial adapter and extension use URL encoding.
@ -58,8 +57,8 @@ class GitAdapterTest < ActiveSupport::TestCase
'ISO-8859-1'
)
assert @adapter
@char_1 = CHAR_1_HEX.dup.force_encoding('UTF-8')
@str_felix_hex = FELIX_HEX.dup.force_encoding('ASCII-8BIT')
@char_1 = 'Ü'
@str_felix_hex = "Felix Sch\xC3\xA4fer".b
end
def test_scm_version
@ -76,23 +75,33 @@ class GitAdapterTest < ActiveSupport::TestCase
@adapter.branches.each do |b|
brs << b
end
assert_equal 6, brs.length
assert_equal 8, brs.length
br_issue_8857 = brs[0]
assert_equal 'issue-8857', br_issue_8857.to_s
assert_equal 'issue-8857', br_issue_8857.to_s
assert_equal '2a682156a3b6e77a8bf9cd4590e8db757f3c6c78', br_issue_8857.revision
assert_equal br_issue_8857.scmid, br_issue_8857.revision
assert_equal false, br_issue_8857.is_default
br_latin_1_path = brs[1]
assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s
br_latin_1_branch1 = brs[1]
assert_equal "latin-1-branch-#{@char_1}-01", br_latin_1_branch1.to_s
assert_equal '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', br_latin_1_branch1.revision
assert_equal br_latin_1_branch1.scmid, br_latin_1_branch1.revision
assert_equal false, br_latin_1_branch1.is_default
br_latin_1_branch2 = brs[2]
assert_equal "latin-1-branch-#{@char_1}-02", br_latin_1_branch2.to_s
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', br_latin_1_branch2.revision
assert_equal br_latin_1_branch2.scmid, br_latin_1_branch2.revision
assert_equal false, br_latin_1_branch2.is_default
br_latin_1_path = brs[3]
assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', br_latin_1_path.revision
assert_equal br_latin_1_path.scmid, br_latin_1_path.revision
assert_equal false, br_latin_1_path.is_default
br_master = brs[2]
br_master = brs[4]
assert_equal 'master', br_master.to_s
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master.revision
assert_equal br_master.scmid, br_master.revision
assert_equal false, br_master.is_default
br_master_20120212 = brs[3]
br_master_20120212 = brs[5]
assert_equal 'master-20120212', br_master_20120212.to_s
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master_20120212.revision
assert_equal br_master_20120212.scmid, br_master_20120212.revision
@ -114,9 +123,10 @@ class GitAdapterTest < ActiveSupport::TestCase
end
def test_tags
assert_equal [
assert_equal [
"tag00.lightweight",
"tag01.annotated",
"tag02.lightweight.#{@char_1}.01",
], @adapter.tags
end
@ -126,7 +136,7 @@ class GitAdapterTest < ActiveSupport::TestCase
revs1 << rev
end
assert_equal 15, revs1.length
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 0].identifier
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[0].identifier
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier
revs2 = []
@ -136,7 +146,7 @@ class GitAdapterTest < ActiveSupport::TestCase
end
assert_equal 15, revs2.length
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[0].identifier
end
def test_revisions_master_merged_rev
@ -148,12 +158,12 @@ class GitAdapterTest < ActiveSupport::TestCase
revs1 << rev
end
assert_equal 8, revs1.length
assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', revs1[ 0].identifier
assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 1].identifier
assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', revs1[0].identifier
assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[1].identifier
# 4a07fe31b is not a child of 713f49446
assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 2].identifier
assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[2].identifier
# Merged revision
assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 3].identifier
assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[3].identifier
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
revs2 = []
@ -164,11 +174,11 @@ class GitAdapterTest < ActiveSupport::TestCase
revs2 << rev
end
assert_equal 7, revs2.length
assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs2[ 0].identifier
assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs2[0].identifier
# 4a07fe31b is not a child of fba357b8869
assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs2[ 1].identifier
assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs2[1].identifier
# Merged revision
assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs2[ 2].identifier
assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs2[2].identifier
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier
end
@ -178,7 +188,7 @@ class GitAdapterTest < ActiveSupport::TestCase
revs1 << rev
end
assert_equal 8, revs1.length
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[ 0].identifier
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[0].identifier
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier
revs2 = []
@ -188,7 +198,7 @@ class GitAdapterTest < ActiveSupport::TestCase
end
assert_equal 8, revs2.length
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[0].identifier
end
def test_revisions_branch_latin_1_path_encoding_with_rev
@ -200,7 +210,7 @@ class GitAdapterTest < ActiveSupport::TestCase
revs1 << rev
end
assert_equal 7, revs1.length
assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 0].identifier
assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[0].identifier
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier
revs2 = []
@ -211,15 +221,36 @@ class GitAdapterTest < ActiveSupport::TestCase
revs2 << rev
end
assert_equal 3, revs2.length
assert_equal '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', revs2[ 0].identifier
assert_equal '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', revs2[0].identifier
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier
end
def test_revisions_latin_1_identifier
if WINDOWS_PASS
puts WINDOWS_SKIP_STR
elsif JRUBY_SKIP
puts JRUBY_SKIP_STR
else
revs1 = []
@adapter.revisions(
'',
"latin-1-branch-#{@char_1}-01",
"latin-1-branch-#{@char_1}-02",
{:reverse => true}) do |rev|
revs1 << rev
end
end
assert_equal 2, revs1.length
assert_equal '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', revs1[0].identifier
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[1].identifier
end
def test_revisions_invalid_rev
assert_equal [], @adapter.revisions('', '1234abcd', "master")
assert_raise Redmine::Scm::Adapters::CommandFailed do
revs1 = []
@adapter.revisions('',
@adapter.revisions(
'',
'1234abcd',
"master",
{:reverse => true}) do |rev|
@ -237,7 +268,7 @@ class GitAdapterTest < ActiveSupport::TestCase
revs1 << rev
end
assert_equal 2, revs1.length
assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier
assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[0].identifier
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
end
@ -250,8 +281,8 @@ class GitAdapterTest < ActiveSupport::TestCase
revs1 << rev
end
assert_equal 2, revs1.length
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[ 0].identifier
assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 1].identifier
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[0].identifier
assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[1].identifier
end
def test_revisions_includes_merged_revs
@ -263,9 +294,9 @@ class GitAdapterTest < ActiveSupport::TestCase
revs1 << rev
end
assert_equal 7, revs1.length
assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 0].identifier
assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 1].identifier
assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 2].identifier
assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[0].identifier
assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[1].identifier
assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[2].identifier
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
end
@ -280,8 +311,8 @@ class GitAdapterTest < ActiveSupport::TestCase
revs1 << rev
end
assert_equal 4, revs1.length
assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier
assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[0].identifier
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[1].identifier
assert_equal '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', revs1[-2].identifier
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier
end
@ -297,8 +328,8 @@ class GitAdapterTest < ActiveSupport::TestCase
revs1 << rev
end
assert_equal 4, revs1.length
assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier
assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[0].identifier
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[1].identifier
assert_equal 'bc201c95999c4f10d018b0aa03b541cd6a2ff0ee', revs1[-2].identifier
assert_equal '92397af84d22f27389c822848ecd5b463c181583', revs1[-1].identifier
end
@ -352,15 +383,18 @@ class GitAdapterTest < ActiveSupport::TestCase
end
def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
assert_equal " filename with a leading space.txt ",
assert_equal(
" filename with a leading space.txt ",
@adapter.revisions(" filename with a leading space.txt ",
nil, "master")[0].paths[0][:path]
nil, "master")[0].paths[0][:path])
end
def test_getting_entries_with_leading_and_trailing_spaces_in_filename
assert_equal " filename with a leading space.txt ",
@adapter.entries('',
'83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
assert_equal(
" filename with a leading space.txt ",
@adapter.entries(
'',
'83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name)
end
def test_annotate
@ -370,10 +404,27 @@ class GitAdapterTest < ActiveSupport::TestCase
assert_equal "# This program is free software; you can redistribute it and/or",
annotate.lines[4].strip
assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
annotate.revisions[4].identifier
annotate.revisions[4].identifier
assert_equal "jsmith", annotate.revisions[4].author
end
def test_annotate_latin_1_identifier
if WINDOWS_PASS
puts WINDOWS_SKIP_STR
elsif JRUBY_SKIP
puts JRUBY_SKIP_STR
else
annotate = @adapter.annotate('sources/watchers_controller.rb',
"latin-1-branch-#{@char_1}-02")
assert_equal 40, annotate.lines.size
assert_equal "# This program is free software; you can redistribute it and/or",
annotate.lines[3].strip
assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
annotate.revisions[3].identifier
assert_equal "jsmith", annotate.revisions[3].author
end
end
def test_annotate_moved_file
annotate = @adapter.annotate('renamed_test.txt')
assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
@ -392,11 +443,10 @@ class GitAdapterTest < ActiveSupport::TestCase
def test_last_rev_with_spaces_in_filename
last_rev = @adapter.lastrev("filemane with spaces.txt",
"ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
last_rev_author = last_rev.author
assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
assert_equal "#{@str_felix_hex} <felix@fachschaften.org>",
last_rev.author
last_rev.author
assert_equal Time.gm(2010, 9, 18, 19, 59, 46), last_rev.time
end
@ -509,6 +559,23 @@ class GitAdapterTest < ActiveSupport::TestCase
end
end
def test_entries_latin_1_identifier
if WINDOWS_PASS
puts WINDOWS_SKIP_STR
elsif JRUBY_SKIP
puts JRUBY_SKIP_STR
else
entries1 = @adapter.entries(nil,
"latin-1-branch-#{@char_1}-02")
assert entries1
assert_equal 4, entries1.size
f1 = entries1[0]
assert_equal "images", f1.name
assert_equal "images", f1.path
assert_equal 'dir', f1.kind
end
end
def test_entry
entry = @adapter.entry()
assert_equal "", entry.path
@ -555,6 +622,17 @@ class GitAdapterTest < ActiveSupport::TestCase
assert_equal "UTF-8", adpt2.path_encoding
end
def test_cat_latin_1_identifier
if WINDOWS_PASS
puts WINDOWS_SKIP_STR
elsif JRUBY_SKIP
puts JRUBY_SKIP_STR
else
assert @adapter.cat('sources/watchers_controller.rb',
"latin-1-branch-#{@char_1}-02")
end
end
def test_cat_path_invalid
assert_nil @adapter.cat('invalid')
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -25,7 +27,6 @@ class MercurialAdapterTest < ActiveSupport::TestCase
HgCommandArgumentError = Redmine::Scm::Adapters::MercurialAdapter::HgCommandArgumentError
REPOSITORY_PATH = repository_path('mercurial')
CHAR_1_HEX = "\xc3\x9c"
if File.directory?(REPOSITORY_PATH)
def setup
@ -40,12 +41,12 @@ class MercurialAdapterTest < ActiveSupport::TestCase
nil,
nil,
nil,
'ISO-8859-1')
'ISO-8859-1')
@diff_c_support = true
@char_1 = CHAR_1_HEX.dup.force_encoding('UTF-8')
@tag_char_1 = "tag-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
@branch_char_0 = "branch-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
@branch_char_1 = "branch-#{CHAR_1_HEX}-01".force_encoding('UTF-8')
@char_1 = 'Ü'
@tag_char_1 = 'tag-Ü-00'
@branch_char_0 = 'branch-Ü-00'
@branch_char_1 = 'branch-Ü-01'
end
def test_hgversion
@ -79,7 +80,7 @@ class MercurialAdapterTest < ActiveSupport::TestCase
def test_info
[REPOSITORY_PATH, REPOSITORY_PATH + "/",
REPOSITORY_PATH + "//"].each do |repo|
REPOSITORY_PATH + "//"].each do |repo|
adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo)
repo_path = adp.info.root_url.gsub(/\\/, "/")
assert_equal REPOSITORY_PATH, repo_path
@ -404,25 +405,26 @@ class MercurialAdapterTest < ActiveSupport::TestCase
@branch_char_0,
'test_branch.latin-1',
'test-branch-00',
].each do |bra|
nib0 = @adapter.nodes_in_branch(bra)
]
.each do |branch|
nib0 = @adapter.nodes_in_branch(branch)
assert nib0
nib1 = @adapter.nodes_in_branch(bra, :limit => 1)
nib1 = @adapter.nodes_in_branch(branch, :limit => 1)
assert_equal 1, nib1.size
case bra
when 'branch (1)[2]&,%.-3_4'
case branch
when 'branch (1)[2]&,%.-3_4'
if @adapter.class.client_version_above?([1, 6])
assert_equal 3, nib0.size
assert_equal 'afc61e85bde74de930e5846c8451bd55b5bafc9c', nib0[0]
nib2 = @adapter.nodes_in_branch(bra, :limit => 2)
nib2 = @adapter.nodes_in_branch(branch, :limit => 2)
assert_equal 2, nib2.size
assert_equal '933ca60293d78f7c7979dd123cc0c02431683575', nib2[1]
end
when @branch_char_1
when @branch_char_1
if @adapter.class.client_version_above?([1, 6])
assert_equal 2, nib0.size
assert_equal '08ff3227303ec0dfcc818efa8e9cc652fe81859f', nib0[1]
nib2 = @adapter.nodes_in_branch(bra, :limit => 1)
nib2 = @adapter.nodes_in_branch(branch, :limit => 1)
assert_equal 1, nib2.size
assert_equal '7bbf4c738e7145149d2e5eb1eed1d3a8ddd3b914', nib2[0]
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,37 +0,0 @@
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../test_helper', __FILE__)
class Redmine::SyntaxHighlighting::CodeRayTest < ActiveSupport::TestCase
def test_retrieve_supported_languages_should_return_array_of_symbols
assert_kind_of Array, Redmine::SyntaxHighlighting::CodeRay.send(:retrieve_supported_languages)
assert_kind_of Symbol, Redmine::SyntaxHighlighting::CodeRay.send(:retrieve_supported_languages).first
end
def test_retrieve_supported_languages_should_return_array_of_symbols_holding_languages
assert_includes Redmine::SyntaxHighlighting::CodeRay.send(:retrieve_supported_languages), :ruby
end
def test_retrieve_supported_languages_should_return_array_of_symbols_holding_languages_aliases
assert_includes Redmine::SyntaxHighlighting::CodeRay.send(:retrieve_supported_languages), :javascript
end
def test_retrieve_supported_languages_should_return_array_of_symbols_not_holding_internal_languages
refute_includes Redmine::SyntaxHighlighting::CodeRay.send(:retrieve_supported_languages), :default
end
end

View file

@ -0,0 +1,65 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../../../test_helper', __FILE__)
class Redmine::SyntaxHighlighting::RougeTest < ActiveSupport::TestCase
def test_filename_supported
to_test = {
'application.js' => true,
'Gemfile' => true,
'HELLO.CBL' => false, # Rouge does not support COBOL
'HELLO.C' => true
}
to_test.each do |filename, expected|
assert_equal expected, Redmine::SyntaxHighlighting::Rouge.filename_supported?(filename)
end
end
def test_highlight_by_filename_should_distinguish_perl_and_prolog
raw_perl = <<~'RAW_PERL'
#!/usr/bin/perl
print "Hello, world!\n";
RAW_PERL
expected_perl = <<~'EXPECTED_PERL'
<span class="c1">#!/usr/bin/perl</span>
<span class="k">print</span> <span class="p">"</span><span class="s2">Hello, world!</span><span class="se">\n</span><span class="p">";</span>
EXPECTED_PERL
raw_prolog = <<~'RAW_PROLOG'
#!/usr/bin/swipl
:- writeln('Hello, world!'),halt.
RAW_PROLOG
expected_prolog = <<~'EXPECTED_PROLOG'
<span class="c1">#!/usr/bin/swipl</span>
<span class="p">:-</span> <span class="ss">writeln</span><span class="p">(</span><span class="ss">'Hello, world!'</span><span class="p">),</span><span class="ss">halt</span><span class="p">.</span>
EXPECTED_PROLOG
filename = 'hello.pl'
# Rouge cannot distinguish between Perl and Prolog by filename alone
assert_raises Rouge::Guesser::Ambiguous do
Rouge::Lexer.guess(:filename => filename)
end
assert_equal Rouge::Lexers::Perl, Rouge::Lexer.guess(:filename => filename, :source => raw_perl)
assert_equal Rouge::Lexers::Prolog, Rouge::Lexer.guess(:filename => filename, :source => raw_prolog)
assert_equal expected_perl, Redmine::SyntaxHighlighting::Rouge.highlight_by_filename(raw_perl, filename)
assert_equal expected_prolog, Redmine::SyntaxHighlighting::Rouge.highlight_by_filename(raw_prolog, filename)
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -88,17 +90,16 @@ class Redmine::UnifiedDiffTest < ActiveSupport::TestCase
end
def test_partials_with_html_entities
raw = <<-DIFF
--- test.orig.txt Wed Feb 15 16:10:39 2012
+++ test.new.txt Wed Feb 15 16:11:25 2012
@@ -1,5 +1,5 @@
Semicolons were mysteriously appearing in code diffs in the repository
-void DoSomething(std::auto_ptr<MyClass> myObj)
+void DoSomething(const MyClass& myObj)
DIFF
raw = <<~DIFF
--- test.orig.txt Wed Feb 15 16:10:39 2012
+++ test.new.txt Wed Feb 15 16:11:25 2012
@@ -1,5 +1,5 @@
Semicolons were mysteriously appearing in code diffs in the repository
-void DoSomething(std::auto_ptr<MyClass> myObj)
+void DoSomething(const MyClass& myObj)
DIFF
diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs')
assert_equal 1, diff.size
assert_equal 'void DoSomething(<span>std::auto_ptr&lt;MyClass&gt;</span> myObj)', diff.first[2].html_line_left
@ -111,147 +112,187 @@ DIFF
end
def test_line_starting_with_dashes
diff = Redmine::UnifiedDiff.new(<<-DIFF
--- old.txt Wed Nov 11 14:24:58 2009
+++ new.txt Wed Nov 11 14:25:02 2009
@@ -1,8 +1,4 @@
-Lines that starts with dashes:
-
-------------------------
--- file.c
-------------------------
+A line that starts with dashes:
and removed.
@@ -23,4 +19,4 @@
-Another chunk of change
+Another chunk of changes
diff = Redmine::UnifiedDiff.new(<<~DIFF)
--- old.txt Wed Nov 11 14:24:58 2009
+++ new.txt Wed Nov 11 14:25:02 2009
@@ -1,8 +1,4 @@
-Lines that starts with dashes:
-
-------------------------
--- file.c
-------------------------
+A line that starts with dashes:
DIFF
)
and removed.
@@ -23,4 +19,4 @@
-Another chunk of change
+Another chunk of changes
DIFF
assert_equal 1, diff.size
end
def test_one_line_new_files
diff = Redmine::UnifiedDiff.new(<<-DIFF
diff -r 000000000000 -r ea98b14f75f0 README1
--- /dev/null
+++ b/README1
@@ -0,0 +1,1 @@
+test1
diff -r 000000000000 -r ea98b14f75f0 README2
--- /dev/null
+++ b/README2
@@ -0,0 +1,1 @@
+test2
diff -r 000000000000 -r ea98b14f75f0 README3
--- /dev/null
+++ b/README3
@@ -0,0 +1,3 @@
+test4
+test5
+test6
diff -r 000000000000 -r ea98b14f75f0 README4
--- /dev/null
+++ b/README4
@@ -0,0 +1,3 @@
+test4
+test5
+test6
DIFF
)
diff = Redmine::UnifiedDiff.new(<<~DIFF)
diff -r 000000000000 -r ea98b14f75f0 README1
--- /dev/null
+++ b/README1
@@ -0,0 +1,1 @@
+test1
diff -r 000000000000 -r ea98b14f75f0 README2
--- /dev/null
+++ b/README2
@@ -0,0 +1,1 @@
+test2
diff -r 000000000000 -r ea98b14f75f0 README3
--- /dev/null
+++ b/README3
@@ -0,0 +1,3 @@
+test4
+test5
+test6
diff -r 000000000000 -r ea98b14f75f0 README4
--- /dev/null
+++ b/README4
@@ -0,0 +1,3 @@
+test4
+test5
+test6
DIFF
assert_equal 4, diff.size
assert_equal "README1", diff[0].file_name
end
def test_both_git_diff
diff = Redmine::UnifiedDiff.new(<<-DIFF
# HG changeset patch
# User test
# Date 1348014182 -32400
# Node ID d1c871b8ef113df7f1c56d41e6e3bfbaff976e1f
# Parent 180b6605936cdc7909c5f08b59746ec1a7c99b3e
modify test1.txt
diff = Redmine::UnifiedDiff.new(<<~DIFF)
# HG changeset patch
# User test
# Date 1348014182 -32400
# Node ID d1c871b8ef113df7f1c56d41e6e3bfbaff976e1f
# Parent 180b6605936cdc7909c5f08b59746ec1a7c99b3e
modify test1.txt
diff -r 180b6605936c -r d1c871b8ef11 test1.txt
--- a/test1.txt
+++ b/test1.txt
@@ -1,1 +1,1 @@
-test1
+modify test1
DIFF
)
diff -r 180b6605936c -r d1c871b8ef11 test1.txt
--- a/test1.txt
+++ b/test1.txt
@@ -1,1 +1,1 @@
-test1
+modify test1
DIFF
assert_equal 1, diff.size
assert_equal "test1.txt", diff[0].file_name
end
def test_previous_file_name_with_git
diff = Redmine::UnifiedDiff.new(<<~DIFF)
From 585da9683fb5ed7bf7cb438492e3347cdf3d83df Mon Sep 17 00:00:00 2001
From: Gregor Schmidt <schmidt@nach-vorne.eu>
Date: Mon, 5 Mar 2018 14:12:13 +0100
Subject: [PATCH] changes including a rename, rename+modify and addition
---
one.markdown => one.md | 0
three.md | 2 ++
two.markdown => two.md | 1 +
3 files changed, 3 insertions(+)
rename one.markdown => one.md (100%)
create mode 100644 three.md
rename two.markdown => two.md (50%)
diff --git a/one.markdown b/one.md
similarity index 100%
rename from one.markdown
rename to one.md
diff --git a/three.md b/three.md
new file mode 100644
index 0000000..288012f
--- /dev/null
+++ b/three.md
@@ -0,0 +1,2 @@
+three
+=====
diff --git a/two.markdown b/two.md
similarity index 50%
rename from two.markdown
rename to two.md
index f719efd..6a268ed 100644
--- a/two.markdown
+++ b/two.md
@@ -1 +1,2 @@
two
+===
--
2.14.1
DIFF
assert_equal 2, diff.size
assert_equal "three.md", diff[0].file_name
assert_nil diff[0].previous_file_name
assert_equal "two.md", diff[1].file_name
assert_equal "two.markdown", diff[1].previous_file_name
end
def test_include_a_b_slash
diff = Redmine::UnifiedDiff.new(<<-DIFF
--- test1.txt
+++ b/test02.txt
@@ -1 +0,0 @@
-modify test1
DIFF
)
diff = Redmine::UnifiedDiff.new(<<~DIFF)
--- test1.txt
+++ b/test02.txt
@@ -1 +0,0 @@
-modify test1
DIFF
assert_equal 1, diff.size
assert_equal "b/test02.txt", diff[0].file_name
diff = Redmine::UnifiedDiff.new(<<-DIFF
--- a/test1.txt
+++ a/test02.txt
@@ -1 +0,0 @@
-modify test1
DIFF
)
diff = Redmine::UnifiedDiff.new(<<~DIFF)
--- a/test1.txt
+++ a/test02.txt
@@ -1 +0,0 @@
-modify test1
DIFF
assert_equal 1, diff.size
assert_equal "a/test02.txt", diff[0].file_name
diff = Redmine::UnifiedDiff.new(<<-DIFF
--- a/test1.txt
+++ test02.txt
@@ -1 +0,0 @@
-modify test1
DIFF
)
diff = Redmine::UnifiedDiff.new(<<~DIFF)
--- a/test1.txt
+++ test02.txt
@@ -1 +0,0 @@
-modify test1
DIFF
assert_equal 1, diff.size
assert_equal "test02.txt", diff[0].file_name
end
def test_utf8_ja
ja = " text_tip_issue_end_day: "
ja += "\xe3\x81\x93\xe3\x81\xae\xe6\x97\xa5\xe3\x81\xab\xe7\xb5\x82\xe4\xba\x86\xe3\x81\x99\xe3\x82\x8b<span>\xe3\x82\xbf\xe3\x82\xb9\xe3\x82\xaf</span>".force_encoding('UTF-8')
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(read_diff_fixture('issue-12641-ja.diff'), :type => 'inline')
assert_equal 1, diff.size
assert_equal 12, diff.first.size
assert_equal ja, diff.first[4].html_line_left
assert_equal ' text_tip_issue_end_day: この日に終了する<span>タスク</span>', diff.first[4].html_line_left
end
end
def test_utf8_ru
ru = " other: &quot;\xd0\xbe\xd0\xba\xd0\xbe\xd0\xbb\xd0\xbe %{count} \xd1\x87\xd0\xb0\xd1\x81<span>\xd0\xb0</span>&quot;".force_encoding('UTF-8')
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(read_diff_fixture('issue-12641-ru.diff'), :type => 'inline')
assert_equal 1, diff.size
assert_equal 8, diff.first.size
assert_equal ru, diff.first[3].html_line_left
assert_equal ' other: &quot;около %{count} час<span>а</span>&quot;', diff.first[3].html_line_left
end
end
def test_offset_range_ascii_1
raw = <<-DIFF
--- a.txt 2013-04-05 14:19:39.000000000 +0900
+++ b.txt 2013-04-05 14:19:51.000000000 +0900
@@ -1,3 +1,3 @@
aaaa
-abc
+abcd
bbbb
DIFF
raw = <<~DIFF
--- a.txt 2013-04-05 14:19:39.000000000 +0900
+++ b.txt 2013-04-05 14:19:51.000000000 +0900
@@ -1,3 +1,3 @@
aaaa
-abc
+abcd
bbbb
DIFF
diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs')
assert_equal 1, diff.size
assert_equal 3, diff.first.size
@ -260,15 +301,15 @@ DIFF
end
def test_offset_range_ascii_2
raw = <<-DIFF
--- a.txt 2013-04-05 14:19:39.000000000 +0900
+++ b.txt 2013-04-05 14:19:51.000000000 +0900
@@ -1,3 +1,3 @@
aaaa
-abc
+zabc
bbbb
DIFF
raw = <<~DIFF
--- a.txt 2013-04-05 14:19:39.000000000 +0900
+++ b.txt 2013-04-05 14:19:51.000000000 +0900
@@ -1,3 +1,3 @@
aaaa
-abc
+zabc
bbbb
DIFF
diff = Redmine::UnifiedDiff.new(raw, :type => 'sbs')
assert_equal 1, diff.size
assert_equal 3, diff.first.size
@ -277,70 +318,60 @@ DIFF
end
def test_offset_range_japanese_1
ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span></span>".force_encoding('UTF-8')
ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x9e</span>".force_encoding('UTF-8')
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(
read_diff_fixture('issue-13644-1.diff'), :type => 'sbs')
assert_equal 1, diff.size
assert_equal 3, diff.first.size
assert_equal ja1, diff.first[1].html_line_left
assert_equal ja2, diff.first[1].html_line_right
assert_equal '日本<span></span>', diff.first[1].html_line_left
assert_equal '日本<span>語</span>', diff.first[1].html_line_right
end
end
def test_offset_range_japanese_2
ja1 = "<span></span>\xe6\x97\xa5\xe6\x9c\xac".force_encoding('UTF-8')
ja2 = "<span>\xe3\x81\xab\xe3\x81\xa3\xe3\x81\xbd\xe3\x82\x93</span>\xe6\x97\xa5\xe6\x9c\xac".force_encoding('UTF-8')
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(
read_diff_fixture('issue-13644-2.diff'), :type => 'sbs')
assert_equal 1, diff.size
assert_equal 3, diff.first.size
assert_equal ja1, diff.first[1].html_line_left
assert_equal ja2, diff.first[1].html_line_right
assert_equal '<span></span>日本', diff.first[1].html_line_left
assert_equal '<span>にっぽん</span>日本', diff.first[1].html_line_right
end
end
def test_offset_range_japanese_3
# UTF-8 The 1st byte differs.
ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>".force_encoding('UTF-8')
ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe5\xa8\x98</span>".force_encoding('UTF-8')
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(
read_diff_fixture('issue-13644-3.diff'), :type => 'sbs')
assert_equal 1, diff.size
assert_equal 3, diff.first.size
assert_equal ja1, diff.first[1].html_line_left
assert_equal ja2, diff.first[1].html_line_right
assert_equal '日本<span>記</span>', diff.first[1].html_line_left
assert_equal '日本<span>娘</span>', diff.first[1].html_line_right
end
end
def test_offset_range_japanese_4
# UTF-8 The 2nd byte differs.
ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>".force_encoding('UTF-8')
ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x98</span>".force_encoding('UTF-8')
# UTF-8 The 2nd byte differs.
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(
read_diff_fixture('issue-13644-4.diff'), :type => 'sbs')
assert_equal 1, diff.size
assert_equal 3, diff.first.size
assert_equal ja1, diff.first[1].html_line_left
assert_equal ja2, diff.first[1].html_line_right
assert_equal '日本<span>記</span>', diff.first[1].html_line_left
assert_equal '日本<span>誘</span>', diff.first[1].html_line_right
end
end
def test_offset_range_japanese_5
# UTF-8 The 2nd byte differs.
ja1 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xa8\x98</span>ok".force_encoding('UTF-8')
ja2 = "\xe6\x97\xa5\xe6\x9c\xac<span>\xe8\xaa\x98</span>ok".force_encoding('UTF-8')
# UTF-8 The 2nd byte differs.
with_settings :repositories_encodings => '' do
diff = Redmine::UnifiedDiff.new(
read_diff_fixture('issue-13644-5.diff'), :type => 'sbs')
assert_equal 1, diff.size
assert_equal 3, diff.first.size
assert_equal ja1, diff.first[1].html_line_left
assert_equal ja2, diff.first[1].html_line_right
assert_equal '日本<span>記</span>ok', diff.first[1].html_line_left
assert_equal '日本<span>誘</span>ok', diff.first[1].html_line_right
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -95,9 +97,20 @@ class Redmine::Views::Builders::JsonTest < ActiveSupport::TestCase
end
end
def test_request_response
assert_json_output({'request' => { 'get' => 'book' }, 'response' => { 'book' => { 'title' => 'Book 1' } }}) do |b|
b.request do
b.get 'book'
end
b.response do
b.book title: 'Book 1'
end
end
end
def assert_json_output(expected, &block)
builder = Redmine::Views::Builders::Json.new(ActionDispatch::TestRequest.new, ActionDispatch::TestResponse.new)
block.call(builder)
builder = Redmine::Views::Builders::Json.new(ActionDispatch::TestRequest.create, ActionDispatch::TestResponse.create)
yield(builder)
assert_equal(expected, ActiveSupport::JSON.decode(builder.output))
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -60,8 +62,8 @@ class Redmine::Views::Builders::XmlTest < ActiveSupport::TestCase
end
def assert_xml_output(expected, &block)
builder = Redmine::Views::Builders::Xml.new(ActionDispatch::TestRequest.new, ActionDispatch::TestResponse.new)
block.call(builder)
builder = Redmine::Views::Builders::Xml.new(ActionDispatch::TestRequest.create, ActionDispatch::TestResponse.create)
yield(builder)
assert_equal('<?xml version="1.0" encoding="UTF-8"?>' + expected, builder.output)
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -32,4 +34,34 @@ class Redmine::WikiFormatting::HtmlParserTest < ActiveSupport::TestCase
assert_equal "Text",
@parser.to_text('<html><body><style>body {font-size: 0.8em;}</style>Text</body></html>')
end
def test_should_remove_preceding_whitespaces
to_test = {
"<div> blocks with</div>\n<p>\n preceding whitespaces\n</p>" => "blocks with\n\npreceding whitespaces",
"<div>blocks without</div>\n<p>\npreceding whitespaces\n</p>" => "blocks without\n\npreceding whitespaces",
"<span> span with</span>\n<span> preceding whitespaces</span>" => "span with preceding whitespaces",
"<span>span without</span>\n<span>preceding whitespaces</span>" => "span without preceding whitespaces"
}
to_test.each do |html, expected|
assert_equal expected, @parser.to_text(html)
end
end
def test_should_remove_space_of_beginning_of_line
str = <<~HTML
<table>
<tr>
<th>th1</th>
<th>th2</th>
</tr>
<tr>
<td>td1</td>
<td>td2</td>
</tr>
</table>
HTML
assert_equal "th1\n\nth2\n\ntd1\n\ntd2",
@parser.to_text(str)
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -26,12 +28,12 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest
extend ActionView::Helpers::SanitizeHelper::ClassMethods
fixtures :projects, :roles, :enabled_modules, :users,
:repositories, :changesets,
:trackers, :issue_statuses, :issues,
:versions, :documents,
:wikis, :wiki_pages, :wiki_contents,
:boards, :messages,
:attachments
:repositories, :changesets,
:trackers, :issue_statuses, :issues,
:versions, :documents,
:wikis, :wiki_pages, :wiki_contents,
:boards, :messages,
:attachments, :enumerations
def setup
super
@ -87,7 +89,7 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest
def test_multiple_macros_on_the_same_line
Redmine::WikiFormatting::Macros.macro :foo do |obj, args|
args.any? ? "args: #{args.join(',')}" : "no args"
args.any? ? "args: #{args.join(',')}" : "no args"
end
assert_equal '<p>no args no args</p>', textilizable("{{foo}} {{foo}}")
@ -210,11 +212,11 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest
text = "{{collapse\n*Collapsed* block of text\n}}"
with_locale 'en' do
result = textilizable(text)
assert_select_in result, 'div.collapsed-text'
assert_select_in result, 'strong', :text => 'Collapsed'
assert_select_in result, 'a.collapsible.collapsed', :text => 'Show'
assert_select_in result, 'a.collapsible', :text => 'Hide'
assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Show'
assert_select_in result, 'a.collapsible.icon-expended', :text => 'Hide'
end
end
@ -224,8 +226,8 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest
assert_select_in result, 'div.collapsed-text'
assert_select_in result, 'strong', :text => 'Collapsed'
assert_select_in result, 'a.collapsible.collapsed', :text => 'Example'
assert_select_in result, 'a.collapsible', :text => 'Example'
assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Example'
assert_select_in result, 'a.collapsible.icon-expended', :text => 'Example'
end
def test_macro_collapse_with_two_args
@ -234,22 +236,22 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest
assert_select_in result, 'div.collapsed-text'
assert_select_in result, 'strong', :text => 'Collapsed'
assert_select_in result, 'a.collapsible.collapsed', :text => 'Show example'
assert_select_in result, 'a.collapsible', :text => 'Hide example'
assert_select_in result, 'a.collapsible.icon-collapsed', :text => 'Show example'
assert_select_in result, 'a.collapsible.icon-expended', :text => 'Hide example'
end
def test_macro_collapse_should_not_break_toc
set_language_if_valid 'en'
text = <<-RAW
{{toc}}
text = <<~RAW
{{toc}}
h1. Title
h1. Title
{{collapse(Show example, Hide example)
h2. Heading
}}"
RAW
{{collapse(Show example, Hide example)
h2. Heading
}}"
RAW
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>'
@ -307,7 +309,7 @@ RAW
end
def test_macro_thumbnail
link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17" />'.html_safe,
link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17/200" />'.html_safe,
"/attachments/17",
:class => "thumbnail",
:title => "testfile.PNG")
@ -316,7 +318,7 @@ RAW
end
def test_macro_thumbnail_with_full_path
link = link_to('<img alt="testfile.PNG" src="http://test.host/attachments/thumbnail/17" />'.html_safe,
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")
@ -325,16 +327,16 @@ RAW
end
def test_macro_thumbnail_with_size
link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17/200" />'.html_safe,
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=200)}}", :object => Issue.find(14))
textilizable("{{thumbnail(testfile.png, size=400)}}", :object => Issue.find(14))
end
def test_macro_thumbnail_with_title
link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17" />'.html_safe,
link = link_to('<img alt="testfile.PNG" src="/attachments/thumbnail/17/200" />'.html_safe,
"/attachments/17",
:class => "thumbnail",
:title => "Cool image")
@ -344,32 +346,30 @@ RAW
def test_macro_thumbnail_with_invalid_filename_should_fail
assert_include 'test.png not found',
textilizable("{{thumbnail(test.png)}}", :object => Issue.find(14))
textilizable("{{thumbnail(test.png)}}", :object => Issue.find(14))
end
def test_macros_should_not_be_executed_in_pre_tags
text = <<-RAW
{{hello_world(foo)}}
text = <<~RAW
{{hello_world(foo)}}
<pre>
{{hello_world(pre)}}
!{{hello_world(pre)}}
</pre>
<pre>
{{hello_world(pre)}}
!{{hello_world(pre)}}
</pre>
{{hello_world(bar)}}
RAW
{{hello_world(bar)}}
RAW
expected = <<~EXPECTED
<p>Hello world! Object: NilClass, Arguments: foo and no block of text.</p>
expected = <<-EXPECTED
<p>Hello world! Object: NilClass, Arguments: foo and no block of text.</p>
<pre>
{{hello_world(pre)}}
!{{hello_world(pre)}}
</pre>
<p>Hello world! Object: NilClass, Arguments: bar and no block of text.</p>
EXPECTED
<pre>
{{hello_world(pre)}}
!{{hello_world(pre)}}
</pre>
<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]}, '')
end
@ -384,21 +384,19 @@ EXPECTED
end
def test_macros_with_text_should_not_mangle_following_macros
text = <<-RAW
{{hello_world
Line of text
}}
{{hello_world
Another line of text
}}
RAW
expected = <<-EXPECTED
<p>Hello world! Object: NilClass, Called with no argument and a 12 bytes long block of text.</p>
<p>Hello world! Object: NilClass, Called with no argument and a 20 bytes long block of text.</p>
EXPECTED
text = <<~RAW
{{hello_world
Line of text
}}
{{hello_world
Another line of text
}}
RAW
expected = <<~EXPECTED
<p>Hello world! Object: NilClass, Called with no argument and a 12 bytes long block of text.</p>
<p>Hello world! Object: NilClass, Called with no argument and a 20 bytes long block of text.</p>
EXPECTED
assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(text).gsub(%r{[\r\n\t]}, '')
end
@ -406,4 +404,14 @@ EXPECTED
text = "*{{hello_world}}*"
assert_match %r|\A<p><strong>Hello world!.*</strong></p>\z|, textilizable(text)
end
def test_issue_macro_should_not_render_link_if_not_visible
assert_equal "<p>#123</p>", textilizable('{{issue(123)}}')
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" 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" href="/issues/1">Bug #1</a>: #{issue.subject}</p>}, textilizable("{{issue(1, project=true)}}")
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -58,24 +60,24 @@ class Redmine::WikiFormatting::MarkdownFormatterTest < ActionView::TestCase
assert_include 'version:"1.0"', @formatter.new(text).to_html
end
def test_should_support_syntax_highligth
text = <<-STR
~~~ruby
def foo
end
~~~
STR
def test_should_support_syntax_highlight
text = <<~STR
~~~ruby
def foo
end
~~~
STR
assert_select_in @formatter.new(text).to_html, 'pre code.ruby.syntaxhl' do
assert_select 'span.keyword', :text => 'def'
assert_select 'span.k', :text => 'def'
end
end
def test_should_not_allow_invalid_language_for_code_blocks
text = <<-STR
~~~foo
test
~~~
STR
text = <<~STR
~~~foo
test
~~~
STR
assert_equal "<pre>test\n</pre>", @formatter.new(text).to_html
end
@ -90,43 +92,76 @@ STR
end
def test_markdown_should_not_require_surrounded_empty_line
text = <<-STR
This is a list:
* One
* Two
STR
text = <<~STR
This is a list:
* One
* Two
STR
assert_equal "<p>This is a list:</p>\n\n<ul>\n<li>One</li>\n<li>Two</li>\n</ul>", @formatter.new(text).to_html.strip
end
STR_WITH_PRE = [
# 0
"# Title
def test_footnotes
text = <<~STR
This is some text[^1].
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.",
# 1
"## Heading 2
[^1]: This is the foot note
STR
expected = <<~EXPECTED
<p>This is some text<sup id="fnref1"><a href="#fn1">1</a></sup>.</p>
<div class="footnotes">
<hr>
<ol>
~~~ruby
def foo
<li id="fn1">
<p>This is the foot note&nbsp;<a href="#fnref1">&#8617;</a></p>
</li>
</ol>
</div>
EXPECTED
assert_equal expected.gsub(%r{[\r\n\t]}, ''), @formatter.new(text).to_html.gsub(%r{[\r\n\t]}, '')
end
>>>>>>> .merge-right.r17266
~~~
Morbi facilisis accumsan orci non pharetra.
STR_WITH_PRE = [
# 0
<<~STR.chomp,
# Title
```
Pre Content:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
STR
# 1
<<~STR.chomp,
## Heading 2
## Inside pre
~~~ruby
def foo
end
~~~
<tag> inside pre block
Morbi facilisis accumsan orci non pharetra.
Morbi facilisis accumsan orci non pharetra.
```",
# 2
"### Heading 3
~~~ ruby
def foo
end
~~~
Nulla nunc nisi, egestas in ornare vel, posuere ac libero."]
```
Pre Content:
## Inside pre
<tag> inside pre block
Morbi facilisis accumsan orci non pharetra.
```
STR
# 2
<<~STR.chomp,
### Heading 3
Nulla nunc nisi, egestas in ornare vel, posuere ac libero.
STR
]
def test_get_section_should_ignore_pre_content
text = STR_WITH_PRE.join("\n\n")
@ -143,6 +178,11 @@ Nulla nunc nisi, egestas in ornare vel, posuere ac libero."]
@formatter.new(text).update_section(3, replacement)
end
def test_should_support_underlined_text
text = 'This _text_ should be underlined'
assert_equal '<p>This <u>text</u> should be underlined</p>', @formatter.new(text).to_html.strip
end
private
def assert_section_with_hash(expected, text, index)
@ -153,6 +193,5 @@ Nulla nunc nisi, egestas in ornare vel, posuere ac libero."]
assert_equal expected, result.first, "section content did not match"
assert_equal Digest::MD5.hexdigest(expected), result.last, "section hash did not match"
end
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -26,5 +28,22 @@ class Redmine::WikiFormatting::MarkdownHtmlParserTest < ActiveSupport::TestCase
def test_should_convert_tags
assert_equal 'A **simple** html snippet.',
@parser.to_text('<p>A <b>simple</b> html snippet.</p>')
assert_equal 'foo [bar](http://example.com/) baz',
@parser.to_text('foo<a href="http://example.com/">bar</a>baz')
assert_equal 'foo http://example.com/ baz',
@parser.to_text('foo<a href="http://example.com/"></a>baz')
assert_equal 'foobarbaz',
@parser.to_text('foo<a name="Header-one">bar</a>baz')
assert_equal 'foobaz',
@parser.to_text('foo<a name="Header-one"/>baz')
end
def test_html_tables_conversion
assert_equal "*th1*\n*th2*\n\ntd1\ntd2",
@parser.to_text('<table><tr><th>th1</th><th>th2</th></tr><tr><td>td1</td><td>td2</td></tr></table>')
end
end

View file

@ -1,7 +1,8 @@
#encoding: utf-8
# frozen_string_literal: true
#
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -80,6 +81,10 @@ class Redmine::WikiFormatting::TextileFormatterTest < ActionView::TestCase
'p{border-right:1px}. text' => '<p style="border-right:1px;">text</p>',
'p{border-top:1px}. text' => '<p style="border-top:1px;">text</p>',
'p{border-bottom:1px}. text' => '<p style="border-bottom:1px;">text</p>',
'p{width:50px}. text' => '<p style="width:50px;">text</p>',
'p{max-width:100px}. text' => '<p style="max-width:100px;">text</p>',
'p{height:40px}. text' => '<p style="height:40px;">text</p>',
'p{max-height:80px}. text' => '<p style="max-height:80px;">text</p>',
}, false)
# multiple styles
@ -156,6 +161,24 @@ RAW
EXPECTED
assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
raw = <<~RAW
* Item-1
* Item-1a
* Item-1b
RAW
expected = <<~EXPECTED
<ul>
<li>Item-1
<ul>
<li>Item-1a</li>
<li>Item-1b</li>
</ul>
</li>
</ul>
EXPECTED
assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
end
def test_escaping
@ -276,7 +299,7 @@ EXPECTED
This is a table with trailing whitespace in one row:
|cell11|cell12|
|cell21|cell22|
|cell21|cell22|
|cell31|cell32|
RAW
@ -378,67 +401,76 @@ EXPECTED
expected = '<p><img src="/images/comment.png&quot;onclick=&amp;#x61;&amp;#x6c;&amp;#x65;&amp;#x72;&amp;#x74;&amp;#x28;&amp;#x27;&amp;#x58;&amp;#x53;&amp;#x53;&amp;#x27;&amp;#x29;;&amp;#x22;" alt="" /></p>'
assert_equal expected.gsub(%r{\s+}, ''), to_html(raw).gsub(%r{\s+}, '')
end
STR_WITHOUT_PRE = [
# 0
"h1. Title
# 0
<<~STR.chomp,
h1. Title
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.",
# 1
"h2. Heading 2
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
STR
# 1
<<~STR.chomp,
h2. Heading 2
Maecenas sed elit sit amet mi accumsan vestibulum non nec velit. Proin porta tincidunt lorem, consequat rhoncus dolor fermentum in.
Maecenas sed elit sit amet mi accumsan vestibulum non nec velit. Proin porta tincidunt lorem, consequat rhoncus dolor fermentum in.
Cras ipsum felis, ultrices at porttitor vel, faucibus eu nunc.",
# 2
"h2. Heading 2
Cras ipsum felis, ultrices at porttitor vel, faucibus eu nunc.
STR
# 2
<<~STR.chomp,
h2. Heading 2
Morbi facilisis accumsan orci non pharetra.
Morbi facilisis accumsan orci non pharetra.
h3. Heading 3
h3. Heading 3
Nulla nunc nisi, egestas in ornare vel, posuere ac libero.",
# 3
"h3. Heading 3
Nulla nunc nisi, egestas in ornare vel, posuere ac libero.
STR
# 3
<<~STR.chomp,
h3. Heading 3
Praesent eget turpis nibh, a lacinia nulla.",
# 4
"h2. Heading 2
Ut rhoncus elementum adipiscing."]
Praesent eget turpis nibh, a lacinia nulla.
STR
# 4
<<~STR.chomp,
h2. Heading 2
Ut rhoncus elementum adipiscing.
STR
]
TEXT_WITHOUT_PRE = STR_WITHOUT_PRE.join("\n\n").freeze
def test_get_section_should_return_the_requested_section_and_its_hash
assert_section_with_hash STR_WITHOUT_PRE[1], TEXT_WITHOUT_PRE, 2
assert_section_with_hash STR_WITHOUT_PRE[2..3].join("\n\n"), TEXT_WITHOUT_PRE, 3
assert_section_with_hash STR_WITHOUT_PRE[3], TEXT_WITHOUT_PRE, 5
assert_section_with_hash STR_WITHOUT_PRE[4], TEXT_WITHOUT_PRE, 6
assert_section_with_hash '', TEXT_WITHOUT_PRE, 0
assert_section_with_hash '', TEXT_WITHOUT_PRE, 10
end
def test_update_section_should_update_the_requested_section
replacement = "New text"
assert_equal [STR_WITHOUT_PRE[0], replacement, STR_WITHOUT_PRE[2..4]].flatten.join("\n\n"), @formatter.new(TEXT_WITHOUT_PRE).update_section(2, replacement)
assert_equal [STR_WITHOUT_PRE[0..1], replacement, STR_WITHOUT_PRE[4]].flatten.join("\n\n"), @formatter.new(TEXT_WITHOUT_PRE).update_section(3, replacement)
assert_equal [STR_WITHOUT_PRE[0..2], replacement, STR_WITHOUT_PRE[4]].flatten.join("\n\n"), @formatter.new(TEXT_WITHOUT_PRE).update_section(5, replacement)
assert_equal [STR_WITHOUT_PRE[0..3], replacement].flatten.join("\n\n"), @formatter.new(TEXT_WITHOUT_PRE).update_section(6, replacement)
assert_equal TEXT_WITHOUT_PRE, @formatter.new(TEXT_WITHOUT_PRE).update_section(0, replacement)
assert_equal TEXT_WITHOUT_PRE, @formatter.new(TEXT_WITHOUT_PRE).update_section(10, replacement)
end
def test_update_section_with_hash_should_update_the_requested_section
replacement = "New text"
assert_equal [STR_WITHOUT_PRE[0], replacement, STR_WITHOUT_PRE[2..4]].flatten.join("\n\n"),
@formatter.new(TEXT_WITHOUT_PRE).update_section(2, replacement, Digest::MD5.hexdigest(STR_WITHOUT_PRE[1]))
end
def test_update_section_with_wrong_hash_should_raise_an_error
assert_raise Redmine::WikiFormatting::StaleSectionError do
@formatter.new(TEXT_WITHOUT_PRE).update_section(2, "New text", Digest::MD5.hexdigest("Old text"))
@ -446,38 +478,45 @@ Ut rhoncus elementum adipiscing."]
end
STR_WITH_PRE = [
# 0
"h1. Title
# 0
<<~STR.chomp,
h1. Title
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.",
# 1
"h2. Heading 2
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero.
STR
# 1
<<~STR.chomp,
h2. Heading 2
<pre><code class=\"ruby\">
def foo
end
</code></pre>
<pre><code class=\"ruby\">
def foo
end
</code></pre>
<pre><code><pre><code class=\"ruby\">
Place your code here.
</code></pre>
</code></pre>
<pre><code><pre><code class=\"ruby\">
Place your code here.
</code></pre>
</code></pre>
Morbi facilisis accumsan orci non pharetra.
Morbi facilisis accumsan orci non pharetra.
<pre>
Pre Content:
<pre>
Pre Content:
h2. Inside pre
h2. Inside pre
<tag> inside pre block
<tag> inside pre block
Morbi facilisis accumsan orci non pharetra.
</pre>",
# 2
"h3. Heading 3
Morbi facilisis accumsan orci non pharetra.
</pre>
STR
# 2
<<~STR.chomp,
h3. Heading 3
Nulla nunc nisi, egestas in ornare vel, posuere ac libero."]
Nulla nunc nisi, egestas in ornare vel, posuere ac libero.
STR
]
def test_get_section_should_ignore_pre_content
text = STR_WITH_PRE.join("\n\n")
@ -489,7 +528,7 @@ Nulla nunc nisi, egestas in ornare vel, posuere ac libero."]
def test_update_section_should_not_escape_pre_content_outside_section
text = STR_WITH_PRE.join("\n\n")
replacement = "New text"
assert_equal [STR_WITH_PRE[0..1], "New text"].flatten.join("\n\n"),
@formatter.new(text).update_section(3, replacement)
end
@ -504,13 +543,13 @@ Content 1
h1. Heading 2
Content 2
h1. Heading 3
Content 3
h1. Heading 4
Content 4
STR
@ -551,9 +590,9 @@ STR
def test_should_allow_valid_language_class_attribute_on_code_tags
# language name is double-quoted
assert_html_output({"<code class=\"ruby\">test</code>" => "<code class=\"ruby syntaxhl\"><span class=\"CodeRay\">test</span></code>"}, false)
assert_html_output({"<code class=\"ruby\">test</code>" => "<code class=\"ruby syntaxhl\"><span class=\"nb\">test</span></code>"}, false)
# language name is single-quoted
assert_html_output({"<code class='ruby'>test</code>" => "<code class=\"ruby syntaxhl\"><span class=\"CodeRay\">test</span></code>"}, false)
assert_html_output({"<code class='ruby'>test</code>" => "<code class=\"ruby syntaxhl\"><span class=\"nb\">test</span></code>"}, false)
end
def test_should_not_allow_valid_language_class_attribute_on_non_code_offtags
@ -588,6 +627,21 @@ STR
}, false)
end
def test_footnotes
text = <<-STR
This is some text[1].
fn1. This is the foot note
STR
expected = <<-EXPECTED
<p>This is some text<sup><a href=\"#fn1\">1</a></sup>.</p>
<p id="fn1" class="footnote"><sup>1</sup> This is the foot note</p>
EXPECTED
assert_equal expected.gsub(%r{[\r\n\t]}, ''), to_html(text).gsub(%r{[\r\n\t]}, '')
end
# TODO: Remove this test after migrating to RedCloth 4
def test_should_not_crash_with_special_input
assert_nothing_raised { to_html(" \f") }
@ -621,10 +675,10 @@ EXPECTED
def to_html(text)
@formatter.new(text).to_html
end
def assert_section_with_hash(expected, text, index)
result = @formatter.new(text).get_section(index)
assert_kind_of Array, result
assert_equal 2, result.size
assert_equal expected, result.first, "section content did not match"

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -26,5 +28,22 @@ class Redmine::WikiFormatting::TextileHtmlParserTest < ActiveSupport::TestCase
def test_should_convert_tags
assert_equal 'A *simple* html snippet.',
@parser.to_text('<p>A <b>simple</b> html snippet.</p>')
assert_equal 'foo "bar":http://example.com/ baz',
@parser.to_text('foo<a href="http://example.com/">bar</a>baz')
assert_equal 'foo http://example.com/ baz',
@parser.to_text('foo<a href="http://example.com/"></a>baz')
assert_equal 'foobarbaz',
@parser.to_text('foo<a name="Header-one">bar</a>baz')
assert_equal 'foobaz',
@parser.to_text('foo<a name="Header-one"/>baz')
end
def test_html_tables_conversion
assert_equal "*th1*\n*th2*\n\ntd1\ntd2",
@parser.to_text('<table><tr><th>th1</th><th>th2</th></tr><tr><td>td1</td><td>td2</td></tr></table>')
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -64,19 +66,32 @@ DIFF
<p>link: <a class="external" href="https://www.redmine.org">https://www.redmine.org</a><br />
<a class="external" href="http://www.redmine.org">http://www.redmine.org</a></p>
EXPECTED
assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
end
def test_supports_section_edit
with_settings :text_formatting => 'textile' do
assert_equal true, Redmine::WikiFormatting.supports_section_edit?
end
with_settings :text_formatting => '' do
assert_equal false, Redmine::WikiFormatting.supports_section_edit?
end
end
def test_hires_images_should_not_be_recognized_as_email_addresses
raw = <<-DIFF
Image: logo@2x.png
DIFF
expected = <<-EXPECTED
<p>Image: logo@2x.png</p>
EXPECTED
assert_equal expected.gsub(%r{[\r\n\t]}, ''), Redmine::WikiFormatting::NullFormatter::Formatter.new(raw).to_html.gsub(%r{[\r\n\t]}, '')
end
def test_cache_key_for_saved_object_should_no_be_nil
assert_not_nil Redmine::WikiFormatting.cache_key_for('textile', 'Text', Issue.find(1), :description)
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License