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
@ -169,7 +171,7 @@ class ActivityTest < ActiveSupport::TestCase
def test_event_types_should_include_activity_provider_with_nil_permission
Redmine::Activity.register 'test', :class_name => 'ActivityTest::TestActivityProviderWithNilPermission'
user = MockUser.new()
user = MockUser.new
f = Redmine::Activity::Fetcher.new(user, :project => Project.find(1))
assert_include 'test', f.event_types
ensure
@ -179,7 +181,7 @@ class ActivityTest < ActiveSupport::TestCase
def test_event_types_should_use_default_permission_for_activity_provider_without_permission
Redmine::Activity.register 'test', :class_name => 'ActivityTest::TestActivityProviderWithoutPermission'
user = MockUser.new()
user = MockUser.new
f = Redmine::Activity::Fetcher.new(user, :project => Project.find(1))
assert_not_include 'test', f.event_types

View file

@ -1,7 +1,7 @@
# 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
@ -23,11 +23,8 @@ class AttachmentTest < ActiveSupport::TestCase
fixtures :users, :email_addresses, :projects, :roles, :members, :member_roles,
:enabled_modules, :issues, :trackers, :attachments
# TODO: remove this with Rails 5 that supports after_commit callbacks
# in transactional fixtures (https://github.com/rails/rails/pull/18458)
self.use_transactional_fixtures = false
def setup
User.current = nil
set_tmp_attachments_directory
end
@ -299,7 +296,8 @@ class AttachmentTest < ActiveSupport::TestCase
test "Attachmnet.attach_files should attach the file" do
issue = Issue.first
assert_difference 'Attachment.count' do
Attachment.attach_files(issue,
Attachment.attach_files(
issue,
'1' => {
'file' => uploaded_test_file('testfile.txt', 'text/plain'),
'description' => 'test'
@ -347,6 +345,8 @@ class AttachmentTest < ActiveSupport::TestCase
assert attachment.readable?
attachment.update_digest_to_sha256!
assert_equal 'ac5c6e99a21ae74b2e3f5b8e5b568be1b9107cd7153d139e822b9fe5caf50938', attachment.digest
ensure
set_tmp_attachments_directory
end
def test_update_attachments
@ -406,12 +406,12 @@ class AttachmentTest < ActiveSupport::TestCase
assert_equal 17, la1.id
la2 = Attachment.latest_attach([a1, a2], "Testfile.PNG")
assert_equal 17, la2.id
ensure
set_tmp_attachments_directory
end
def test_latest_attach_should_not_error_with_string_with_invalid_encoding
string = "width:50\xFE-Image.jpg".force_encoding('UTF-8')
string = "width:50\xFE-Image.jpg"
assert_equal false, string.valid_encoding?
Attachment.latest_attach(Attachment.limit(2).to_a, string)
@ -421,21 +421,78 @@ class AttachmentTest < ActiveSupport::TestCase
assert_equal true, Attachment.new(:filename => 'test.jpg').thumbnailable?
end
def test_thumbnailable_should_be_true_for_non_images
def test_thumbnailable_should_be_false_for_images_if_convert_is_unavailable
Redmine::Thumbnail.stubs(:convert_available?).returns(false)
assert_equal false, Attachment.new(:filename => 'test.jpg').thumbnailable?
end
def test_thumbnailable_should_be_false_for_non_images
assert_equal false, Attachment.new(:filename => 'test.txt').thumbnailable?
end
if convert_installed?
def test_thumbnail_should_generate_the_thumbnail
set_fixtures_attachments_directory
attachment = Attachment.find(16)
Attachment.clear_thumbnails
to_test = []
# image/png
to_test << Attachment.find(16)
# application/pdf
if Redmine::Thumbnail.gs_available?
to_test << Attachment.find(23)
else
puts '(Ghostscript not available)'
end
assert_difference "Dir.glob(File.join(Attachment.thumbnails_storage_path, '*.thumb')).size", to_test.size do
to_test.each do |attachment|
thumbnail = attachment.thumbnail
thumbnail_name = "#{attachment.digest}_#{attachment.filesize}_#{Setting.thumbnails_size}.thumb"
assert_equal thumbnail_name, File.basename(thumbnail)
assert File.exist?(thumbnail)
end
end
ensure
set_tmp_attachments_directory
end
def test_should_reuse_thumbnail
Attachment.clear_thumbnails
a = Attachment.create!(
:container => Issue.find(1),
:file => uploaded_test_file("2010/11/101123161450_testfile_1.png", "image/png"),
:author => User.find(1)
)
a_thumb = b_thumb = nil
assert_difference "Dir.glob(File.join(Attachment.thumbnails_storage_path, '*.thumb')).size" do
thumbnail = attachment.thumbnail
assert_equal "16_8e0294de2441577c529f170b6fb8f638_100.thumb", File.basename(thumbnail)
assert File.exists?(thumbnail)
a_thumb = a.thumbnail
end
b = Attachment.create!(
:container => Issue.find(2),
:file => uploaded_test_file("2010/11/101123161450_testfile_1.png", "image/png"),
:author => User.find(1)
)
assert_no_difference "Dir.glob(File.join(Attachment.thumbnails_storage_path, '*.thumb')).size" do
b_thumb = b.thumbnail
end
assert_equal a_thumb, b_thumb
end
def test_destroy_should_destroy_thumbnails
a = Attachment.create!(
:container => Issue.find(1),
:file => uploaded_test_file("2010/11/101123161450_testfile_1.png", "image/png"),
:author => User.find(1)
)
diskfile = a.diskfile
thumbnail = a.thumbnail
assert File.exist?(diskfile)
assert File.exist?(thumbnail)
assert a.destroy
refute File.exist?(diskfile)
refute File.exist?(thumbnail)
end
def test_thumbnail_should_return_nil_if_generation_fails
@ -443,9 +500,49 @@ class AttachmentTest < ActiveSupport::TestCase
set_fixtures_attachments_directory
attachment = Attachment.find(16)
assert_nil attachment.thumbnail
ensure
set_tmp_attachments_directory
end
def test_thumbnail_should_be_at_least_of_requested_size
set_fixtures_attachments_directory
attachment = Attachment.find(16)
Attachment.clear_thumbnails
[
[0, 100],
[49, 50],
[50, 50],
[51, 100],
[100, 100],
[101, 150],
].each do |size, generated_size|
thumbnail = attachment.thumbnail(size: size)
assert_equal(
"8e0294de2441577c529f170b6fb8f638_2654_#{generated_size}.thumb",
File.basename(thumbnail))
end
ensure
set_tmp_attachments_directory
end
else
puts '(ImageMagick convert not available)'
end
def test_is_text
js_attachment = Attachment.new(
:container => Issue.find(1),
:file => uploaded_test_file('hello.js', 'application/javascript'),
:author => User.find(1))
to_test = {
js_attachment => true, # hello.js (application/javascript)
attachments(:attachments_003) => false, # logo.gif (image/gif)
attachments(:attachments_004) => true, # source.rb (application/x-ruby)
attachments(:attachments_015) => true, # private.diff (text/x-diff)
attachments(:attachments_016) => false, # testfile.png (image/png)
}
to_test.each do |attachment, expected|
assert_equal expected, attachment.is_text?, attachment.inspect
end
end
end

View file

@ -1,7 +1,7 @@
# 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
@ -23,7 +23,7 @@ class AttachmentTest < ActiveSupport::TestCase
fixtures :users, :email_addresses, :projects, :roles, :members, :member_roles,
:enabled_modules, :issues, :trackers, :attachments
self.use_transactional_fixtures = false
self.use_transactional_tests = false
def setup
User.current = nil

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
@ -41,6 +43,8 @@ class AuthSourceLdapTest < ActiveSupport::TestCase
assert_nil auth_source.attr_mail
assert_equal false, auth_source.onthefly_register
assert_equal false, auth_source.tls
assert_equal true, auth_source.verify_peer
assert_equal :ldap, auth_source.ldap_mode
assert_nil auth_source.filter
assert_nil auth_source.timeout
end
@ -78,6 +82,42 @@ class AuthSourceLdapTest < ActiveSupport::TestCase
assert a.valid?
end
test 'ldap_mode setter sets tls and verify_peer' do
a = AuthSourceLdap.new
a.ldap_mode = 'ldaps_verify_peer'
assert a.tls
assert a.verify_peer
a.ldap_mode = 'ldaps_verify_none'
assert a.tls
assert !a.verify_peer
a.ldap_mode = 'ldap'
assert !a.tls
assert !a.verify_peer
end
test 'ldap_mode getter reads from tls and verify_peer' do
a = AuthSourceLdap.new
a.tls = true
a.verify_peer = true
assert_equal :ldaps_verify_peer, a.ldap_mode
a.tls = true
a.verify_peer = false
assert_equal :ldaps_verify_none, a.ldap_mode
a.tls = false
a.verify_peer = false
assert_equal :ldap, a.ldap_mode
a.tls = false
a.verify_peer = true
assert_equal :ldap, a.ldap_mode
end
if ldap_configured?
test '#authenticate with a valid LDAP user should return the user attributes' do
auth = AuthSourceLdap.find(1)
@ -151,7 +191,7 @@ class AuthSourceLdapTest < ActiveSupport::TestCase
end
def test_search_with_exception_should_return_an_empty_array
Net::LDAP.stubs(:new).raises(Net::LDAP::LdapError, 'Cannot connect')
Net::LDAP.stubs(:new).raises(Net::LDAP::Error, 'Cannot connect')
results = AuthSource.search("exa")
assert_equal [], results
@ -160,7 +200,7 @@ class AuthSourceLdapTest < ActiveSupport::TestCase
def test_test_connection_with_correct_host_and_port
auth_source = AuthSourceLdap.find(1)
assert_nothing_raised Net::LDAP::Error do
assert_nothing_raised do
auth_source.test_connection
end
end
@ -170,7 +210,7 @@ class AuthSourceLdapTest < ActiveSupport::TestCase
auth_source.host = "badhost"
auth_source.save!
assert_raise Net::LDAP::Error do
assert_raise AuthSourceException do
auth_source.test_connection
end
end
@ -180,7 +220,7 @@ class AuthSourceLdapTest < ActiveSupport::TestCase
auth_source.port = 1234
auth_source.save!
assert_raise Net::LDAP::Error do
assert_raise AuthSourceException do
auth_source.test_connection
end
end

View file

@ -1,7 +1,7 @@
# 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
@ -93,6 +93,7 @@ class BoardTest < ActiveSupport::TestCase
end
def test_destroy
set_tmp_attachments_directory
board = Board.find(1)
assert_difference 'Message.count', -6 do
assert_difference 'Attachment.count', -1 do

View file

@ -1,7 +1,7 @@
# 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
@ -50,7 +50,7 @@ class ChangesetTest < ActiveSupport::TestCase
fixed = Issue.find(1)
assert fixed.closed?
assert_equal 90, fixed.done_ratio
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal 2, ActionMailer::Base.deliveries.size
end
def test_ref_keywords
@ -210,7 +210,6 @@ class ChangesetTest < ActiveSupport::TestCase
{'keywords' => 'fixes, closes', 'status_id' => '5'},
{'keywords' => 'resolves', 'status_id' => '3'}
] do
issue1 = Issue.generate!
issue2 = Issue.generate!
Changeset.generate!(:comments => "Closes ##{issue1.id}\nResolves ##{issue2.id}")
@ -224,7 +223,6 @@ class ChangesetTest < ActiveSupport::TestCase
{'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
{'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => ''}
] do
issue1 = Issue.generate!(:tracker_id => 2)
issue2 = Issue.generate!
Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
@ -238,7 +236,6 @@ class ChangesetTest < ActiveSupport::TestCase
{'keywords' => 'Fixes, Closes', 'status_id' => '5', 'done_ratio' => '100', 'if_tracker_id' => '2'},
{'keywords' => 'Testing', 'status_id' => '3', 'done_ratio' => '90', 'if_tracker_id' => '2'}
] do
issue1 = Issue.generate!(:tracker_id => 2)
issue2 = Issue.generate!(:tracker_id => 2)
Changeset.generate!(:comments => "Testing ##{issue1.id}, Fixes ##{issue2.id}")
@ -256,7 +253,6 @@ class ChangesetTest < ActiveSupport::TestCase
{'keywords' => 'fixes', 'status_id' => '5', 'if_tracker_id' => '2'},
{'keywords' => 'fixes', 'status_id' => '3', 'if_tracker_id' => '3'}
] do
issue1 = Issue.generate!(:tracker_id => 2)
issue2 = Issue.generate!
Changeset.generate!(:comments => "Fixes ##{issue1.id}, ##{issue2.id}")
@ -448,8 +444,7 @@ class ChangesetTest < ActiveSupport::TestCase
def test_comments_should_be_converted_to_utf8
proj = Project.find(3)
# str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
str = "Texte encod\xe9 en ISO-8859-1.".force_encoding("ASCII-8BIT")
str = "Texte encod\xe9 en ISO-8859-1.".b
r = Repository::Bazaar.create!(
:project => proj,
:url => '/tmp/test/bazaar',
@ -461,15 +456,12 @@ class ChangesetTest < ActiveSupport::TestCase
:scmid => '12345',
:comments => str)
assert( c.save )
str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1.".force_encoding("UTF-8")
assert_equal str_utf8, c.comments
assert_equal 'Texte encodé en ISO-8859-1.', c.comments
end
def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
proj = Project.find(3)
# str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
str1 = "Texte encod\xe9 en ISO-8859-1.".force_encoding("UTF-8")
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".b
r = Repository::Bazaar.create!(
:project => proj,
:url => '/tmp/test/bazaar',
@ -479,7 +471,7 @@ class ChangesetTest < ActiveSupport::TestCase
:committed_on => Time.now,
:revision => '123',
:scmid => '12345',
:comments => str1,
:comments => "Texte encod\xE9 en ISO-8859-1.",
:committer => str2)
assert( c.save )
assert_equal "Texte encod? en ISO-8859-1.", c.comments
@ -488,7 +480,7 @@ class ChangesetTest < ActiveSupport::TestCase
def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
proj = Project.find(3)
str = "test\xb5\xfetest\xb5\xfe".force_encoding('ASCII-8BIT')
str = "test\xb5\xfetest\xb5\xfe".b
r = Repository::Bazaar.create!(
:project => proj,
:url => '/tmp/test/bazaar',
@ -504,12 +496,12 @@ class ChangesetTest < ActiveSupport::TestCase
end
def test_comments_should_be_converted_all_latin1_to_utf8
s1 = "\xC2\x80"
s2 = "\xc3\x82\xc2\x80"
s1 = +"\xC2\x80"
s2 = +"\xc3\x82\xc2\x80"
s4 = s2.dup
s3 = s1.dup
s1.force_encoding('ASCII-8BIT')
s2.force_encoding('ASCII-8BIT')
s1 = s1.b
s2 = s2.b
s3.force_encoding('ISO-8859-1')
s4.force_encoding('UTF-8')
assert_equal s3.encode('UTF-8'), s4
@ -530,8 +522,7 @@ class ChangesetTest < ActiveSupport::TestCase
def test_invalid_utf8_sequences_in_paths_should_be_replaced
proj = Project.find(3)
str1 = "Texte encod\xe9 en ISO-8859-1".force_encoding("UTF-8")
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".force_encoding("ASCII-8BIT")
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".b
r = Repository::Bazaar.create!(
:project => proj,
:url => '/tmp/test/bazaar',
@ -547,7 +538,7 @@ class ChangesetTest < ActiveSupport::TestCase
ch = Change.new(
:changeset => cs,
:action => "A",
:path => str1,
:path => "Texte encod\xE9 en ISO-8859-1",
:from_path => str2,
:from_revision => "345")
assert(ch.save)

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,7 +20,8 @@
require File.expand_path('../../test_helper', __FILE__)
class CommentTest < ActiveSupport::TestCase
fixtures :users, :email_addresses, :news, :comments, :projects, :enabled_modules
fixtures :users, :email_addresses, :news, :comments, :projects, :enabled_modules,
:user_preferences, :roles, :members, :member_roles
def setup
User.current = nil
@ -37,7 +40,7 @@ class CommentTest < ActiveSupport::TestCase
Watcher.create!(:watchable => @news, :user => @jsmith)
with_settings :notified_events => %w(news_comment_added) do
assert_difference 'ActionMailer::Base.deliveries.size' do
assert_difference 'ActionMailer::Base.deliveries.size', 2 do
Comment.create!(:commented => @news, :author => @jsmith, :comments => "my comment")
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,7 +22,11 @@ require File.expand_path('../../test_helper', __FILE__)
class CustomFieldTest < ActiveSupport::TestCase
fixtures :custom_fields, :roles, :projects,
:trackers, :issue_statuses,
:issues
:issues, :users
def setup
User.current = nil
end
def test_create
field = UserCustomField.new(:name => 'Money money money', :field_format => 'float')
@ -101,7 +107,7 @@ class CustomFieldTest < ActiveSupport::TestCase
def test_possible_values_should_return_utf8_encoded_strings
field = CustomField.new
s = "Value".force_encoding('BINARY')
s = "Value".b
field.possible_values = s
assert_equal [s], field.possible_values
assert_equal 'UTF-8', field.possible_values.first.encoding.name
@ -342,4 +348,28 @@ class CustomFieldTest < ActiveSupport::TestCase
assert_equal 12.5, field.cast_value('+12.5')
assert_equal -12.5, field.cast_value('-12.5')
end
def test_project_custom_field_visibility
project_field = ProjectCustomField.generate!(:visible => false, :field_format => 'list', :possible_values => %w[a b c])
project = Project.find(3)
project.custom_field_values = { project_field.id => 'a' }
# Admins can find projects with the field
with_current_user(User.find(1)) do
assert_includes Project.where(project_field.visibility_by_project_condition), project
end
# The field is not visible to normal users
with_current_user(User.find(2)) do
refute_includes Project.where(project_field.visibility_by_project_condition), project
end
end
def test_full_text_formatting?
field = IssueCustomField.create!(:name => 'Long text', :field_format => 'text', :text_formatting => 'full')
assert field.full_text_formatting?
field2 = IssueCustomField.create!(:name => 'Another long text', :field_format => 'text')
assert !field2.full_text_formatting?
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

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
@ -40,7 +42,7 @@ class DocumentCategoryTest < ActiveSupport::TestCase
def test_default
assert_nil DocumentCategory.where(:is_default => true).first
e = Enumeration.find_by_name('Technical documentation')
e.update_attributes(:is_default => true)
e.update(:is_default => true)
assert_equal 3, DocumentCategory.default.id
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,10 @@ class DocumentTest < ActiveSupport::TestCase
:users, :email_addresses, :members, :member_roles, :roles,
:groups_users
def setup
User.current = nil
end
def test_create
doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation'))
assert doc.save
@ -41,13 +47,13 @@ class DocumentTest < ActiveSupport::TestCase
doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation'))
assert doc.save
end
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal 2, ActionMailer::Base.deliveries.size
end
def test_create_with_default_category
# Sets a default category
e = Enumeration.find_by_name('Technical documentation')
e.update_attributes(:is_default => true)
e.update(:is_default => true)
doc = Document.new(:project => Project.find(1), :title => 'New document')
assert_equal e, doc.category

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2020 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
@ -15,16 +17,17 @@
# 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 File.expand_path('../../test_helper', __FILE__)
class SettingsHelperTest < Redmine::HelperTest
include SettingsHelper
include ERB::Util
class EmailAddressTest < ActiveSupport::TestCase
fixtures :users
def test_date_format_setting_options_should_include_human_readable_format
Date.stubs(:today).returns(Date.parse("2015-07-14"))
def setup
User.current = nil
end
options = date_format_setting_options('en')
assert_include ["2015-07-14 (yyyy-mm-dd)", "%Y-%m-%d"], options
def test_address_with_punycode_tld_should_be_valid
email = EmailAddress.new(address: 'jsmith@example.xn--80akhbyknj4f')
assert email.valid?
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
@ -51,7 +53,7 @@ class EnumerationTest < ActiveSupport::TestCase
assert e.is_a?(Enumeration)
assert e.is_default?
assert e.active?
e.update_attributes(:active => false)
e.update(:active => false)
assert e.is_default?
assert !e.active?
end
@ -72,19 +74,19 @@ class EnumerationTest < ActiveSupport::TestCase
def test_update_default
e = Enumeration.default
e.update_attributes(:name => 'Changed', :is_default => true)
e.update(:name => 'Changed', :is_default => true)
assert_equal e, Enumeration.default
end
def test_update_default_to_non_default
e = Enumeration.default
e.update_attributes(:name => 'Changed', :is_default => false)
e.update(:name => 'Changed', :is_default => false)
assert_nil Enumeration.default
end
def test_change_default
e = Enumeration.find_by_name('Default Enumeration')
e.update_attributes(:name => 'Changed Enumeration', :is_default => true)
e.update(:name => 'Changed Enumeration', :is_default => true)
assert_equal e, Enumeration.default
end
@ -166,6 +168,7 @@ class EnumerationTest < ActiveSupport::TestCase
def test_destroying_override_should_not_update_positions
Enumeration.delete_all
Issue.delete_all
a = IssuePriority.create!(:name => 'A')
b = IssuePriority.create!(:name => 'B')

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
@ -56,10 +58,9 @@ class GroupTest < ActiveSupport::TestCase
def test_blank_name_error_message_fr
set_language_if_valid 'fr'
str = "Nom doit \xc3\xaatre renseign\xc3\xa9(e)".force_encoding('UTF-8')
g = Group.new
assert !g.save
assert_include str, g.errors.full_messages
assert_include 'Nom doit être renseigné(e)', g.errors.full_messages
end
def test_group_roles_should_be_given_to_added_user

View file

@ -1,102 +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 ActivitiesHelperTest < Redmine::HelperTest
include ActivitiesHelper
class MockEvent
attr_reader :event_datetime, :event_group, :name
def initialize(group=nil)
@@count ||= 0
@name = "e#{@@count}"
@event_datetime = Time.now + @@count.hours
@event_group = group || self
@@count += 1
end
def self.clear
@@count = 0
end
end
def setup
super
MockEvent.clear
end
def test_sort_activity_events_should_sort_by_datetime
events = []
events << MockEvent.new
events << MockEvent.new
events << MockEvent.new
assert_equal [
['e2', false],
['e1', false],
['e0', false]
], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
end
def test_sort_activity_events_should_group_events
events = []
events << MockEvent.new
events << MockEvent.new(events[0])
events << MockEvent.new(events[0])
assert_equal [
['e2', false],
['e1', true],
['e0', true]
], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
end
def test_sort_activity_events_with_group_not_in_set_should_group_events
e = MockEvent.new
events = []
events << MockEvent.new(e)
events << MockEvent.new(e)
assert_equal [
['e2', false],
['e1', true]
], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
end
def test_sort_activity_events_should_sort_by_datetime_and_group
events = []
events << MockEvent.new
events << MockEvent.new
events << MockEvent.new
events << MockEvent.new(events[1])
events << MockEvent.new(events[2])
events << MockEvent.new
events << MockEvent.new(events[2])
assert_equal [
['e6', false],
['e4', true],
['e2', true],
['e5', false],
['e3', false],
['e1', true],
['e0', false]
], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
end
end

File diff suppressed because it is too large Load diff

View file

@ -1,89 +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 CustomFieldsHelperTest < Redmine::HelperTest
include ApplicationHelper
include CustomFieldsHelper
include ERB::Util
def test_format_boolean_value
I18n.locale = 'en'
assert_equal 'Yes', format_value('1', CustomField.new(:field_format => 'bool'))
assert_equal 'No', format_value('0', CustomField.new(:field_format => 'bool'))
end
def test_label_tag_should_include_description_as_span_title_if_present
field = CustomField.new(:field_format => 'string', :description => 'This is the description')
tag = custom_field_label_tag('foo', CustomValue.new(:custom_field => field))
assert_select_in tag, 'label span[title=?]', 'This is the description'
end
def test_label_tag_should_not_include_title_if_description_is_blank
field = CustomField.new(:field_format => 'string')
tag = custom_field_label_tag('foo', CustomValue.new(:custom_field => field))
assert_select_in tag, 'label span[title]', 0
end
def test_label_tag_should_include_for_attribute_for_select_tag
field = CustomField.new(:name => 'Foo', :field_format => 'list')
s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
assert_select_in s, 'label[for]'
end
def test_label_tag_should_not_include_for_attribute_for_checkboxes
field = CustomField.new(:name => 'Foo', :field_format => 'list', :edit_tag_style => 'check_box')
s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
assert_select_in s, 'label:not([for])'
end
def test_label_tag_should_include_for_attribute_for_bool_as_select_tag
field = CustomField.new(:name => 'Foo', :field_format => 'bool')
s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
assert_select_in s, 'label[for]'
end
def test_label_tag_should_include_for_attribute_for_bool_as_checkbox
field = CustomField.new(:name => 'Foo', :field_format => 'bool', :edit_tag_style => 'check_box')
s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
assert_select_in s, 'label[for]'
end
def test_label_tag_should_not_include_for_attribute_for_bool_as_radio
field = CustomField.new(:name => 'Foo', :field_format => 'bool', :edit_tag_style => 'radio')
s = custom_field_tag_with_label('foo', CustomValue.new(:custom_field => field))
assert_select_in s, 'label:not([for])'
end
def test_unknow_field_format_should_be_edited_as_string
field = CustomField.new(:field_format => 'foo')
value = CustomValue.new(:value => 'bar', :custom_field => field)
field.id = 52
assert_select_in custom_field_tag('object', value),
'input[type=text][value=bar][name=?]', 'object[custom_field_values][52]'
end
def test_unknow_field_format_should_be_bulk_edited_as_string
field = CustomField.new(:field_format => 'foo')
field.id = 52
assert_select_in custom_field_tag_for_bulk_edit('object', field),
'input[type=text][value=""][name=?]', 'object[custom_field_values][52]'
end
end

View file

@ -1,42 +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 GroupsHelperTest < Redmine::HelperTest
include ERB::Util
include GroupsHelper
include Rails.application.routes.url_helpers
fixtures :users
def test_render_principals_for_new_group_users
group = Group.generate!
result = render_principals_for_new_group_users(group)
assert_select_in result, 'input[name=?][value="2"]', 'user_ids[]'
end
def test_render_principals_for_new_group_users_with_limited_results_should_paginate
group = Group.generate!
result = render_principals_for_new_group_users(group, 3)
assert_select_in result, 'span.pagination'
assert_select_in result, 'span.pagination li.current span', :text => '1'
assert_select_in result, 'a[href=?]', "/groups/#{group.id}/autocomplete_for_user.js?page=2", :text => '2'
end
end

View file

@ -1,332 +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 IssuesHelperTest < Redmine::HelperTest
include IssuesHelper
include CustomFieldsHelper
include ERB::Util
include Rails.application.routes.url_helpers
fixtures :projects, :trackers, :issue_statuses, :issues,
:enumerations, :users, :issue_categories,
:projects_trackers,
:roles,
:member_roles,
:members,
:enabled_modules,
:custom_fields,
:attachments,
:versions
def test_issue_heading
assert_equal "Bug #1", issue_heading(Issue.find(1))
end
def test_issues_destroy_confirmation_message_with_one_root_issue
assert_equal l(:text_issues_destroy_confirmation),
issues_destroy_confirmation_message(Issue.find(1))
end
def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
assert_equal l(:text_issues_destroy_confirmation),
issues_destroy_confirmation_message(Issue.find([1, 2]))
end
def test_issues_destroy_confirmation_message_with_one_parent_issue
Issue.find(2).update! :parent_issue_id => 1
assert_equal l(:text_issues_destroy_confirmation) + "\n" +
l(:text_issues_destroy_descendants_confirmation, :count => 1),
issues_destroy_confirmation_message(Issue.find(1))
end
def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
Issue.find(2).update! :parent_issue_id => 1
assert_equal l(:text_issues_destroy_confirmation),
issues_destroy_confirmation_message(Issue.find([1, 2]))
end
def test_issues_destroy_confirmation_message_with_issues_that_share_descendants
root = Issue.generate!
child = Issue.generate!(:parent_issue_id => root.id)
Issue.generate!(:parent_issue_id => child.id)
assert_equal l(:text_issues_destroy_confirmation) + "\n" +
l(:text_issues_destroy_descendants_confirmation, :count => 1),
issues_destroy_confirmation_message([root.reload, child.reload])
end
test 'show_detail with no_html should show a changing attribute' do
detail = JournalDetail.new(:property => 'attr', :old_value => '40',
:value => '100', :prop_key => 'done_ratio')
assert_equal "% Done changed from 40 to 100", show_detail(detail, true)
end
test 'show_detail with no_html should show a new attribute' do
detail = JournalDetail.new(:property => 'attr', :old_value => nil,
:value => '100', :prop_key => 'done_ratio')
assert_equal "% Done set to 100", show_detail(detail, true)
end
test 'show_detail with no_html should show a deleted attribute' do
detail = JournalDetail.new(:property => 'attr', :old_value => '50',
:value => nil, :prop_key => 'done_ratio')
assert_equal "% Done deleted (50)", show_detail(detail, true)
end
test 'show_detail with html should show a changing attribute with HTML highlights' do
detail = JournalDetail.new(:property => 'attr', :old_value => '40',
:value => '100', :prop_key => 'done_ratio')
html = show_detail(detail, false)
assert_include '<strong>% Done</strong>', html
assert_include '<i>40</i>', html
assert_include '<i>100</i>', html
end
test 'show_detail with html should show a new attribute with HTML highlights' do
detail = JournalDetail.new(:property => 'attr', :old_value => nil,
:value => '100', :prop_key => 'done_ratio')
html = show_detail(detail, false)
assert_include '<strong>% Done</strong>', html
assert_include '<i>100</i>', html
end
test 'show_detail with html should show a deleted attribute with HTML highlights' do
detail = JournalDetail.new(:property => 'attr', :old_value => '50',
:value => nil, :prop_key => 'done_ratio')
html = show_detail(detail, false)
assert_include '<strong>% Done</strong>', html
assert_include '<del><i>50</i></del>', html
end
test 'show_detail with a start_date attribute should format the dates' do
detail = JournalDetail.new(
:property => 'attr',
:old_value => '2010-01-01',
:value => '2010-01-31',
:prop_key => 'start_date'
)
with_settings :date_format => '%m/%d/%Y' do
assert_match "01/31/2010", show_detail(detail, true)
assert_match "01/01/2010", show_detail(detail, true)
end
end
test 'show_detail with a due_date attribute should format the dates' do
detail = JournalDetail.new(
:property => 'attr',
:old_value => '2010-01-01',
:value => '2010-01-31',
:prop_key => 'due_date'
)
with_settings :date_format => '%m/%d/%Y' do
assert_match "01/31/2010", show_detail(detail, true)
assert_match "01/01/2010", show_detail(detail, true)
end
end
test 'show_detail should show old and new values with a project attribute' do
detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id',
:old_value => 1, :value => 2)
assert_match 'eCookbook', show_detail(detail, true)
assert_match 'OnlineStore', show_detail(detail, true)
end
test 'show_detail should show old and new values with a issue status attribute' do
detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id',
:old_value => 1, :value => 2)
assert_match 'New', show_detail(detail, true)
assert_match 'Assigned', show_detail(detail, true)
end
test 'show_detail should show old and new values with a tracker attribute' do
detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id',
:old_value => 1, :value => 2)
assert_match 'Bug', show_detail(detail, true)
assert_match 'Feature request', show_detail(detail, true)
end
test 'show_detail should show old and new values with a assigned to attribute' do
detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id',
:old_value => 1, :value => 2)
assert_match 'Redmine Admin', show_detail(detail, true)
assert_match 'John Smith', show_detail(detail, true)
end
test 'show_detail should show old and new values with a priority attribute' do
detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id',
:old_value => 4, :value => 5)
assert_match 'Low', show_detail(detail, true)
assert_match 'Normal', show_detail(detail, true)
end
test 'show_detail should show old and new values with a category attribute' do
detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id',
:old_value => 1, :value => 2)
assert_match 'Printing', show_detail(detail, true)
assert_match 'Recipes', show_detail(detail, true)
end
test 'show_detail should show old and new values with a fixed version attribute' do
detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id',
:old_value => 1, :value => 2)
assert_match '0.1', show_detail(detail, true)
assert_match '1.0', show_detail(detail, true)
end
test 'show_detail should show old and new values with a estimated hours attribute' do
detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours',
:old_value => '5', :value => '6.3')
assert_match '5.00', show_detail(detail, true)
assert_match '6.30', show_detail(detail, true)
end
test 'show_detail should not show values with a description attribute' do
detail = JournalDetail.new(:property => 'attr', :prop_key => 'description',
:old_value => 'Foo', :value => 'Bar')
assert_equal 'Description updated', show_detail(detail, true)
end
test 'show_detail should show old and new values with a custom field' do
detail = JournalDetail.new(:property => 'cf', :prop_key => '1',
:old_value => 'MySQL', :value => 'PostgreSQL')
assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true)
end
test 'show_detail should not show values with a long text custom field' do
field = IssueCustomField.create!(:name => "Long field", :field_format => 'text')
detail = JournalDetail.new(:property => 'cf', :prop_key => field.id,
:old_value => 'Foo', :value => 'Bar')
assert_equal 'Long field updated', show_detail(detail, true)
end
test 'show_detail should show added file' do
detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
:old_value => nil, :value => 'error281.txt')
assert_match 'error281.txt', show_detail(detail, true)
end
test 'show_detail should show removed file' do
detail = JournalDetail.new(:property => 'attachment', :prop_key => '1',
:old_value => 'error281.txt', :value => nil)
assert_match 'error281.txt', show_detail(detail, true)
end
def test_show_detail_relation_added
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'precedes',
:value => 1)
assert_equal "Precedes Bug #1: Cannot print recipes added", show_detail(detail, true)
str = link_to("Bug #1", "/issues/1", :class => Issue.find(1).css_classes)
assert_equal "<strong>Precedes</strong> <i>#{str}: Cannot print recipes</i> added",
show_detail(detail, false)
end
def test_show_detail_relation_added_with_inexistant_issue
inexistant_issue_number = 9999
assert_nil Issue.find_by_id(inexistant_issue_number)
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'precedes',
:value => inexistant_issue_number)
assert_equal "Precedes Issue ##{inexistant_issue_number} added", show_detail(detail, true)
assert_equal "<strong>Precedes</strong> <i>Issue ##{inexistant_issue_number}</i> added", show_detail(detail, false)
end
def test_show_detail_relation_added_should_not_disclose_issue_that_is_not_visible
issue = Issue.generate!(:is_private => true)
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'precedes',
:value => issue.id)
assert_equal "Precedes Issue ##{issue.id} added", show_detail(detail, true)
assert_equal "<strong>Precedes</strong> <i>Issue ##{issue.id}</i> added", show_detail(detail, false)
end
def test_show_detail_relation_deleted
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'precedes',
:old_value => 1)
assert_equal "Precedes deleted (Bug #1: Cannot print recipes)", show_detail(detail, true)
str = link_to("Bug #1",
"/issues/1",
:class => Issue.find(1).css_classes)
assert_equal "<strong>Precedes</strong> deleted (<i>#{str}: Cannot print recipes</i>)",
show_detail(detail, false)
end
def test_show_detail_relation_deleted_with_inexistant_issue
inexistant_issue_number = 9999
assert_nil Issue.find_by_id(inexistant_issue_number)
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'precedes',
:old_value => inexistant_issue_number)
assert_equal "Precedes deleted (Issue #9999)", show_detail(detail, true)
assert_equal "<strong>Precedes</strong> deleted (<i>Issue #9999</i>)", show_detail(detail, false)
end
def test_show_detail_relation_deleted_should_not_disclose_issue_that_is_not_visible
issue = Issue.generate!(:is_private => true)
detail = JournalDetail.new(:property => 'relation',
:prop_key => 'precedes',
:old_value => issue.id)
assert_equal "Precedes deleted (Issue ##{issue.id})", show_detail(detail, true)
assert_equal "<strong>Precedes</strong> deleted (<i>Issue ##{issue.id}</i>)", show_detail(detail, false)
end
def test_details_to_strings_with_multiple_values_removed_from_custom_field
field = IssueCustomField.generate!(:name => 'User', :field_format => 'user', :multiple => true)
details = []
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '1', :value => nil)
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '3', :value => nil)
assert_equal ["User deleted (Dave Lopper, Redmine Admin)"], details_to_strings(details, true)
assert_equal ["<strong>User</strong> deleted (<del><i>Dave Lopper, Redmine Admin</i></del>)"], details_to_strings(details, false)
end
def test_details_to_strings_with_multiple_values_added_to_custom_field
field = IssueCustomField.generate!(:name => 'User', :field_format => 'user', :multiple => true)
details = []
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => nil, :value => '1')
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => nil, :value => '3')
assert_equal ["User Dave Lopper, Redmine Admin added"], details_to_strings(details, true)
assert_equal ["<strong>User</strong> <i>Dave Lopper, Redmine Admin</i> added"], details_to_strings(details, false)
end
def test_details_to_strings_with_multiple_values_added_and_removed_from_custom_field
field = IssueCustomField.generate!(:name => 'User', :field_format => 'user', :multiple => true)
details = []
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => nil, :value => '1')
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '2', :value => nil)
details << JournalDetail.new(:property => 'cf', :prop_key => field.id.to_s, :old_value => '3', :value => nil)
assert_equal [
"User Redmine Admin added",
"User deleted (Dave Lopper, John Smith)"
], details_to_strings(details, true)
assert_equal [
"<strong>User</strong> <i>Redmine Admin</i> added",
"<strong>User</strong> deleted (<del><i>Dave Lopper, John Smith</i></del>)"
], details_to_strings(details, false)
end
def test_find_name_by_reflection_should_return_nil_for_missing_record
assert_nil find_name_by_reflection('status', 99)
end
end

View file

@ -1,48 +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 JournalsHelperTest < Redmine::HelperTest
include JournalsHelper
fixtures :projects, :trackers, :issue_statuses, :issues,
:enumerations, :issue_categories,
:projects_trackers,
:users, :roles, :member_roles, :members,
:enabled_modules,
:custom_fields,
:attachments,
:versions
def test_journal_thumbnail_attachments_should_return_thumbnailable_attachments
issue = Issue.generate!
journal = new_record(Journal) do
issue.init_journal(User.find(1))
issue.attachments << Attachment.new(:file => mock_file_with_options(:original_filename => 'image.png'), :author => User.find(1))
issue.attachments << Attachment.new(:file => mock_file_with_options(:original_filename => 'foo'), :author => User.find(1))
issue.save
end
assert_equal 2, journal.details.count
thumbnails = journal_thumbnail_attachments(journal)
assert_equal 1, thumbnails.count
assert_kind_of Attachment, thumbnails.first
assert_equal 'image.png', thumbnails.first.filename
end
end

View file

@ -1,43 +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 MembersHelperTest < Redmine::HelperTest
include ERB::Util
include MembersHelper
include Rails.application.routes.url_helpers
fixtures :projects, :users, :members, :member_roles,
:trackers, :issue_statuses
def test_render_principals_for_new_members
project = Project.generate!
result = render_principals_for_new_members(project)
assert_select_in result, 'input[name=?][value="2"]', 'membership[user_ids][]'
end
def test_render_principals_for_new_members_with_limited_results_should_paginate
project = Project.generate!
result = render_principals_for_new_members(project, 3)
assert_select_in result, 'span.pagination'
assert_select_in result, 'span.pagination li.current span', :text => '1'
assert_select_in result, 'a[href=?]', "/projects/#{project.identifier}/memberships/autocomplete.js?page=2", :text => '2'
end
end

View file

@ -1,78 +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 ProjectsHelperTest < Redmine::HelperTest
include ApplicationHelper
include ProjectsHelper
include ERB::Util
include Rails.application.routes.url_helpers
fixtures :projects, :trackers, :issue_statuses, :issues,
:enumerations, :users, :issue_categories,
:versions,
:projects_trackers,
:member_roles,
:members,
:groups_users,
:enabled_modules
def test_link_to_version_within_project
@project = Project.find(2)
User.current = User.find(1)
assert_equal '<a title="07/01/2006" href="/versions/5">Alpha</a>', link_to_version(Version.find(5))
end
def test_link_to_version
User.current = User.find(1)
assert_equal '<a title="07/01/2006" href="/versions/5">OnlineStore - Alpha</a>', link_to_version(Version.find(5))
end
def test_link_to_version_without_effective_date
User.current = User.find(1)
version = Version.find(5)
version.effective_date = nil
assert_equal '<a href="/versions/5">OnlineStore - Alpha</a>', link_to_version(version)
end
def test_link_to_private_version
assert_equal 'OnlineStore - Alpha', link_to_version(Version.find(5))
end
def test_link_to_version_invalid_version
assert_equal '', link_to_version(Object)
end
def test_format_version_name_within_project
@project = Project.find(1)
assert_equal "0.1", format_version_name(Version.find(1))
end
def test_format_version_name
assert_equal "eCookbook - 0.1", format_version_name(Version.find(1))
end
def test_format_version_name_for_system_version
assert_equal "OnlineStore - Systemwide visible version", format_version_name(Version.find(7))
end
def test_version_options_for_select_with_no_versions
assert_equal '', version_options_for_select([])
assert_equal '', version_options_for_select([], Version.find(1))
end
end

View file

@ -1,96 +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 QueriesHelperTest < Redmine::HelperTest
include QueriesHelper
fixtures :projects, :enabled_modules, :users, :members,
:member_roles, :roles, :trackers, :issue_statuses,
:issue_categories, :enumerations, :issues,
:watchers, :custom_fields, :custom_values, :versions,
:queries,
:projects_trackers,
:custom_fields_trackers
def test_filters_options_for_select_should_have_a_blank_option
options = filters_options_for_select(IssueQuery.new)
assert_select_in options, 'option[value=""]'
end
def test_filters_options_for_select_should_not_group_regular_filters
with_locale 'en' do
options = filters_options_for_select(IssueQuery.new)
assert_select_in options, 'optgroup option[value=status_id]', 0
assert_select_in options, 'option[value=status_id]', :text => 'Status'
end
end
def test_filters_options_for_select_should_group_date_filters
with_locale 'en' do
options = filters_options_for_select(IssueQuery.new)
assert_select_in options, 'optgroup[label=?]', 'Date', 1
assert_select_in options, 'optgroup > option[value=due_date]', :text => 'Due date'
end
end
def test_filters_options_for_select_should_not_group_only_one_date_filter
with_locale 'en' do
options = filters_options_for_select(TimeEntryQuery.new)
assert_select_in options, 'option[value=spent_on]'
assert_select_in options, 'optgroup[label=?]', 'Date', 0
assert_select_in options, 'optgroup option[value=spent_on]', 0
end
end
def test_filters_options_for_select_should_group_relations_filters
with_locale 'en' do
options = filters_options_for_select(IssueQuery.new)
assert_select_in options, 'optgroup[label=?]', 'Relations', 1
assert_select_in options, 'optgroup[label=?] > option', 'Relations', 11
assert_select_in options, 'optgroup > option[value=relates]', :text => 'Related to'
end
end
def test_filters_options_for_select_should_group_associations_filters
CustomField.delete_all
cf1 = ProjectCustomField.create!(:name => 'Foo', :field_format => 'string', :is_filter => true)
cf2 = ProjectCustomField.create!(:name => 'Bar', :field_format => 'string', :is_filter => true)
with_locale 'en' do
options = filters_options_for_select(IssueQuery.new)
assert_select_in options, 'optgroup[label=?]', 'Project', 1
assert_select_in options, 'optgroup[label=?] > option', 'Project', 2
assert_select_in options, 'optgroup > option[value=?]', "project.cf_#{cf1.id}", :text => "Project's Foo"
end
end
def test_query_to_csv_should_translate_boolean_custom_field_values
f = IssueCustomField.generate!(:field_format => 'bool', :name => 'Boolean', :is_for_all => true, :trackers => Tracker.all)
issues = [
Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {f.id.to_s => '0'}),
Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {f.id.to_s => '1'})
]
with_locale 'fr' do
csv = query_to_csv(issues, IssueQuery.new(:column_names => ['id', "cf_#{f.id}"]))
assert_include "Oui", csv
assert_include "Non", csv
end
end
end

View file

@ -1,43 +0,0 @@
# encoding: utf-8
#
# 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 RoutesHelperTest < Redmine::HelperTest
fixtures :projects, :issues
include Rails.application.routes.url_helpers
def test_time_entries_path
assert_equal '/projects/ecookbook/time_entries', _time_entries_path(Project.find(1), nil)
assert_equal '/time_entries', _time_entries_path(nil, nil)
end
def test_report_time_entries_path
assert_equal '/projects/ecookbook/time_entries/report', _report_time_entries_path(Project.find(1), nil)
assert_equal '/time_entries/report', _report_time_entries_path(nil, nil)
end
def test_new_time_entry_path
assert_equal '/projects/ecookbook/time_entries/new', _new_time_entry_path(Project.find(1), nil)
assert_equal '/issues/1/time_entries/new', _new_time_entry_path(Project.find(1), Issue.find(1))
assert_equal '/issues/1/time_entries/new', _new_time_entry_path(nil, Issue.find(1))
assert_equal '/time_entries/new', _new_time_entry_path(nil, nil)
end
end

View file

@ -1,48 +0,0 @@
# encoding: utf-8
#
# 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 SearchHelperTest < Redmine::HelperTest
include SearchHelper
include ERB::Util
def test_highlight_single_token
assert_equal 'This is a <span class="highlight token-0">token</span>.',
highlight_tokens('This is a token.', %w(token))
end
def test_highlight_multiple_tokens
assert_equal 'This is a <span class="highlight token-0">token</span> and <span class="highlight token-1">another</span> <span class="highlight token-0">token</span>.',
highlight_tokens('This is a token and another token.', %w(token another))
end
def test_highlight_should_not_exceed_maximum_length
s = (('1234567890' * 100) + ' token ') * 100
r = highlight_tokens(s, %w(token))
assert r.include?('<span class="highlight token-0">token</span>')
assert r.length <= 1300
end
def test_highlight_multibyte
s = ('й' * 200) + ' token ' + ('й' * 200)
r = highlight_tokens(s, %w(token))
assert_equal ('й' * 45) + ' ... ' + ('й' * 44) + ' <span class="highlight token-0">token</span> ' + ('й' * 44) + ' ... ' + ('й' * 45), r
end
end

View file

@ -1,109 +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 SortHelperTest < Redmine::HelperTest
include SortHelper
include ERB::Util
def setup
super
@session = nil
@sort_param = nil
end
def test_default_sort_clause_with_array
sort_init 'attr1', 'desc'
sort_update(['attr1', 'attr2'])
assert_equal ['attr1 DESC'], sort_clause
end
def test_default_sort_clause_with_hash
sort_init 'attr1', 'desc'
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
assert_equal ['table1.attr1 DESC'], sort_clause
end
def test_default_sort_clause_with_multiple_columns
sort_init 'attr1', 'desc'
sort_update({'attr1' => ['table1.attr1', 'table1.attr2'], 'attr2' => 'table2.attr2'})
assert_equal ['table1.attr1 DESC', 'table1.attr2 DESC'], sort_clause
end
def test_params_sort
@sort_param = 'attr1,attr2:desc'
sort_init 'attr1', 'desc'
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
assert_equal ['table1.attr1 ASC', 'table2.attr2 DESC'], sort_clause
assert_equal 'attr1,attr2:desc', @session['foo_bar_sort']
end
def test_invalid_params_sort
@sort_param = 'invalid_key'
sort_init 'attr1', 'desc'
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
assert_nil sort_clause
assert_equal 'invalid_key', @session['foo_bar_sort']
end
def test_invalid_order_params_sort
@sort_param = 'attr1:foo:bar,attr2'
sort_init 'attr1', 'desc'
sort_update({'attr1' => 'table1.attr1', 'attr2' => 'table2.attr2'})
assert_equal ['table1.attr1 ASC', 'table2.attr2 ASC'], sort_clause
assert_equal 'attr1,attr2', @session['foo_bar_sort']
end
def test_sort_css_without_params_should_use_default_sort
sort_init 'attr1', 'desc'
sort_update(['attr1', 'attr2'])
assert_equal 'sort-by-attr1 sort-desc', sort_css_classes
end
def test_sort_css_should_use_params
@sort_param = 'attr2,attr1'
sort_init 'attr1', 'desc'
sort_update(['attr1', 'attr2'])
assert_equal 'sort-by-attr2 sort-asc', sort_css_classes
end
def test_sort_css_should_dasherize_sort_name
sort_init 'foo_bar'
sort_update(['foo_bar'])
assert_equal 'sort-by-foo-bar sort-asc', sort_css_classes
end
private
def controller_name; 'foo'; end
def action_name; 'bar'; end
def params; {:sort => @sort_param}; end
def session; @session ||= {}; end
end

View file

@ -1,53 +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 TimelogHelperTest < Redmine::HelperTest
include TimelogHelper
include ActionView::Helpers::TextHelper
include ActionView::Helpers::DateHelper
include ERB::Util
fixtures :projects, :roles, :enabled_modules, :users,
:repositories, :changesets,
:trackers, :issue_statuses, :issues, :versions, :documents,
:wikis, :wiki_pages, :wiki_contents,
:boards, :messages,
:attachments,
:enumerations
def test_activities_collection_for_select_options_should_return_array_of_activity_names_and_ids
activities = activity_collection_for_select_options
assert activities.include?(["Design", 9])
assert activities.include?(["Development", 10])
end
def test_activities_collection_for_select_options_should_not_include_inactive_activities
activities = activity_collection_for_select_options
assert !activities.include?(["Inactive Activity", 14])
end
def test_activities_collection_for_select_options_should_use_the_projects_override
project = Project.find(1)
override_activity = TimeEntryActivity.create!({:name => "Design override", :parent => TimeEntryActivity.find_by_name("Design"), :project => project})
activities = activity_collection_for_select_options(nil, project)
assert !activities.include?(["Design", 9]), "System activity found in: " + activities.inspect
assert activities.include?(["Design override", override_activity.id]), "Override activity not found in: " + activities.inspect
end
end

View file

@ -1,54 +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 VersionsHelperTest < Redmine::HelperTest
include Rails.application.routes.url_helpers
fixtures :projects, :versions
def test_version_filtered_issues_path_sharing_none
version = Version.new(:name => 'test', :sharing => 'none')
version.project = Project.find(5)
assert_match '/projects/private-child/issues?', version_filtered_issues_path(version)
end
def test_version_filtered_issues_path_sharing_descendants
version = Version.new(:name => 'test', :sharing => 'descendants')
version.project = Project.find(5)
assert_match '/projects/private-child/issues?', version_filtered_issues_path(version)
end
def test_version_filtered_issues_path_sharing_hierarchy
version = Version.new(:name => 'test', :sharing => 'hierarchy')
version.project = Project.find(5)
assert_match '/projects/ecookbook/issues?', version_filtered_issues_path(version)
end
def test_version_filtered_issues_path_sharing_tree
version = Version.new(:name => 'test', :sharing => 'tree')
version.project = Project.find(5)
assert_match '/projects/ecookbook/issues?', version_filtered_issues_path(version)
end
def test_version_filtered_issues_path_sharing_system
version = Version.new(:name => 'test', :sharing => 'system')
version.project = Project.find(5)
assert_match /^\/issues\?/, version_filtered_issues_path(version)
end
end

View file

@ -1,67 +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 WatchersHelperTest < Redmine::HelperTest
include WatchersHelper
include Rails.application.routes.url_helpers
fixtures :users, :issues
test '#watcher_link with a non-watched object' do
expected = link_to(
"Watch",
"/watchers/watch?object_id=1&object_type=issue",
:remote => true, :method => 'post', :class => "issue-1-watcher icon icon-fav-off"
)
assert_equal expected, watcher_link(Issue.find(1), User.find(1))
end
test '#watcher_link with a single objet array' do
expected = link_to(
"Watch",
"/watchers/watch?object_id=1&object_type=issue",
:remote => true, :method => 'post', :class => "issue-1-watcher icon icon-fav-off"
)
assert_equal expected, watcher_link([Issue.find(1)], User.find(1))
end
test '#watcher_link with a multiple objets array' do
expected = link_to(
"Watch",
"/watchers/watch?object_id%5B%5D=1&object_id%5B%5D=3&object_type=issue",
:remote => true, :method => 'post', :class => "issue-bulk-watcher icon icon-fav-off"
)
assert_equal expected, watcher_link([Issue.find(1), Issue.find(3)], User.find(1))
end
def test_watcher_link_with_nil_should_return_empty_string
assert_equal '', watcher_link(nil, User.find(1))
end
test '#watcher_link with a watched object' do
Watcher.create!(:watchable => Issue.find(1), :user => User.find(1))
expected = link_to(
"Unwatch",
"/watchers/watch?object_id=1&object_type=issue",
:remote => true, :method => 'delete', :class => "issue-1-watcher icon icon-fav"
)
assert_equal expected, watcher_link(Issue.find(1), User.find(1))
end
end

View file

@ -1,45 +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 WikiHelperTest < Redmine::HelperTest
include WikiHelper
include Rails.application.routes.url_helpers
fixtures :projects, :users,
:roles, :member_roles, :members,
:enabled_modules, :wikis, :wiki_pages
def test_wiki_page_edit_cancel_path_for_new_page_without_parent_should_be_wiki_index
wiki = Wiki.find(1)
page = WikiPage.new(:wiki => wiki)
assert_equal '/projects/ecookbook/wiki/index', wiki_page_edit_cancel_path(page)
end
def test_wiki_page_edit_cancel_path_for_new_page_with_parent_should_be_parent
wiki = Wiki.find(1)
page = WikiPage.new(:wiki => wiki, :parent => wiki.find_page('Another_page'))
assert_equal '/projects/ecookbook/wiki/Another_page', wiki_page_edit_cancel_path(page)
end
def test_wiki_page_edit_cancel_path_for_existing_page_should_be_the_page
wiki = Wiki.find(1)
page = wiki.find_page('Child_1')
assert_equal '/projects/ecookbook/wiki/Child_1', wiki_page_edit_cancel_path(page)
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,16 +24,6 @@ class PatchesTest < ActiveSupport::TestCase
def setup
Setting.default_language = 'en'
@symbols = { :a => 1, :b => 2 }
@keys = %w( blue green red pink orange )
@values = %w( 000099 009900 aa0000 cc0066 cc6633 )
@hash = Hash.new
@ordered_hash = ActiveSupport::OrderedHash.new
@keys.each_with_index do |key, index|
@hash[key] = @values[index]
@ordered_hash[key] = @values[index]
end
end
test "ActiveRecord::Base.human_attribute_name should transform name to field_name" do
@ -45,51 +37,4 @@ class PatchesTest < ActiveSupport::TestCase
test "ActiveRecord::Base.human_attribute_name should default to humanized value if no translation has been found (useful for custom fields)" do
assert_equal 'Patch name', ActiveRecord::Base.human_attribute_name('Patch name')
end
# https://github.com/rails/rails/pull/14198/files
def test_indifferent_select
hash = ActiveSupport::HashWithIndifferentAccess.new(@symbols).select { |_ ,v| v == 1 }
assert_equal({ 'a' => 1 }, hash)
assert_instance_of ((Rails::VERSION::MAJOR < 4 && RUBY_VERSION < "2.1") ?
Hash : ActiveSupport::HashWithIndifferentAccess),
hash
end
def test_indifferent_select_bang
indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@symbols)
indifferent_strings.select! { |_, v| v == 1 }
assert_equal({ 'a' => 1 }, indifferent_strings)
assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
end
def test_indifferent_reject
hash = ActiveSupport::HashWithIndifferentAccess.new(@symbols).reject { |_, v| v != 1 }
assert_equal({ 'a' => 1 }, hash)
assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
end
def test_indifferent_reject_bang
indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@symbols)
indifferent_strings.reject! { |_, v| v != 1 }
assert_equal({ 'a' => 1 }, indifferent_strings)
assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
end
def test_select
assert_equal @keys, @ordered_hash.select { true }.map(&:first)
new_ordered_hash = @ordered_hash.select { true }
assert_equal @keys, new_ordered_hash.map(&:first)
assert_instance_of ((Rails::VERSION::MAJOR < 4 && RUBY_VERSION < "2.1") ?
Hash : ActiveSupport::OrderedHash),
new_ordered_hash
end
def test_reject
copy = @ordered_hash.dup
new_ordered_hash = @ordered_hash.reject { |k, _| k == 'pink' }
assert_equal copy, @ordered_hash
assert !new_ordered_hash.keys.include?('pink')
assert @ordered_hash.keys.include?('pink')
assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash
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
@ -24,7 +26,6 @@ class IssueCustomFieldTest < ActiveSupport::TestCase
def setup
User.current = nil
@category = IssueCategory.find(1)
end
def test_custom_field_with_visible_set_to_false_should_validate_roles

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
@ -39,6 +41,12 @@ class IssueImportTest < ActiveSupport::TestCase
set_language_if_valid 'en'
end
def test_authorized
assert IssueImport.authorized?(User.find(1)) # admins
assert IssueImport.authorized?(User.find(2)) # has import_issues permission
assert !IssueImport.authorized?(User.find(3)) # does not have permission
end
def test_create_versions_should_create_missing_versions
import = generate_import_with_mapping
import.mapping.merge!('fixed_version' => '9', 'create_versions' => '1')
@ -138,6 +146,16 @@ class IssueImportTest < ActiveSupport::TestCase
assert_equal child2, grandchild.parent
end
def test_backward_and_forward_reference_with_unique_id
import = generate_import_with_mapping('import_subtasks_with_unique_id.csv')
import.settings['mapping'] = {'project_id' => '1', 'unique_id' => '0', 'tracker' => '1', 'subject' => '2', 'parent_issue_id' => '3'}
import.save!
root, child1, grandchild, child2 = new_records(Issue, 4) { import.run }
assert_equal root, child1.parent
assert_equal child2, grandchild.parent
end
def test_assignee_should_be_set
import = generate_import_with_mapping
import.mapping.merge!('assigned_to' => '11')
@ -157,6 +175,35 @@ class IssueImportTest < ActiveSupport::TestCase
assert_equal '3', issues.first.custom_field_value(field)
end
def test_list_custom_field_should_be_set
field = CustomField.find(1)
field.tracker_ids = Tracker.all.ids
field.save!
import = generate_import_with_mapping
import.mapping.merge!("cf_1" => '8')
import.save!
issues = new_records(Issue, 3) { import.run }
assert_equal 'PostgreSQL', issues[0].custom_field_value(1)
assert_equal 'MySQL', issues[1].custom_field_value(1)
assert_equal '', issues.third.custom_field_value(1)
end
def test_multiple_list_custom_field_should_be_set
field = CustomField.find(1)
field.tracker_ids = Tracker.all.ids
field.multiple = true
field.save!
import = generate_import_with_mapping
import.mapping.merge!("cf_1" => '15')
import.save!
issues = new_records(Issue, 3) { import.run }
assert_equal ['Oracle', 'PostgreSQL'], issues[0].custom_field_value(1).sort
assert_equal ['MySQL'], issues[1].custom_field_value(1)
assert_equal [''], issues.third.custom_field_value(1)
end
def test_is_private_should_be_set_based_on_user_locale
import = generate_import_with_mapping
import.mapping.merge!('is_private' => '6')
@ -178,6 +225,15 @@ class IssueImportTest < ActiveSupport::TestCase
assert_equal Date.parse('2015-07-10'), issue.start_date
assert_equal Date.parse('2015-08-12'), issue.due_date
assert_equal '2015-07-14', issue.custom_field_value(field)
# Tests using other date formats
import = generate_import_with_mapping('import_dates_ja.csv')
import.settings.merge!('date_format' => Import::DATE_FORMATS[3])
import.mapping.merge!('tracker' => 'value:1', 'subject' => '0', 'start_date' => '1')
import.save!
issue = new_record(Issue) { import.run }
assert_equal Date.parse('2019-05-28'), issue.start_date
end
def test_date_format_should_default_to_user_language
@ -210,4 +266,32 @@ class IssueImportTest < ActiveSupport::TestCase
issues = new_records(Issue, 3) { import.run }
assert [nil, 3, system_version.id], issues.map(&:fixed_version_id)
end
def test_set_default_settings_with_project_id
import = Import.new
import.set_default_settings(:project_id => 3)
assert_equal 3, import.mapping['project_id']
end
def test_set_default_settings_with_project_identifier
import = Import.new
import.set_default_settings(:project_id => 'ecookbook')
assert_equal 1, import.mapping['project_id']
end
def test_set_default_settings_without_project_id
import = Import.new
import.set_default_settings
assert_empty import.mapping
end
def test_set_default_settings_with_invalid_project_should_not_fail
import = Import.new
import.set_default_settings(:project_id => 'abc')
assert_empty import.mapping
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
@ -24,7 +26,7 @@ class IssueNestedSetConcurrencyTest < ActiveSupport::TestCase
:issue_statuses,
:enumerations
self.use_transactional_fixtures = false
self.use_transactional_tests = false
def setup
skip if sqlite? || mysql?
@ -82,7 +84,7 @@ class IssueNestedSetConcurrencyTest < ActiveSupport::TestCase
ActiveRecord::Base.connection_pool.with_connection do
begin
yield
rescue Exception => e
rescue => e
Thread.current[:exception] = e.message
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
@ -24,6 +26,10 @@ class IssueNestedSetTest < ActiveSupport::TestCase
:enumerations,
:issues
def setup
User.current = nil
end
def test_new_record_is_leaf
i = Issue.new
assert i.leaf?

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
@ -99,6 +101,13 @@ class IssuePriorityTest < ActiveSupport::TestCase
assert_equal 'highest', IssuePriority.active.order(:position).last.position_name
end
def test_changing_default_priority_should_update_position_names
prio = IssuePriority.first
prio.is_default = true
prio.save
assert_equal %w(default high4 high3 high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)
end
def test_destroying_a_priority_should_update_position_names
IssuePriority.find_by_position_name('highest').destroy
assert_equal %w(lowest default high2 highest), IssuePriority.active.to_a.sort.map(&:position_name)

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
@ -59,11 +61,18 @@ class IssueStatusTest < ActiveSupport::TestCase
def test_new_statuses_allowed_to
WorkflowTransition.delete_all
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2, :author => false, :assignee => false)
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3, :author => true, :assignee => false)
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4, :author => false, :assignee => true)
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5, :author => true, :assignee => true)
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
:old_status_id => 1, :new_status_id => 2,
:author => false, :assignee => false)
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
:old_status_id => 1, :new_status_id => 3,
:author => true, :assignee => false)
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
:old_status_id => 1, :new_status_id => 4,
:author => false, :assignee => true)
WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
:old_status_id => 1, :new_status_id => 5,
:author => true, :assignee => true)
status = IssueStatus.find(1)
role = Role.find(1)
tracker = Tracker.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
@ -161,6 +163,17 @@ class IssueSubtaskingTest < ActiveSupport::TestCase
end
end
def test_parent_done_ratio_should_be_rounded_down_to_the_nearest_integer
with_settings :parent_issue_done_ratio => 'derived' do
parent = Issue.generate!
parent.generate_child!(:done_ratio => 20)
parent.generate_child!(:done_ratio => 20)
parent.generate_child!(:done_ratio => 10)
# (20 + 20 + 10) / 3 = 16.666...
assert_equal 16, parent.reload.done_ratio
end
end
def test_parent_done_ratio_should_be_weighted_by_estimated_times_if_any
with_settings :parent_issue_done_ratio => 'derived' do
parent = Issue.generate!
@ -236,7 +249,7 @@ class IssueSubtaskingTest < ActiveSupport::TestCase
child = first_parent.generate_child!(:done_ratio => 20)
assert_equal 30, first_parent.reload.done_ratio
assert_equal 0, second_parent.reload.done_ratio
child.update_attributes(:parent_issue_id => second_parent.id)
child.update(:parent_issue_id => second_parent.id)
assert_equal 40, first_parent.reload.done_ratio
assert_equal 20, second_parent.reload.done_ratio
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
@ -33,6 +35,7 @@ class IssueTest < ActiveSupport::TestCase
include Redmine::I18n
def setup
User.current = nil
set_language_if_valid 'en'
end
@ -540,6 +543,23 @@ class IssueTest < ActiveSupport::TestCase
assert_equal false, issue.deletable?(user)
end
def test_issue_should_editable_by_author
Role.all.each do |r|
r.remove_permission! :edit_issues
r.add_permission! :edit_own_issues
end
issue = Issue.find(1)
user = User.find_by_login('jsmith')
# author
assert_equal user, issue.author
assert_equal true, issue.attributes_editable?(user)
# not author
assert_equal false, issue.attributes_editable?(User.find_by_login('dlopper'))
end
def test_errors_full_messages_should_include_custom_fields_errors
field = IssueCustomField.find_by_name('Database')
@ -666,7 +686,12 @@ class IssueTest < ActiveSupport::TestCase
issue.expects(:project_id=).in_sequence(seq)
issue.expects(:tracker_id=).in_sequence(seq)
issue.expects(:subject=).in_sequence(seq)
issue.attributes = {:tracker_id => 2, :project_id => 1, :subject => 'Test'}
assert_raise Exception do
issue.attributes = {:subject => 'Test'}
end
assert_nothing_raised do
issue.attributes = {:tracker_id => 2, :project_id => 1, :subject => 'Test'}
end
end
def test_assigning_tracker_and_custom_fields_should_assign_custom_fields
@ -1001,16 +1026,18 @@ class IssueTest < ActiveSupport::TestCase
issue = Issue.new(:project_id => 1, :tracker_id => 1, :status_id => 1)
issue.send :safe_attributes=, {'start_date' => '2012-07-12',
'due_date' => '2012-07-14'},
user
issue.send(:safe_attributes=,
{'start_date' => '2012-07-12',
'due_date' => '2012-07-14'},
user)
assert_equal Date.parse('2012-07-12'), issue.start_date
assert_nil issue.due_date
issue.send :safe_attributes=, {'start_date' => '2012-07-15',
'due_date' => '2012-07-16',
'status_id' => 2},
user
issue.send(:safe_attributes=,
{'start_date' => '2012-07-15',
'due_date' => '2012-07-16',
'status_id' => 2},
user)
assert_equal Date.parse('2012-07-12'), issue.start_date
assert_equal Date.parse('2012-07-16'), issue.due_date
end
@ -1045,7 +1072,7 @@ class IssueTest < ActiveSupport::TestCase
issue.required_attribute_names(user).sort
assert !issue.save, "Issue was saved"
assert_equal ["Category cannot be blank", "Due date cannot be blank", "Foo cannot be blank"],
issue.errors.full_messages.sort
issue.errors.full_messages.sort
issue.tracker_id = 2
assert_equal [cf.id.to_s, "start_date"], issue.required_attribute_names(user).sort
@ -1103,7 +1130,7 @@ class IssueTest < ActiveSupport::TestCase
end
def test_required_custom_field_that_is_not_visible_for_the_user_should_not_be_required
CustomField.delete_all
CustomField.destroy_all
field = IssueCustomField.generate!(:is_required => true, :visible => false, :role_ids => [1], :trackers => Tracker.all, :is_for_all => true)
user = User.generate!
User.add_to_project(user, Project.find(1), Role.find(2))
@ -1114,7 +1141,7 @@ class IssueTest < ActiveSupport::TestCase
end
def test_required_custom_field_that_is_visible_for_the_user_should_be_required
CustomField.delete_all
CustomField.destroy_all
field = IssueCustomField.generate!(:is_required => true, :visible => false, :role_ids => [1], :trackers => Tracker.all, :is_for_all => true)
user = User.generate!
User.add_to_project(user, Project.find(1), Role.find(1))
@ -1394,7 +1421,7 @@ class IssueTest < ActiveSupport::TestCase
end
def test_copy_should_clear_subtasks_target_version_if_locked_or_closed
version = Version.new(:project => Project.find(1), :name => '2.1',)
version = Version.new(:project => Project.find(1), :name => '2.1')
version.save!
parent = Issue.generate!
@ -1477,8 +1504,8 @@ class IssueTest < ActiveSupport::TestCase
IssueRelation.create!(:issue_from => issue2, :issue_to => issue1,
:relation_type => IssueRelation::TYPE_DUPLICATES)
# And 3 is a dupe of 2
# IssueRelation.create!(:issue_from => issue3, :issue_to => issue2,
# :relation_type => IssueRelation::TYPE_DUPLICATES)
IssueRelation.create!(:issue_from => issue3, :issue_to => issue2,
:relation_type => IssueRelation::TYPE_DUPLICATES)
# And 3 is a dupe of 1 (circular duplicates)
IssueRelation.create!(:issue_from => issue3, :issue_to => issue1,
:relation_type => IssueRelation::TYPE_DUPLICATES)
@ -1494,6 +1521,23 @@ class IssueTest < ActiveSupport::TestCase
assert issue3.reload.closed?
end
def test_should_not_close_duplicate_when_disabled
issue = Issue.generate!
duplicate = Issue.generate!
IssueRelation.create!(:issue_from => duplicate, :issue_to => issue,
:relation_type => IssueRelation::TYPE_DUPLICATES)
assert issue.reload.duplicates.include?(duplicate)
with_settings :close_duplicate_issues => '0' do
issue.init_journal(User.first, "Closing issue")
issue.status = IssueStatus.where(:is_closed => true).first
issue.save
end
assert !duplicate.reload.closed?
end
def test_should_close_duplicates_with_private_notes
issue = Issue.generate!
duplicate = Issue.generate!
@ -1812,8 +1856,9 @@ class IssueTest < ActiveSupport::TestCase
parent.reload
parent.project_id = project.id
assert !parent.save
assert_include "Subtask ##{child.id} could not be moved to the new project: Tracker is not included in the list",
parent.errors[:base]
assert_include(
"Subtask ##{child.id} could not be moved to the new project: Tracker is not included in the list",
parent.errors[:base])
end
def test_copy_to_the_same_project
@ -1936,10 +1981,16 @@ class IssueTest < ActiveSupport::TestCase
user = User.find(3)
user.members.update_all ["mail_notification = ?", false]
user.update! :mail_notification => 'only_assigned'
issue = Issue.find(2)
issue.assigned_to = nil
assert_include user.mail, issue.recipients
issue.save!
assert_include user.mail, issue.recipients
issue.assigned_to = User.find(2)
issue.save!
assert !issue.recipients.include?(user.mail)
end
def test_recipients_should_not_include_users_that_cannot_view_the_issue
@ -2116,18 +2167,30 @@ class IssueTest < ActiveSupport::TestCase
end
def test_rescheduling_an_issue_to_a_later_due_date_should_reschedule_following_issue
issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
IssueRelation.create!(:issue_from => issue1, :issue_to => issue2,
:relation_type => IssueRelation::TYPE_PRECEDES)
assert_equal Date.parse('2012-10-18'), issue2.reload.start_date
with_settings :non_working_week_days => [] do
issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
IssueRelation.create!(:issue_from => issue1, :issue_to => issue2,
:relation_type => IssueRelation::TYPE_PRECEDES)
assert_equal Date.parse('2012-10-18'), issue2.reload.start_date
issue1.reload
issue1.due_date = '2012-10-23'
issue1.save!
issue2.reload
assert_equal Date.parse('2012-10-24'), issue2.start_date
assert_equal Date.parse('2012-10-26'), issue2.due_date
issue1.reload
issue1.due_date = '2012-10-23'
issue1.save!
issue2.reload
assert_equal Date.parse('2012-10-24'), issue2.start_date
assert_equal Date.parse('2012-10-26'), issue2.due_date
end
# The delay should honor non-working week days
with_settings :non_working_week_days => %w(6 7) do
issue1 = Issue.generate!(:start_date => '2014-03-10', :due_date => '2014-03-12')
issue2 = Issue.generate!(:start_date => '2014-03-10', :due_date => '2014-03-12')
IssueRelation.create!(:issue_from => issue1, :issue_to => issue2,
:relation_type => IssueRelation::TYPE_PRECEDES,
:delay => 8)
assert_equal Date.parse('2014-03-25'), issue2.reload.start_date
end
end
def test_rescheduling_an_issue_to_an_earlier_due_date_should_reschedule_following_issue
@ -2171,7 +2234,6 @@ class IssueTest < ActiveSupport::TestCase
end
end
def test_rescheduling_reschedule_following_issue_earlier_should_consider_other_preceding_issues
issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
@ -2440,7 +2502,7 @@ class IssueTest < ActiveSupport::TestCase
assert_equal 2, assignable_user_ids.length
assignable_user_ids.each do |user_id|
assert_equal 1, assignable_user_ids.select {|i| i == user_id}.length,
assert_equal 1, assignable_user_ids.count {|i| i == user_id},
"User #{user_id} appears more or less than once"
end
end
@ -2494,7 +2556,7 @@ class IssueTest < ActiveSupport::TestCase
:subject => 'test_create', :estimated_hours => '1:30')
with_settings :notified_events => %w(issue_added) do
assert issue.save
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal 2, ActionMailer::Base.deliveries.size
end
end
@ -2506,7 +2568,7 @@ class IssueTest < ActiveSupport::TestCase
:subject => 'test_create', :estimated_hours => '1:30')
with_settings :notified_events => %w(issue_added issue_updated) do
assert issue.save
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal 2, ActionMailer::Base.deliveries.size
end
end
@ -2524,15 +2586,17 @@ class IssueTest < ActiveSupport::TestCase
def test_update_should_notify_previous_assignee
ActionMailer::Base.deliveries.clear
user = User.generate!(:mail_notification => 'only_assigned')
Issue.where(:id => 2).update_all(:assigned_to_id => user.id)
user = User.find(3)
user.members.update_all ["mail_notification = ?", false]
user.update! :mail_notification => 'only_assigned'
with_settings :notified_events => %w(issue_updated) do
issue = Issue.find(2)
issue.init_journal User.find(1)
issue.assigned_to = nil
issue.save!
assert_include user.mail, ActionMailer::Base.deliveries.last.bcc
assert_include [user.mail], ActionMailer::Base.deliveries.map(&:bcc)
end
end
@ -2545,7 +2609,7 @@ class IssueTest < ActiveSupport::TestCase
issue.subject = 'Subjet update'
with_settings :notified_events => %w(issue_updated) do
assert issue.save
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal 2, ActionMailer::Base.deliveries.size
ActionMailer::Base.deliveries.clear
stale.init_journal(User.find(1))
@ -2720,45 +2784,63 @@ class IssueTest < ActiveSupport::TestCase
end
test "#by_tracker" do
User.current = User.anonymous
User.current = User.find(2)
groups = Issue.by_tracker(Project.find(1))
assert_equal 3, groups.count
groups_containing_subprojects = Issue.by_tracker(Project.find(1), true)
assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i}
assert_equal 13, groups_containing_subprojects.inject(0) {|sum, group| sum + group['total'].to_i}
end
test "#by_version" do
User.current = User.anonymous
groups = Issue.by_version(Project.find(1))
assert_equal 3, groups.count
User.current = User.find(2)
project = Project.find(1)
Issue.generate!(:project_id => project.descendants.visible.first, :fixed_version_id => project.shared_versions.find_by(:sharing => 'tree').id)
groups = Issue.by_version(project)
groups_containing_subprojects = Issue.by_version(project, true)
assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i}
assert_equal 4, groups_containing_subprojects.inject(0) {|sum, group| sum + group['total'].to_i}
end
test "#by_priority" do
User.current = User.anonymous
groups = Issue.by_priority(Project.find(1))
assert_equal 4, groups.count
User.current = User.find(2)
project = Project.find(1)
groups = Issue.by_priority(project)
groups_containing_subprojects = Issue.by_priority(project, true)
assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i}
assert_equal 13, groups_containing_subprojects.inject(0) {|sum, group| sum + group['total'].to_i}
end
test "#by_category" do
User.current = User.anonymous
groups = Issue.by_category(Project.find(1))
assert_equal 2, groups.count
User.current = User.find(2)
project = Project.find(1)
issue_category = IssueCategory.create(:project => project.descendants.visible.first, :name => 'test category')
Issue.generate!(:project_id => project.descendants.visible.first, :category_id => issue_category.id)
groups = Issue.by_category(project)
groups_containing_subprojects = Issue.by_category(project, true)
assert_equal 3, groups.inject(0) {|sum, group| sum + group['total'].to_i}
assert_equal 4, groups_containing_subprojects.inject(0) {|sum, group| sum + group['total'].to_i}
end
test "#by_assigned_to" do
User.current = User.anonymous
groups = Issue.by_assigned_to(Project.find(1))
assert_equal 2, groups.count
User.current = User.find(2)
project = Project.find(1)
Issue.generate!(:project_id => project.descendants.visible.first, :assigned_to => User.current)
groups = Issue.by_assigned_to(project)
groups_containing_subprojects = Issue.by_assigned_to(project, true)
assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i}
assert_equal 3, groups_containing_subprojects.inject(0) {|sum, group| sum + group['total'].to_i}
end
test "#by_author" do
User.current = User.anonymous
groups = Issue.by_author(Project.find(1))
assert_equal 4, groups.count
User.current = User.find(2)
project = Project.find(1)
groups = Issue.by_author(project)
groups_containing_subprojects = Issue.by_author(project, true)
assert_equal 7, groups.inject(0) {|sum, group| sum + group['total'].to_i}
assert_equal 13, groups_containing_subprojects.inject(0) {|sum, group| sum + group['total'].to_i}
end
test "#by_subproject" do
@ -2770,7 +2852,7 @@ class IssueTest < ActiveSupport::TestCase
end
def test_recently_updated_scope
#should return the last updated issue
# should return the last updated issue
assert_equal Issue.reorder("updated_on DESC").first, Issue.recently_updated.limit(1).first
end
@ -3111,14 +3193,14 @@ class IssueTest < ActiveSupport::TestCase
assert_equal IssueStatus.find(3), issue.status
end
def test_assigned_to_was_with_a_group
def test_previous_assignee_with_a_group
group = Group.find(10)
Member.create!(:project_id => 1, :principal => group, :role_ids => [1])
with_settings :issue_group_assignment => '1' do
issue = Issue.generate!(:assigned_to => group)
issue.reload.assigned_to = nil
assert_equal group, issue.assigned_to_was
assert_equal group, issue.previous_assignee
end
end
@ -3145,6 +3227,5 @@ class IssueTest < ActiveSupport::TestCase
# March 21st and the issue should be marked overdue
User.current = user_in_asia
assert issue.overdue?
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,7 +29,7 @@ class IssueTransactionTest < ActiveSupport::TestCase
:custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values,
:time_entries
self.use_transactional_fixtures = false
self.use_transactional_tests = false
def setup
User.current = nil

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,12 +22,12 @@ require File.expand_path('../../test_helper', __FILE__)
class JournalObserverTest < ActiveSupport::TestCase
fixtures :issues, :issue_statuses, :journals, :journal_details, :projects,
:projects_trackers, :trackers, :enabled_modules, :enumerations,
:users, :email_addresses, :roles
:users, :user_preferences, :email_addresses, :roles, :members, :member_roles,
:versions
def setup
User.current = nil
ActionMailer::Base.deliveries.clear
@journal = Journal.find 1
end
# context: issue_updated notified_events
@ -37,7 +39,7 @@ class JournalObserverTest < ActiveSupport::TestCase
with_settings :notified_events => %w(issue_updated) do
assert journal.save
end
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal 2, ActionMailer::Base.deliveries.size
end
def test_create_should_not_send_email_notification_with_notify_set_to_false
@ -72,7 +74,7 @@ class JournalObserverTest < ActiveSupport::TestCase
with_settings :notified_events => %w(issue_note_added) do
assert journal.save
end
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal 2, ActionMailer::Base.deliveries.size
end
def test_create_should_not_send_email_notification_without_issue_note_added
@ -96,7 +98,7 @@ class JournalObserverTest < ActiveSupport::TestCase
with_settings :notified_events => %w(issue_status_updated) do
assert issue.save
end
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal 2, ActionMailer::Base.deliveries.size
end
def test_create_should_not_send_email_notification_without_issue_status_updated
@ -133,7 +135,7 @@ class JournalObserverTest < ActiveSupport::TestCase
with_settings :notified_events => %w(issue_assigned_to_updated) do
assert issue.save
end
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal 2, ActionMailer::Base.deliveries.size
end
def test_create_should_not_send_email_notification_without_issue_assignee_updated
@ -158,7 +160,7 @@ class JournalObserverTest < ActiveSupport::TestCase
with_settings :notified_events => %w(issue_priority_updated) do
assert issue.save
end
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal 2, ActionMailer::Base.deliveries.size
end
def test_create_should_not_send_email_notification_without_issue_priority_updated
@ -172,4 +174,28 @@ class JournalObserverTest < ActiveSupport::TestCase
end
assert_equal 0, ActionMailer::Base.deliveries.size
end
def test_create_should_send_email_notification_with_issue_fixed_version_updated
with_settings :notified_events => %w(issue_fixed_version_updated) do
user = User.find_by_login('jsmith')
issue = issues(:issues_001)
issue.init_journal(user)
issue.fixed_version = versions(:versions_003)
assert issue.save
assert_equal 2, ActionMailer::Base.deliveries.size
end
end
def test_create_should_not_send_email_notification_without_issue_fixed_version_updated
with_settings :notified_events => [] do
user = User.find_by_login('jsmith')
issue = issues(:issues_001)
issue.init_journal(user)
issue.fixed_version = versions(:versions_003)
assert issue.save
assert_equal 0, ActionMailer::Base.deliveries.size
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
@ -50,7 +52,7 @@ class JournalTest < ActiveSupport::TestCase
journal = issue.init_journal(user, issue)
assert journal.save
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal 2, ActionMailer::Base.deliveries.size
end
def test_should_not_save_journal_with_blank_notes_and_no_details

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

Some files were not shown because too many files have changed in this diff Show more