annotate .svn/pristine/d4/d4482ad7b7f59be62f8bc68fbfaf937393743402.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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