@@ -1,158 +1,164 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../../../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../../../test_helper' | |
19 |
|
19 | |||
20 | class Redmine::Hook::ManagerTest < Test::Unit::TestCase |
|
20 | class Redmine::Hook::ManagerTest < Test::Unit::TestCase | |
21 |
|
21 | |||
22 | # Some hooks that are manually registered in these tests |
|
22 | # Some hooks that are manually registered in these tests | |
23 | class TestHook < Redmine::Hook::ViewListener; end |
|
23 | class TestHook < Redmine::Hook::ViewListener; end | |
24 |
|
24 | |||
25 | class TestHook1 < TestHook |
|
25 | class TestHook1 < TestHook | |
26 | def view_layouts_base_html_head(context) |
|
26 | def view_layouts_base_html_head(context) | |
27 | 'Test hook 1 listener.' |
|
27 | 'Test hook 1 listener.' | |
28 | end |
|
28 | end | |
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | class TestHook2 < TestHook |
|
31 | class TestHook2 < TestHook | |
32 | def view_layouts_base_html_head(context) |
|
32 | def view_layouts_base_html_head(context) | |
33 | 'Test hook 2 listener.' |
|
33 | 'Test hook 2 listener.' | |
34 | end |
|
34 | end | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | class TestHook3 < TestHook |
|
37 | class TestHook3 < TestHook | |
38 | def view_layouts_base_html_head(context) |
|
38 | def view_layouts_base_html_head(context) | |
39 | "Context keys: #{context.keys.collect(&:to_s).sort.join(', ')}." |
|
39 | "Context keys: #{context.keys.collect(&:to_s).sort.join(', ')}." | |
40 | end |
|
40 | end | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | class TestLinkToHook < TestHook |
|
43 | class TestLinkToHook < TestHook | |
44 | def view_layouts_base_html_head(context) |
|
44 | def view_layouts_base_html_head(context) | |
45 | link_to('Issues', :controller => 'issues') |
|
45 | link_to('Issues', :controller => 'issues') | |
46 | end |
|
46 | end | |
47 | end |
|
47 | end | |
48 |
|
48 | |||
|
49 | class TestHookHelperController < ActionController::Base | |||
|
50 | include Redmine::Hook::Helper | |||
|
51 | end | |||
|
52 | ||||
49 | Redmine::Hook.clear_listeners |
|
53 | Redmine::Hook.clear_listeners | |
50 |
|
54 | |||
51 | def setup |
|
55 | def setup | |
52 | @hook_module = Redmine::Hook |
|
56 | @hook_module = Redmine::Hook | |
|
57 | @hook_helper = TestHookHelperController.new | |||
53 | end |
|
58 | end | |
54 |
|
59 | |||
55 | def teardown |
|
60 | def teardown | |
56 | @hook_module.clear_listeners |
|
61 | @hook_module.clear_listeners | |
57 | @hook_module.default_url_options = { } |
|
62 | @hook_module.default_url_options = { } | |
58 | end |
|
63 | end | |
59 |
|
64 | |||
60 | def test_clear_listeners |
|
65 | def test_clear_listeners | |
61 | assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size |
|
66 | assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size | |
62 | @hook_module.add_listener(TestHook1) |
|
67 | @hook_module.add_listener(TestHook1) | |
63 | @hook_module.add_listener(TestHook2) |
|
68 | @hook_module.add_listener(TestHook2) | |
64 | assert_equal 2, @hook_module.hook_listeners(:view_layouts_base_html_head).size |
|
69 | assert_equal 2, @hook_module.hook_listeners(:view_layouts_base_html_head).size | |
65 |
|
70 | |||
66 | @hook_module.clear_listeners |
|
71 | @hook_module.clear_listeners | |
67 | assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size |
|
72 | assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size | |
68 | end |
|
73 | end | |
69 |
|
74 | |||
70 | def test_add_listener |
|
75 | def test_add_listener | |
71 | assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size |
|
76 | assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size | |
72 | @hook_module.add_listener(TestHook1) |
|
77 | @hook_module.add_listener(TestHook1) | |
73 | assert_equal 1, @hook_module.hook_listeners(:view_layouts_base_html_head).size |
|
78 | assert_equal 1, @hook_module.hook_listeners(:view_layouts_base_html_head).size | |
74 | end |
|
79 | end | |
75 |
|
80 | |||
76 | def test_call_hook |
|
81 | def test_call_hook | |
77 | @hook_module.add_listener(TestHook1) |
|
82 | @hook_module.add_listener(TestHook1) | |
78 |
assert_equal ['Test hook 1 listener.'], @hook_ |
|
83 | assert_equal ['Test hook 1 listener.'], @hook_helper.call_hook(:view_layouts_base_html_head) | |
79 | end |
|
84 | end | |
80 |
|
85 | |||
81 | def test_call_hook_with_context |
|
86 | def test_call_hook_with_context | |
82 | @hook_module.add_listener(TestHook3) |
|
87 | @hook_module.add_listener(TestHook3) | |
83 | assert_equal ['Context keys: bar, foo.'], @hook_module.call_hook(:view_layouts_base_html_head, :foo => 1, :bar => 'a') |
|
88 | assert_equal ['Context keys: bar, controller, foo, project, request.'], | |
|
89 | @hook_helper.call_hook(:view_layouts_base_html_head, :foo => 1, :bar => 'a') | |||
84 | end |
|
90 | end | |
85 |
|
91 | |||
86 | def test_call_hook_with_multiple_listeners |
|
92 | def test_call_hook_with_multiple_listeners | |
87 | @hook_module.add_listener(TestHook1) |
|
93 | @hook_module.add_listener(TestHook1) | |
88 | @hook_module.add_listener(TestHook2) |
|
94 | @hook_module.add_listener(TestHook2) | |
89 |
assert_equal ['Test hook 1 listener.', 'Test hook 2 listener.'], @hook_ |
|
95 | assert_equal ['Test hook 1 listener.', 'Test hook 2 listener.'], @hook_helper.call_hook(:view_layouts_base_html_head) | |
90 | end |
|
96 | end | |
91 |
|
97 | |||
92 | # Context: Redmine::Hook::call_hook |
|
98 | # Context: Redmine::Hook::call_hook | |
93 | def test_call_hook_default_url_options_set |
|
99 | def test_call_hook_default_url_options_set | |
94 | request = ActionController::TestRequest.new |
|
100 | request = ActionController::TestRequest.new | |
95 | request.env = { "SERVER_NAME" => 'example.com'} |
|
101 | request.env = { "SERVER_NAME" => 'example.com'} | |
96 | @hook_module.add_listener(TestLinkToHook) |
|
102 | @hook_module.add_listener(TestLinkToHook) | |
97 |
|
103 | |||
98 | assert_equal ['<a href="http://example.com/issues">Issues</a>'], |
|
104 | assert_equal ['<a href="http://example.com/issues">Issues</a>'], | |
99 |
@hook_ |
|
105 | @hook_helper.call_hook(:view_layouts_base_html_head, :request => request) | |
100 | end |
|
106 | end | |
101 |
|
107 | |||
102 | def test_call_hook_default_url_options_set_with_no_standard_request_port |
|
108 | def test_call_hook_default_url_options_set_with_no_standard_request_port | |
103 | request = ActionController::TestRequest.new |
|
109 | request = ActionController::TestRequest.new | |
104 | request.env = { "SERVER_NAME" => 'example.com', "SERVER_PORT" => 3000} |
|
110 | request.env = { "SERVER_NAME" => 'example.com', "SERVER_PORT" => 3000} | |
105 | @hook_module.add_listener(TestLinkToHook) |
|
111 | @hook_module.add_listener(TestLinkToHook) | |
106 |
|
112 | |||
107 | assert_equal ['<a href="http://example.com:3000/issues">Issues</a>'], |
|
113 | assert_equal ['<a href="http://example.com:3000/issues">Issues</a>'], | |
108 |
@hook_ |
|
114 | @hook_helper.call_hook(:view_layouts_base_html_head, :request => request) | |
109 | end |
|
115 | end | |
110 |
|
116 | |||
111 | def test_call_hook_default_url_options_set_with_ssl |
|
117 | def test_call_hook_default_url_options_set_with_ssl | |
112 | request = ActionController::TestRequest.new |
|
118 | request = ActionController::TestRequest.new | |
113 | request.env = { "SERVER_NAME" => 'example.com', "HTTPS" => 'on'} |
|
119 | request.env = { "SERVER_NAME" => 'example.com', "HTTPS" => 'on'} | |
114 | @hook_module.add_listener(TestLinkToHook) |
|
120 | @hook_module.add_listener(TestLinkToHook) | |
115 |
|
121 | |||
116 | assert_equal ['<a href="https://example.com/issues">Issues</a>'], |
|
122 | assert_equal ['<a href="https://example.com/issues">Issues</a>'], | |
117 |
@hook_ |
|
123 | @hook_helper.call_hook(:view_layouts_base_html_head, :request => request) | |
118 | end |
|
124 | end | |
119 |
|
125 | |||
120 | def test_call_hook_default_url_options_set_with_forwarded_ssl |
|
126 | def test_call_hook_default_url_options_set_with_forwarded_ssl | |
121 | request = ActionController::TestRequest.new |
|
127 | request = ActionController::TestRequest.new | |
122 | request.env = { "SERVER_NAME" => 'example.com', "HTTP_X_FORWARDED_PROTO" => "https"} |
|
128 | request.env = { "SERVER_NAME" => 'example.com', "HTTP_X_FORWARDED_PROTO" => "https"} | |
123 | @hook_module.add_listener(TestLinkToHook) |
|
129 | @hook_module.add_listener(TestLinkToHook) | |
124 |
|
130 | |||
125 | assert_equal ['<a href="https://example.com/issues">Issues</a>'], |
|
131 | assert_equal ['<a href="https://example.com/issues">Issues</a>'], | |
126 |
@hook_ |
|
132 | @hook_helper.call_hook(:view_layouts_base_html_head, :request => request) | |
127 | end |
|
133 | end | |
128 |
|
134 | |||
129 | # Context: Redmine::Hook::Helper.call_hook |
|
135 | # Context: Redmine::Hook::Helper.call_hook | |
130 | def test_call_hook_with_project_added_to_context |
|
136 | def test_call_hook_with_project_added_to_context | |
131 | # TODO: Implement test |
|
137 | # TODO: Implement test | |
132 | end |
|
138 | end | |
133 |
|
139 | |||
134 | def test_call_hook_from_controller_with_controller_added_to_context |
|
140 | def test_call_hook_from_controller_with_controller_added_to_context | |
135 | # TODO: Implement test |
|
141 | # TODO: Implement test | |
136 | end |
|
142 | end | |
137 |
|
143 | |||
138 | def test_call_hook_from_controller_with_request_added_to_context |
|
144 | def test_call_hook_from_controller_with_request_added_to_context | |
139 | # TODO: Implement test |
|
145 | # TODO: Implement test | |
140 | end |
|
146 | end | |
141 |
|
147 | |||
142 | def test_call_hook_from_view_with_project_added_to_context |
|
148 | def test_call_hook_from_view_with_project_added_to_context | |
143 | # TODO: Implement test |
|
149 | # TODO: Implement test | |
144 | end |
|
150 | end | |
145 |
|
151 | |||
146 | def test_call_hook_from_view_with_controller_added_to_context |
|
152 | def test_call_hook_from_view_with_controller_added_to_context | |
147 | # TODO: Implement test |
|
153 | # TODO: Implement test | |
148 | end |
|
154 | end | |
149 |
|
155 | |||
150 | def test_call_hook_from_view_with_request_added_to_context |
|
156 | def test_call_hook_from_view_with_request_added_to_context | |
151 | # TODO: Implement test |
|
157 | # TODO: Implement test | |
152 | end |
|
158 | end | |
153 |
|
159 | |||
154 | def test_call_hook_from_view_should_join_responses_with_a_space |
|
160 | def test_call_hook_from_view_should_join_responses_with_a_space | |
155 | # TODO: Implement test |
|
161 | # TODO: Implement test | |
156 | end |
|
162 | end | |
157 | end |
|
163 | end | |
158 |
|
164 |
General Comments 0
You need to be logged in to leave comments.
Login now