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