@@ -60,16 +60,7 module Redmine | |||||
60 | returning [] do |response| |
|
60 | returning [] do |response| | |
61 | hls = hook_listeners(hook) |
|
61 | hls = hook_listeners(hook) | |
62 | if hls.any? |
|
62 | if hls.any? | |
63 | request = context[:request] |
|
63 | default_url_options[:only_path] ||= true | |
64 | if request |
|
|||
65 | default_url_options[:host] ||= request.env["SERVER_NAME"] |
|
|||
66 | # Only set port if it's requested and isn't port 80. Otherwise a url |
|
|||
67 | # like: +http://example.com:/url+ may be generated |
|
|||
68 | if request.env["SERVER_PORT"] && request.env["SERVER_PORT"] != 80 |
|
|||
69 | default_url_options[:port] ||= request.env["SERVER_PORT"] |
|
|||
70 | end |
|
|||
71 | default_url_options[:protocol] ||= request.protocol |
|
|||
72 | end |
|
|||
73 | hls.each {|listener| response << listener.send(hook, context)} |
|
64 | hls.each {|listener| response << listener.send(hook, context)} | |
74 | end |
|
65 | end | |
75 | end |
|
66 | end |
@@ -100,41 +100,11 class Redmine::Hook::ManagerTest < Test::Unit::TestCase | |||||
100 | assert_equal ['Test hook 1 listener.', 'Test hook 2 listener.'], @hook_helper.call_hook(:view_layouts_base_html_head) |
|
100 | assert_equal ['Test hook 1 listener.', 'Test hook 2 listener.'], @hook_helper.call_hook(:view_layouts_base_html_head) | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | # Context: Redmine::Hook::call_hook |
|
103 | # Context: Redmine::Hook::Helper.call_hook default_url | |
104 |
def test_call_hook_default_url_options |
|
104 | def test_call_hook_default_url_options | |
105 | request = ActionController::TestRequest.new |
|
|||
106 | request.env = { "SERVER_NAME" => 'example.com'} |
|
|||
107 | @hook_module.add_listener(TestLinkToHook) |
|
105 | @hook_module.add_listener(TestLinkToHook) | |
108 |
|
106 | |||
109 | assert_equal ['<a href="http://example.com/issues">Issues</a>'], |
|
107 | assert_equal ['<a href="/issues">Issues</a>'], @hook_helper.call_hook(:view_layouts_base_html_head) | |
110 | @hook_helper.call_hook(:view_layouts_base_html_head, :request => request) |
|
|||
111 | end |
|
|||
112 |
|
||||
113 | def test_call_hook_default_url_options_set_with_no_standard_request_port |
|
|||
114 | request = ActionController::TestRequest.new |
|
|||
115 | request.env = { "SERVER_NAME" => 'example.com', "SERVER_PORT" => 3000} |
|
|||
116 | @hook_module.add_listener(TestLinkToHook) |
|
|||
117 |
|
||||
118 | assert_equal ['<a href="http://example.com:3000/issues">Issues</a>'], |
|
|||
119 | @hook_helper.call_hook(:view_layouts_base_html_head, :request => request) |
|
|||
120 | end |
|
|||
121 |
|
||||
122 | def test_call_hook_default_url_options_set_with_ssl |
|
|||
123 | request = ActionController::TestRequest.new |
|
|||
124 | request.env = { "SERVER_NAME" => 'example.com', "HTTPS" => 'on'} |
|
|||
125 | @hook_module.add_listener(TestLinkToHook) |
|
|||
126 |
|
||||
127 | assert_equal ['<a href="https://example.com/issues">Issues</a>'], |
|
|||
128 | @hook_helper.call_hook(:view_layouts_base_html_head, :request => request) |
|
|||
129 | end |
|
|||
130 |
|
||||
131 | def test_call_hook_default_url_options_set_with_forwarded_ssl |
|
|||
132 | request = ActionController::TestRequest.new |
|
|||
133 | request.env = { "SERVER_NAME" => 'example.com', "HTTP_X_FORWARDED_PROTO" => "https"} |
|
|||
134 | @hook_module.add_listener(TestLinkToHook) |
|
|||
135 |
|
||||
136 | assert_equal ['<a href="https://example.com/issues">Issues</a>'], |
|
|||
137 | @hook_helper.call_hook(:view_layouts_base_html_head, :request => request) |
|
|||
138 | end |
|
108 | end | |
139 |
|
109 | |||
140 | # Context: Redmine::Hook::Helper.call_hook |
|
110 | # Context: Redmine::Hook::Helper.call_hook |
General Comments 0
You need to be logged in to leave comments.
Login now