annotate .svn/pristine/ce/cef18514271092169d5d166f4163b28499491884.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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