annotate .svn/pristine/97/975492dc75e06846064c4a7839c154496947f0ac.svn-base @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 require File.expand_path('../../../../../test_helper', __FILE__)
Chris@1517 19 require 'redmine/field_format'
Chris@1517 20
Chris@1517 21 class Redmine::LinkFieldFormatTest < ActionView::TestCase
Chris@1517 22 def test_link_field_should_substitute_value
Chris@1517 23 field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%value%')
Chris@1517 24 custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "bar")
Chris@1517 25
Chris@1517 26 assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
Chris@1517 27 assert_equal '<a href="http://foo/bar">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
Chris@1517 28 end
Chris@1517 29
Chris@1517 30 def test_link_field_should_substitute_object_id_in_url
Chris@1517 31 object = Issue.new
Chris@1517 32 object.stubs(:id).returns(10)
Chris@1517 33
Chris@1517 34 field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%id%')
Chris@1517 35 custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
Chris@1517 36
Chris@1517 37 assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
Chris@1517 38 assert_equal '<a href="http://foo/10">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
Chris@1517 39 end
Chris@1517 40
Chris@1517 41 def test_link_field_should_substitute_project_id_in_url
Chris@1517 42 project = Project.new
Chris@1517 43 project.stubs(:id).returns(52)
Chris@1517 44 object = Issue.new
Chris@1517 45 object.stubs(:project).returns(project)
Chris@1517 46
Chris@1517 47 field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%project_id%')
Chris@1517 48 custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
Chris@1517 49
Chris@1517 50 assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
Chris@1517 51 assert_equal '<a href="http://foo/52">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
Chris@1517 52 end
Chris@1517 53
Chris@1517 54 def test_link_field_should_substitute_project_identifier_in_url
Chris@1517 55 project = Project.new
Chris@1517 56 project.stubs(:identifier).returns('foo_project-00')
Chris@1517 57 object = Issue.new
Chris@1517 58 object.stubs(:project).returns(project)
Chris@1517 59
Chris@1517 60 field = IssueCustomField.new(:field_format => 'link', :url_pattern => 'http://foo/%project_identifier%')
Chris@1517 61 custom_value = CustomValue.new(:custom_field => field, :customized => object, :value => "bar")
Chris@1517 62
Chris@1517 63 assert_equal "bar", field.format.formatted_custom_value(self, custom_value, false)
Chris@1517 64 assert_equal '<a href="http://foo/foo_project-00">bar</a>', field.format.formatted_custom_value(self, custom_value, true)
Chris@1517 65 end
Chris@1517 66
Chris@1517 67 def test_link_field_should_substitute_regexp_groups
Chris@1517 68 field = IssueCustomField.new(:field_format => 'link', :regexp => /^(.+)-(.+)$/, :url_pattern => 'http://foo/%m2%/%m1%')
Chris@1517 69 custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "56-142")
Chris@1517 70
Chris@1517 71 assert_equal "56-142", field.format.formatted_custom_value(self, custom_value, false)
Chris@1517 72 assert_equal '<a href="http://foo/142/56">56-142</a>', field.format.formatted_custom_value(self, custom_value, true)
Chris@1517 73 end
Chris@1517 74
Chris@1517 75 def test_link_field_without_url_pattern_should_link_to_value
Chris@1517 76 field = IssueCustomField.new(:field_format => 'link')
Chris@1517 77 custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "http://foo/bar")
Chris@1517 78
Chris@1517 79 assert_equal "http://foo/bar", field.format.formatted_custom_value(self, custom_value, false)
Chris@1517 80 assert_equal '<a href="http://foo/bar">http://foo/bar</a>', field.format.formatted_custom_value(self, custom_value, true)
Chris@1517 81 end
Chris@1517 82
Chris@1517 83 def test_link_field_without_url_pattern_should_link_to_value_with_http_by_default
Chris@1517 84 field = IssueCustomField.new(:field_format => 'link')
Chris@1517 85 custom_value = CustomValue.new(:custom_field => field, :customized => Issue.new, :value => "foo.bar")
Chris@1517 86
Chris@1517 87 assert_equal "foo.bar", field.format.formatted_custom_value(self, custom_value, false)
Chris@1517 88 assert_equal '<a href="http://foo.bar">foo.bar</a>', field.format.formatted_custom_value(self, custom_value, true)
Chris@1517 89 end
Chris@1517 90 end