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