annotate .svn/pristine/2e/2e330182b29b2891c9c2bca0816fa09b38e7c57b.svn-base @ 1494:e248c7af89ec redmine-2.4

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