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