Mercurial > hg > soundsoftware-site
comparison .svn/pristine/01/0154cdd03545376764b58ded20a14138238e65d0.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
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 | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../../../test_helper', __FILE__) | |
19 | |
20 class Redmine::Hook::ManagerTest < ActionView::TestCase | |
21 fixtures :projects, :users, :members, :member_roles, :roles, | |
22 :groups_users, | |
23 :trackers, :projects_trackers, | |
24 :enabled_modules, | |
25 :versions, | |
26 :issue_statuses, :issue_categories, :issue_relations, | |
27 :enumerations, | |
28 :issues | |
29 | |
30 # Some hooks that are manually registered in these tests | |
31 class TestHook < Redmine::Hook::ViewListener; end | |
32 | |
33 class TestHook1 < TestHook | |
34 def view_layouts_base_html_head(context) | |
35 'Test hook 1 listener.' | |
36 end | |
37 end | |
38 | |
39 class TestHook2 < TestHook | |
40 def view_layouts_base_html_head(context) | |
41 'Test hook 2 listener.' | |
42 end | |
43 end | |
44 | |
45 class TestHook3 < TestHook | |
46 def view_layouts_base_html_head(context) | |
47 "Context keys: #{context.keys.collect(&:to_s).sort.join(', ')}." | |
48 end | |
49 end | |
50 | |
51 class TestLinkToHook < TestHook | |
52 def view_layouts_base_html_head(context) | |
53 link_to('Issues', :controller => 'issues') | |
54 end | |
55 end | |
56 | |
57 class TestHookHelperController < ActionController::Base | |
58 include Redmine::Hook::Helper | |
59 end | |
60 | |
61 class TestHookHelperView < ActionView::Base | |
62 include Redmine::Hook::Helper | |
63 end | |
64 | |
65 Redmine::Hook.clear_listeners | |
66 | |
67 def setup | |
68 @hook_module = Redmine::Hook | |
69 end | |
70 | |
71 def teardown | |
72 @hook_module.clear_listeners | |
73 end | |
74 | |
75 def test_clear_listeners | |
76 assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size | |
77 @hook_module.add_listener(TestHook1) | |
78 @hook_module.add_listener(TestHook2) | |
79 assert_equal 2, @hook_module.hook_listeners(:view_layouts_base_html_head).size | |
80 | |
81 @hook_module.clear_listeners | |
82 assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size | |
83 end | |
84 | |
85 def test_add_listener | |
86 assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size | |
87 @hook_module.add_listener(TestHook1) | |
88 assert_equal 1, @hook_module.hook_listeners(:view_layouts_base_html_head).size | |
89 end | |
90 | |
91 def test_call_hook | |
92 @hook_module.add_listener(TestHook1) | |
93 assert_equal ['Test hook 1 listener.'], hook_helper.call_hook(:view_layouts_base_html_head) | |
94 end | |
95 | |
96 def test_call_hook_with_context | |
97 @hook_module.add_listener(TestHook3) | |
98 assert_equal ['Context keys: bar, controller, foo, hook_caller, project, request.'], | |
99 hook_helper.call_hook(:view_layouts_base_html_head, :foo => 1, :bar => 'a') | |
100 end | |
101 | |
102 def test_call_hook_with_multiple_listeners | |
103 @hook_module.add_listener(TestHook1) | |
104 @hook_module.add_listener(TestHook2) | |
105 assert_equal ['Test hook 1 listener.', 'Test hook 2 listener.'], hook_helper.call_hook(:view_layouts_base_html_head) | |
106 end | |
107 | |
108 # Context: Redmine::Hook::Helper.call_hook default_url | |
109 def test_call_hook_default_url_options | |
110 @hook_module.add_listener(TestLinkToHook) | |
111 | |
112 assert_equal ['<a href="/issues">Issues</a>'], hook_helper.call_hook(:view_layouts_base_html_head) | |
113 end | |
114 | |
115 # Context: Redmine::Hook::Helper.call_hook | |
116 def test_call_hook_with_project_added_to_context | |
117 @hook_module.add_listener(TestHook3) | |
118 assert_match /project/i, hook_helper.call_hook(:view_layouts_base_html_head)[0] | |
119 end | |
120 | |
121 def test_call_hook_from_controller_with_controller_added_to_context | |
122 @hook_module.add_listener(TestHook3) | |
123 assert_match /controller/i, hook_helper.call_hook(:view_layouts_base_html_head)[0] | |
124 end | |
125 | |
126 def test_call_hook_from_controller_with_request_added_to_context | |
127 @hook_module.add_listener(TestHook3) | |
128 assert_match /request/i, hook_helper.call_hook(:view_layouts_base_html_head)[0] | |
129 end | |
130 | |
131 def test_call_hook_from_view_with_project_added_to_context | |
132 @hook_module.add_listener(TestHook3) | |
133 assert_match /project/i, view_hook_helper.call_hook(:view_layouts_base_html_head) | |
134 end | |
135 | |
136 def test_call_hook_from_view_with_controller_added_to_context | |
137 @hook_module.add_listener(TestHook3) | |
138 assert_match /controller/i, view_hook_helper.call_hook(:view_layouts_base_html_head) | |
139 end | |
140 | |
141 def test_call_hook_from_view_with_request_added_to_context | |
142 @hook_module.add_listener(TestHook3) | |
143 assert_match /request/i, view_hook_helper.call_hook(:view_layouts_base_html_head) | |
144 end | |
145 | |
146 def test_call_hook_from_view_should_join_responses_with_a_space | |
147 @hook_module.add_listener(TestHook1) | |
148 @hook_module.add_listener(TestHook2) | |
149 assert_equal 'Test hook 1 listener. Test hook 2 listener.', | |
150 view_hook_helper.call_hook(:view_layouts_base_html_head) | |
151 end | |
152 | |
153 def test_call_hook_should_not_change_the_default_url_for_email_notifications | |
154 issue = Issue.find(1) | |
155 | |
156 ActionMailer::Base.deliveries.clear | |
157 Mailer.issue_add(issue).deliver | |
158 mail = ActionMailer::Base.deliveries.last | |
159 | |
160 @hook_module.add_listener(TestLinkToHook) | |
161 hook_helper.call_hook(:view_layouts_base_html_head) | |
162 | |
163 ActionMailer::Base.deliveries.clear | |
164 Mailer.issue_add(issue).deliver | |
165 mail2 = ActionMailer::Base.deliveries.last | |
166 | |
167 assert_equal mail_body(mail), mail_body(mail2) | |
168 end | |
169 | |
170 def hook_helper | |
171 @hook_helper ||= TestHookHelperController.new | |
172 end | |
173 | |
174 def view_hook_helper | |
175 @view_hook_helper ||= TestHookHelperView.new(Rails.root.to_s + '/app/views') | |
176 end | |
177 end | |
178 |