Redmine 3.4.4

This commit is contained in:
Manuel Cillero 2018-02-02 22:19:29 +01:00
commit 64924a6376
2112 changed files with 259028 additions and 0 deletions

View file

@ -0,0 +1,163 @@
# 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::AttachmentFieldFormatTest < ActionView::TestCase
include ApplicationHelper
include Redmine::I18n
fixtures :users
def setup
set_language_if_valid 'en'
set_tmp_attachments_directory
end
def test_should_accept_a_hash_with_upload_on_create
field = GroupCustomField.generate!(:name => "File", :field_format => 'attachment')
group = Group.new(:name => 'Group')
attachment = nil
custom_value = new_record(CustomValue) do
attachment = new_record(Attachment) do
group.custom_field_values = {field.id => {:file => mock_file}}
assert group.save
end
end
assert_equal 'a_file.png', attachment.filename
assert_equal custom_value, attachment.container
assert_equal field, attachment.container.custom_field
assert_equal group, attachment.container.customized
end
def test_should_accept_a_hash_with_no_upload_on_create
field = GroupCustomField.generate!(:name => "File", :field_format => 'attachment')
group = Group.new(:name => 'Group')
attachment = nil
custom_value = new_record(CustomValue) do
assert_no_difference 'Attachment.count' do
group.custom_field_values = {field.id => {}}
assert group.save
end
end
assert_equal '', custom_value.value
end
def test_should_not_validate_with_invalid_upload_on_create
field = GroupCustomField.generate!(:name => "File", :field_format => 'attachment')
group = Group.new(:name => 'Group')
with_settings :attachment_max_size => 0 do
assert_no_difference 'CustomValue.count' do
assert_no_difference 'Attachment.count' do
group.custom_field_values = {field.id => {:file => mock_file}}
assert_equal false, group.save
end
end
end
end
def test_should_accept_a_hash_with_token_on_create
field = GroupCustomField.generate!(:name => "File", :field_format => 'attachment')
group = Group.new(:name => 'Group')
attachment = Attachment.create!(:file => mock_file, :author => User.find(2))
assert_nil attachment.container
custom_value = new_record(CustomValue) do
assert_no_difference 'Attachment.count' do
group.custom_field_values = {field.id => {:token => attachment.token}}
assert group.save
end
end
attachment.reload
assert_equal custom_value, attachment.container
assert_equal field, attachment.container.custom_field
assert_equal group, attachment.container.customized
end
def test_should_not_validate_with_invalid_token_on_create
field = GroupCustomField.generate!(:name => "File", :field_format => 'attachment')
group = Group.new(:name => 'Group')
assert_no_difference 'CustomValue.count' do
assert_no_difference 'Attachment.count' do
group.custom_field_values = {field.id => {:token => "123.0123456789abcdef"}}
assert_equal false, group.save
end
end
end
def test_should_replace_attachment_on_update
field = GroupCustomField.generate!(:name => "File", :field_format => 'attachment')
group = Group.new(:name => 'Group')
attachment = nil
custom_value = new_record(CustomValue) do
attachment = new_record(Attachment) do
group.custom_field_values = {field.id => {:file => mock_file}}
assert group.save
end
end
group.reload
assert_no_difference 'Attachment.count' do
assert_no_difference 'CustomValue.count' do
group.custom_field_values = {field.id => {:file => mock_file}}
assert group.save
end
end
assert !Attachment.exists?(attachment.id)
assert CustomValue.exists?(custom_value.id)
new_attachment = Attachment.order(:id => :desc).first
custom_value.reload
assert_equal custom_value, new_attachment.container
end
def test_should_delete_attachment_on_update
field = GroupCustomField.generate!(:name => "File", :field_format => 'attachment')
group = Group.new(:name => 'Group')
attachment = nil
custom_value = new_record(CustomValue) do
attachment = new_record(Attachment) do
group.custom_field_values = {field.id => {:file => mock_file}}
assert group.save
end
end
group.reload
assert_difference 'Attachment.count', -1 do
assert_no_difference 'CustomValue.count' do
group.custom_field_values = {field.id => {}}
assert group.save
end
end
assert !Attachment.exists?(attachment.id)
assert CustomValue.exists?(custom_value.id)
custom_value.reload
assert_equal '', custom_value.value
end
end

View file

@ -0,0 +1,59 @@
# 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 AttachmentFormatVisibilityTest < ActionView::TestCase
fixtures :projects, :enabled_modules, :projects_trackers,
:roles, :members, :member_roles,
:users, :email_addresses,
:trackers, :issue_statuses, :enumerations, :issue_categories,
:versions, :issues
def setup
set_tmp_attachments_directory
end
def test_attachment_should_be_visible_with_visible_custom_field
field = IssueCustomField.generate!(:field_format => 'attachment', :visible => true)
attachment = new_record(Attachment) do
issue = Issue.generate
issue.custom_field_values = {field.id => {:file => mock_file}}
issue.save!
end
assert attachment.visible?(manager = User.find(2))
assert attachment.visible?(developer = User.find(3))
assert attachment.visible?(non_member = User.find(7))
assert attachment.visible?(User.anonymous)
end
def test_attachment_should_be_visible_with_limited_visibility_custom_field
field = IssueCustomField.generate!(:field_format => 'attachment', :visible => false, :role_ids => [1])
attachment = new_record(Attachment) do
issue = Issue.generate
issue.custom_field_values = {field.id => {:file => mock_file}}
issue.save!
end
assert attachment.visible?(manager = User.find(2))
assert !attachment.visible?(developer = User.find(3))
assert !attachment.visible?(non_member = User.find(7))
assert !attachment.visible?(User.anonymous)
end
end

View file

@ -0,0 +1,63 @@
# 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::BoolFieldFormatTest < ActionView::TestCase
include ApplicationHelper
include Redmine::I18n
def setup
set_language_if_valid 'en'
end
def test_check_box_style_should_render_edit_tag_as_check_box
field = IssueCustomField.new(:field_format => 'bool', :is_required => false, :edit_tag_style => 'check_box')
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
tag = field.format.edit_tag(self, 'abc', 'xyz', value)
assert_select_in tag, 'input[name=xyz]', 2
assert_select_in tag, 'input[id=abc]', 1
assert_select_in tag, 'input[type=hidden][value="0"]'
assert_select_in tag, 'input[type=checkbox][value="1"]'
end
def test_check_box_should_be_checked_when_value_is_set
field = IssueCustomField.new(:field_format => 'bool', :is_required => false, :edit_tag_style => 'check_box')
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => '1')
tag = field.format.edit_tag(self, 'abc', 'xyz', value)
assert_select_in tag, 'input[type=checkbox][value="1"][checked=checked]'
end
def test_radio_style_should_render_edit_tag_as_radio_buttons
field = IssueCustomField.new(:field_format => 'bool', :is_required => false, :edit_tag_style => 'radio')
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
tag = field.format.edit_tag(self, 'abc', 'xyz', value)
assert_select_in tag, 'input[type=radio][name=xyz]', 3
end
def test_default_style_should_render_edit_tag_as_select
field = IssueCustomField.new(:field_format => 'bool', :is_required => false)
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
tag = field.format.edit_tag(self, 'abc', 'xyz', value)
assert_select_in tag, 'select[name=xyz]', 1
end
end

View file

@ -0,0 +1,100 @@
# 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::EnumerationFieldFormatTest < ActionView::TestCase
include ApplicationHelper
def setup
set_language_if_valid 'en'
@field = IssueCustomField.create!(:name => 'List', :field_format => 'enumeration', :is_required => false)
@foo = CustomFieldEnumeration.new(:name => 'Foo')
@bar = CustomFieldEnumeration.new(:name => 'Bar')
@field.enumerations << @foo
@field.enumerations << @bar
end
def test_edit_tag_should_contain_possible_values
value = CustomFieldValue.new(:custom_field => @field, :customized => Issue.new)
tag = @field.format.edit_tag(self, 'id', 'name', value)
assert_select_in tag, 'select' do
assert_select 'option', 3
assert_select 'option[value=""]'
assert_select 'option[value=?]', @foo.id.to_s, :text => 'Foo'
assert_select 'option[value=?]', @bar.id.to_s, :text => 'Bar'
end
end
def test_edit_tag_should_select_current_value
value = CustomFieldValue.new(:custom_field => @field, :customized => Issue.new, :value => @bar.id.to_s)
tag = @field.format.edit_tag(self, 'id', 'name', value)
assert_select_in tag, 'select' do
assert_select 'option[selected=selected]', 1
assert_select 'option[value=?][selected=selected]', @bar.id.to_s, :text => 'Bar'
end
end
def test_edit_tag_with_multiple_should_select_current_values
@field.multiple = true
@field.save!
value = CustomFieldValue.new(:custom_field => @field, :customized => Issue.new, :value => [@foo.id.to_s, @bar.id.to_s])
tag = @field.format.edit_tag(self, 'id', 'name', value)
assert_select_in tag, 'select[multiple=multiple]' do
assert_select 'option[selected=selected]', 2
assert_select 'option[value=?][selected=selected]', @foo.id.to_s, :text => 'Foo'
assert_select 'option[value=?][selected=selected]', @bar.id.to_s, :text => 'Bar'
end
end
def test_edit_tag_with_check_box_style_should_contain_possible_values
@field.edit_tag_style = 'check_box'
@field.save!
value = CustomFieldValue.new(:custom_field => @field, :customized => Issue.new)
tag = @field.format.edit_tag(self, 'id', 'name', value)
assert_select_in tag, 'span' do
assert_select 'input[type=radio]', 3
assert_select 'label', :text => '(none)' do
assert_select 'input[value=""]'
end
assert_select 'label', :text => 'Foo' do
assert_select 'input[value=?]', @foo.id.to_s
end
assert_select 'label', :text => 'Bar' do
assert_select 'input[value=?]', @bar.id.to_s
end
end
end
def test_value_from_keyword_should_return_enumeration_id
assert_equal @foo.id, @field.value_from_keyword('foo', nil)
assert_nil @field.value_from_keyword('baz', nil)
end
def test_value_from_keyword_for_multiple_custom_field_should_return_enumeration_ids
@field.multiple = true
@field.save!
assert_equal [@foo.id, @bar.id], @field.value_from_keyword('foo, bar', nil)
assert_equal [@foo.id], @field.value_from_keyword('foo, baz', nil)
assert_equal [], @field.value_from_keyword('baz', nil)
end
end

View file

@ -0,0 +1,101 @@
# 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::FieldFormatTest < ActionView::TestCase
include ApplicationHelper
def setup
set_language_if_valid 'en'
end
def test_string_field_with_text_formatting_disabled_should_not_format_text
field = IssueCustomField.new(:field_format => 'string')
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "*foo*")
assert_equal "*foo*", field.format.formatted_custom_value(self, custom_value, false)
assert_equal "*foo*", field.format.formatted_custom_value(self, custom_value, true)
end
def test_string_field_with_text_formatting_enabled_should_format_text
field = IssueCustomField.new(:field_format => 'string', :text_formatting => 'full')
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "*foo*")
assert_equal "*foo*", field.format.formatted_custom_value(self, custom_value, false)
assert_include "<strong>foo</strong>", field.format.formatted_custom_value(self, custom_value, true)
end
def test_text_field_with_text_formatting_disabled_should_not_format_text
field = IssueCustomField.new(:field_format => 'text')
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "*foo*\nbar")
assert_equal "*foo*\nbar", field.format.formatted_custom_value(self, custom_value, false)
assert_include "*foo*\n<br />bar", field.format.formatted_custom_value(self, custom_value, true)
end
def test_text_field_with_text_formatting_enabled_should_format_text
field = IssueCustomField.new(:field_format => 'text', :text_formatting => 'full')
custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "*foo*\nbar")
assert_equal "*foo*\nbar", field.format.formatted_custom_value(self, custom_value, false)
assert_include "<strong>foo</strong>", field.format.formatted_custom_value(self, custom_value, true)
end
def test_should_validate_url_pattern_with_safe_scheme
field = IssueCustomField.new(:field_format => 'string', :name => 'URL', :url_pattern => 'http://foo/%value%')
assert_save field
end
def test_should_not_validate_url_pattern_with_unsafe_scheme
field = IssueCustomField.new(:field_format => 'string', :name => 'URL', :url_pattern => 'foo://foo/%value%')
assert !field.save
assert_include "URL is invalid", field.errors.full_messages
end
def test_text_field_with_url_pattern_should_format_as_link
field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/%value%')
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)
end
def test_text_field_with_url_pattern_and_value_containing_a_space_should_format_as_link
field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/%value%')
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)
end
def test_text_field_with_url_pattern_should_not_encode_url_pattern
field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/bar#anchor')
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)
end
def test_text_field_with_url_pattern_should_encode_values
field = IssueCustomField.new(:field_format => 'string', :url_pattern => 'http://foo/%value%#anchor')
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)
end
end

View file

@ -0,0 +1,90 @@
# 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::LinkFieldFormatTest < ActionView::TestCase
def test_link_field_should_substitute_value
field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%value%')
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)
end
def test_link_field_should_substitute_object_id_in_url
object = Issue.new
object.stubs(:id).returns(10)
field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%id%')
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)
end
def test_link_field_should_substitute_project_id_in_url
project = Project.new
project.stubs(:id).returns(52)
object = Issue.new
object.stubs(:project).returns(project)
field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%project_id%')
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)
end
def test_link_field_should_substitute_project_identifier_in_url
project = Project.new
project.stubs(:identifier).returns('foo_project-00')
object = Issue.new
object.stubs(:project).returns(project)
field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%project_identifier%')
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)
end
def test_link_field_should_substitute_regexp_groups
field = IssueCustomField.new(:field_format => 'link', :regexp => /^(.+)-(.+)$/, :url_pattern => 'http://foo/%m2%/%m1%')
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)
end
def test_link_field_without_url_pattern_should_link_to_value
field = IssueCustomField.new(:field_format => 'link')
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)
end
def test_link_field_without_url_pattern_should_link_to_value_with_http_by_default
field = IssueCustomField.new(:field_format => 'link')
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)
end
end

View file

@ -0,0 +1,188 @@
# 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::ListFieldFormatTest < ActionView::TestCase
include ApplicationHelper
include Redmine::I18n
def setup
set_language_if_valid 'en'
end
def test_possible_existing_value_should_be_valid
field = GroupCustomField.create!(:name => 'List', :field_format => 'list', :possible_values => ['Foo', 'Bar'])
group = Group.new(:name => 'Group')
group.custom_field_values = {field.id => 'Baz'}
assert group.save(:validate => false)
group = Group.order('id DESC').first
assert_equal ['Foo', 'Bar', 'Baz'], field.possible_custom_value_options(group.custom_value_for(field))
assert group.valid?
end
def test_edit_tag_should_have_id_and_name
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false)
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
tag = field.format.edit_tag(self, 'abc', 'xyz', value)
assert_select_in tag, 'select[id=abc][name=xyz]'
end
def test_edit_tag_should_contain_possible_values
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false)
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
tag = field.format.edit_tag(self, 'id', 'name', value)
assert_select_in tag, 'select' do
assert_select 'option', 3
assert_select 'option[value=""]'
assert_select 'option[value=Foo]', :text => 'Foo'
assert_select 'option[value=Bar]', :text => 'Bar'
end
end
def test_edit_tag_should_select_current_value
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false)
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => 'Bar')
tag = field.format.edit_tag(self, 'id', 'name', value)
assert_select_in tag, 'select' do
assert_select 'option[selected=selected]', 1
assert_select 'option[value=Bar][selected=selected]', :text => 'Bar'
end
end
def test_edit_tag_with_multiple_should_select_current_values
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar', 'Baz'], :is_required => false,
:multiple => true)
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => ['Bar', 'Baz'])
tag = field.format.edit_tag(self, 'id', 'name', value)
assert_select_in tag, 'select[multiple=multiple]' do
assert_select 'option[selected=selected]', 2
assert_select 'option[value=Bar][selected=selected]', :text => 'Bar'
assert_select 'option[value=Baz][selected=selected]', :text => 'Baz'
end
end
def test_edit_tag_with_check_box_style_should_contain_possible_values
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false,
:edit_tag_style => 'check_box')
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
tag = field.format.edit_tag(self, 'id', 'name', value)
assert_select_in tag, 'span' do
assert_select 'input[type=radio]', 3
assert_select 'label', :text => '(none)' do
assert_select 'input[value=""]'
end
assert_select 'label', :text => 'Foo' do
assert_select 'input[value=Foo]'
end
assert_select 'label', :text => 'Bar' do
assert_select 'input[value=Bar]'
end
end
end
def test_edit_tag_with_check_box_style_should_select_current_value
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false,
:edit_tag_style => 'check_box')
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => 'Bar')
tag = field.format.edit_tag(self, 'id', 'name', value)
assert_select_in tag, 'span' do
assert_select 'input[type=radio][checked=checked]', 1
assert_select 'label', :text => 'Bar' do
assert_select 'input[value=Bar][checked=checked]'
end
end
end
def test_edit_tag_with_check_box_style_and_multiple_values_should_contain_hidden_field_to_clear_value
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar'], :is_required => false,
:edit_tag_style => 'check_box', :multiple => true)
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new)
tag = field.format.edit_tag(self, 'id', 'name', value)
assert_select_in tag, 'span' do
assert_select 'input[type=checkbox]', 2
assert_select 'input[type=hidden]', 1
end
end
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 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 formatted.html_safe?
end
def test_field_with_url_pattern_should_not_link_blank_value
field = IssueCustomField.new(:field_format => 'list', :url_pattern => 'http://localhost/%value%')
formatted = field.format.formatted_value(self, field, '', Issue.new, true)
assert_equal '', formatted
assert formatted.html_safe?
end
def test_edit_tag_with_check_box_style_and_multiple_should_select_current_values
field = IssueCustomField.new(:field_format => 'list', :possible_values => ['Foo', 'Bar', 'Baz'], :is_required => false,
:multiple => true, :edit_tag_style => 'check_box')
value = CustomFieldValue.new(:custom_field => field, :customized => Issue.new, :value => ['Bar', 'Baz'])
tag = field.format.edit_tag(self, 'id', 'name', value)
assert_select_in tag, 'span' do
assert_select 'input[type=checkbox][checked=checked]', 2
assert_select 'label', :text => 'Bar' do
assert_select 'input[value=Bar][checked=checked]'
end
assert_select 'label', :text => 'Baz' do
assert_select 'input[value=Baz][checked=checked]'
end
end
end
def test_value_from_keyword_should_return_value
field = GroupCustomField.create!(:name => 'List', :field_format => 'list', :possible_values => ['Foo', 'Bar', 'Baz,qux'])
assert_equal 'Foo', field.value_from_keyword('foo', nil)
assert_equal 'Baz,qux', field.value_from_keyword('baz,qux', nil)
assert_nil field.value_from_keyword('invalid', nil)
end
def test_value_from_keyword_for_multiple_custom_field_should_return_values
field = GroupCustomField.create!(:name => 'List', :field_format => 'list', :possible_values => ['Foo', 'Bar', 'Baz,qux'], :multiple => true)
assert_equal ['Foo','Bar'], field.value_from_keyword('foo,bar', nil)
assert_equal ['Baz,qux'], field.value_from_keyword('baz,qux', nil)
assert_equal ['Baz,qux', 'Foo'], field.value_from_keyword('baz,qux,foo', nil)
assert_equal ['Foo'], field.value_from_keyword('foo,invalid', nil)
assert_equal ['Foo'], field.value_from_keyword(',foo,', nil)
assert_equal ['Foo'], field.value_from_keyword(',foo, ,,', nil)
assert_equal [], field.value_from_keyword('invalid', nil)
end
end

View file

@ -0,0 +1,31 @@
# 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 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

View file

@ -0,0 +1,79 @@
# 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::UserFieldFormatTest < ActionView::TestCase
fixtures :projects, :roles, :users, :members, :member_roles,
:trackers,
:issue_statuses, :issue_categories, :issue_relations, :workflows,
:enumerations
def test_user_role_should_reject_blank_values
field = IssueCustomField.new(:name => 'Foo', :field_format => 'user', :user_role => ["1", ""])
field.save!
assert_equal ["1"], field.user_role
end
def test_existing_values_should_be_valid
field = IssueCustomField.create!(:name => 'Foo', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
project = Project.generate!
user = User.generate!
User.add_to_project(user, project, Role.find_by_name('Manager'))
issue = Issue.generate!(:project_id => project.id, :tracker_id => 1, :custom_field_values => {field.id => user.id})
field.user_role = [Role.find_by_name('Developer').id]
field.save!
issue = Issue.order('id DESC').first
assert_include [user.name, user.id.to_s], field.possible_custom_value_options(issue.custom_value_for(field))
assert issue.valid?
end
def test_possible_values_options_should_return_project_members
field = IssueCustomField.new(:field_format => 'user')
project = Project.find(1)
assert_equal ['Dave Lopper', 'John Smith'], field.possible_values_options(project).map(&:first)
end
def test_possible_values_options_should_return_project_members_with_selected_role
field = IssueCustomField.new(:field_format => 'user', :user_role => ["2"])
project = Project.find(1)
assert_equal ['Dave Lopper'], 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)
assert_equal 2, field.value_from_keyword('jsmith', project)
assert_equal 3, field.value_from_keyword('Dave Lopper', project)
assert_nil field.value_from_keyword('Unknown User', project)
end
def test_value_from_keyword_for_multiple_custom_field_should_return_enumeration_ids
field = IssueCustomField.new(:field_format => 'user', :multiple => true)
project = Project.find(1)
assert_equal [2, 3], field.value_from_keyword('jsmith, Dave Lopper', project)
assert_equal [2], field.value_from_keyword('jsmith', project)
assert_equal [], field.value_from_keyword('Unknown User', project)
end
end

View file

@ -0,0 +1,105 @@
# 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::VersionFieldFormatTest < ActionView::TestCase
fixtures :projects, :versions, :trackers,
:roles, :users, :members, :member_roles,
:issue_statuses, :issue_categories, :issue_relations, :workflows,
:enumerations
def setup
super
User.current = nil
end
def test_version_status_should_reject_blank_values
field = IssueCustomField.new(:name => 'Foo', :field_format => 'version', :version_status => ["open", ""])
field.save!
assert_equal ["open"], field.version_status
end
def test_existing_values_should_be_valid
field = IssueCustomField.create!(:name => 'Foo', :field_format => 'version', :is_for_all => true, :trackers => Tracker.all)
project = Project.generate!
version = Version.generate!(:project => project, :status => 'open')
issue = Issue.generate!(:project_id => project.id, :tracker_id => 1, :custom_field_values => {field.id => version.id})
field.version_status = ["open"]
field.save!
issue = Issue.order('id DESC').first
assert_include [version.name, version.id.to_s], field.possible_custom_value_options(issue.custom_value_for(field))
assert issue.valid?
end
def test_possible_values_options_should_return_project_versions
field = IssueCustomField.new(:field_format => 'version')
project = Project.find(1)
expected = project.shared_versions.sort.map(&:name)
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')
expected = Version.visible.where(:sharing => 'system').sort.map(&:name)
assert_include version.name, expected
assert_equal expected, field.possible_values_options.map(&:first)
end
def test_possible_values_options_should_return_project_versions_with_selected_status
field = IssueCustomField.new(:field_format => 'version', :version_status => ["open"])
project = Project.find(1)
expected = project.shared_versions.sort.select {|v| v.status == "open"}.map(&:name)
assert_equal expected, field.possible_values_options(project).map(&:first)
end
def test_cast_value_should_not_raise_error_when_array_contains_value_casted_to_nil
field = IssueCustomField.new(:field_format => 'version')
assert_nothing_raised do
field.cast_value([1,2, 42])
end
end
def test_query_filter_options_should_include_versions_with_any_status
field = IssueCustomField.new(:field_format => 'version', :version_status => ["open"])
project = Project.find(1)
version = Version.generate!(:project => project, :status => 'locked')
query = Query.new(:project => project)
full_name = "#{version.project} - #{version.name}"
assert_not_include full_name, field.possible_values_options(project).map(&:first)
assert_include full_name, field.query_filter_options(query)[:values].call.map(&:first)
end
def test_query_filter_options_should_include_version_status_for_grouping
field = IssueCustomField.new(:field_format => 'version', :version_status => ["open"])
project = Project.find(1)
version = Version.generate!(:project => project, :status => 'locked')
query = Query.new(:project => project)
full_name = "#{version.project} - #{version.name}"
assert_include [full_name, version.id.to_s, l(:version_status_locked)],
field.query_filter_options(query)[:values].call
end
end