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