@@ -23,7 +23,7 class Redmine::Hook::ManagerTest < ActiveSupport::TestCase | |||
|
23 | 23 | |
|
24 | 24 | # Some hooks that are manually registered in these tests |
|
25 | 25 | class TestHook < Redmine::Hook::ViewListener; end |
|
26 | ||
|
26 | ||
|
27 | 27 | class TestHook1 < TestHook |
|
28 | 28 | def view_layouts_base_html_head(context) |
|
29 | 29 | 'Test hook 1 listener.' |
@@ -51,54 +51,54 class Redmine::Hook::ManagerTest < ActiveSupport::TestCase | |||
|
51 | 51 | class TestHookHelperController < ActionController::Base |
|
52 | 52 | include Redmine::Hook::Helper |
|
53 | 53 | end |
|
54 | ||
|
54 | ||
|
55 | 55 | class TestHookHelperView < ActionView::Base |
|
56 | 56 | include Redmine::Hook::Helper |
|
57 | 57 | end |
|
58 | ||
|
58 | ||
|
59 | 59 | Redmine::Hook.clear_listeners |
|
60 | ||
|
60 | ||
|
61 | 61 | def setup |
|
62 | 62 | @hook_module = Redmine::Hook |
|
63 | 63 | end |
|
64 | ||
|
64 | ||
|
65 | 65 | def teardown |
|
66 | 66 | @hook_module.clear_listeners |
|
67 | 67 | end |
|
68 | ||
|
68 | ||
|
69 | 69 | def test_clear_listeners |
|
70 | 70 | assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size |
|
71 | 71 | @hook_module.add_listener(TestHook1) |
|
72 | 72 | @hook_module.add_listener(TestHook2) |
|
73 | 73 | assert_equal 2, @hook_module.hook_listeners(:view_layouts_base_html_head).size |
|
74 | ||
|
74 | ||
|
75 | 75 | @hook_module.clear_listeners |
|
76 | 76 | assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size |
|
77 | 77 | end |
|
78 | ||
|
78 | ||
|
79 | 79 | def test_add_listener |
|
80 | 80 | assert_equal 0, @hook_module.hook_listeners(:view_layouts_base_html_head).size |
|
81 | 81 | @hook_module.add_listener(TestHook1) |
|
82 | 82 | assert_equal 1, @hook_module.hook_listeners(:view_layouts_base_html_head).size |
|
83 | 83 | end |
|
84 | ||
|
84 | ||
|
85 | 85 | def test_call_hook |
|
86 | 86 | @hook_module.add_listener(TestHook1) |
|
87 | 87 | assert_equal ['Test hook 1 listener.'], hook_helper.call_hook(:view_layouts_base_html_head) |
|
88 | 88 | end |
|
89 | ||
|
89 | ||
|
90 | 90 | def test_call_hook_with_context |
|
91 | 91 | @hook_module.add_listener(TestHook3) |
|
92 | 92 | assert_equal ['Context keys: bar, controller, foo, project, request.'], |
|
93 | 93 | hook_helper.call_hook(:view_layouts_base_html_head, :foo => 1, :bar => 'a') |
|
94 | 94 | end |
|
95 | ||
|
95 | ||
|
96 | 96 | def test_call_hook_with_multiple_listeners |
|
97 | 97 | @hook_module.add_listener(TestHook1) |
|
98 | 98 | @hook_module.add_listener(TestHook2) |
|
99 | 99 | assert_equal ['Test hook 1 listener.', 'Test hook 2 listener.'], hook_helper.call_hook(:view_layouts_base_html_head) |
|
100 | 100 | end |
|
101 | ||
|
101 | ||
|
102 | 102 | # Context: Redmine::Hook::Helper.call_hook default_url |
|
103 | 103 | def test_call_hook_default_url_options |
|
104 | 104 | @hook_module.add_listener(TestLinkToHook) |
@@ -111,27 +111,27 class Redmine::Hook::ManagerTest < ActiveSupport::TestCase | |||
|
111 | 111 | @hook_module.add_listener(TestHook3) |
|
112 | 112 | assert_match /project/i, hook_helper.call_hook(:view_layouts_base_html_head)[0] |
|
113 | 113 | end |
|
114 | ||
|
114 | ||
|
115 | 115 | def test_call_hook_from_controller_with_controller_added_to_context |
|
116 | 116 | @hook_module.add_listener(TestHook3) |
|
117 | 117 | assert_match /controller/i, hook_helper.call_hook(:view_layouts_base_html_head)[0] |
|
118 | 118 | end |
|
119 | ||
|
119 | ||
|
120 | 120 | def test_call_hook_from_controller_with_request_added_to_context |
|
121 | 121 | @hook_module.add_listener(TestHook3) |
|
122 | 122 | assert_match /request/i, hook_helper.call_hook(:view_layouts_base_html_head)[0] |
|
123 | 123 | end |
|
124 | ||
|
124 | ||
|
125 | 125 | def test_call_hook_from_view_with_project_added_to_context |
|
126 | 126 | @hook_module.add_listener(TestHook3) |
|
127 | 127 | assert_match /project/i, view_hook_helper.call_hook(:view_layouts_base_html_head) |
|
128 | 128 | end |
|
129 | ||
|
129 | ||
|
130 | 130 | def test_call_hook_from_view_with_controller_added_to_context |
|
131 | 131 | @hook_module.add_listener(TestHook3) |
|
132 | 132 | assert_match /controller/i, view_hook_helper.call_hook(:view_layouts_base_html_head) |
|
133 | 133 | end |
|
134 | ||
|
134 | ||
|
135 | 135 | def test_call_hook_from_view_with_request_added_to_context |
|
136 | 136 | @hook_module.add_listener(TestHook3) |
|
137 | 137 | assert_match /request/i, view_hook_helper.call_hook(:view_layouts_base_html_head) |
@@ -146,27 +146,27 class Redmine::Hook::ManagerTest < ActiveSupport::TestCase | |||
|
146 | 146 | |
|
147 | 147 | def test_call_hook_should_not_change_the_default_url_for_email_notifications |
|
148 | 148 | issue = Issue.find(1) |
|
149 | ||
|
149 | ||
|
150 | 150 | ActionMailer::Base.deliveries.clear |
|
151 | 151 | Mailer.deliver_issue_add(issue) |
|
152 | 152 | mail = ActionMailer::Base.deliveries.last |
|
153 | ||
|
153 | ||
|
154 | 154 | @hook_module.add_listener(TestLinkToHook) |
|
155 | 155 | hook_helper.call_hook(:view_layouts_base_html_head) |
|
156 | ||
|
156 | ||
|
157 | 157 | ActionMailer::Base.deliveries.clear |
|
158 | 158 | Mailer.deliver_issue_add(issue) |
|
159 | 159 | mail2 = ActionMailer::Base.deliveries.last |
|
160 | ||
|
160 | ||
|
161 | 161 | assert_equal mail.body, mail2.body |
|
162 | 162 | end |
|
163 | ||
|
163 | ||
|
164 | 164 | def hook_helper |
|
165 | 165 | @hook_helper ||= TestHookHelperController.new |
|
166 | 166 | end |
|
167 | 167 | |
|
168 | 168 | def view_hook_helper |
|
169 |
@view_hook_helper ||= TestHookHelperView.new(R |
|
|
169 | @view_hook_helper ||= TestHookHelperView.new(RAILS_ROOT + '/app/views') | |
|
170 | 170 | end |
|
171 | 171 | end |
|
172 | 172 |
General Comments 0
You need to be logged in to leave comments.
Login now