comparison .svn/pristine/e0/e09af230a1244dd904e00eb402f9ad5ad77a9fd1.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
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../../../test_helper', __FILE__)
19
20 class HookTest < ActionController::IntegrationTest
21 fixtures :users, :roles, :projects, :members, :member_roles
22
23 # Hooks that are manually registered later
24 class ProjectBasedTemplate < Redmine::Hook::ViewListener
25 def view_layouts_base_html_head(context)
26 # Adds a project stylesheet
27 stylesheet_link_tag(context[:project].identifier) if context[:project]
28 end
29 end
30
31 class SidebarContent < Redmine::Hook::ViewListener
32 def view_layouts_base_sidebar(context)
33 content_tag('p', 'Sidebar hook')
34 end
35 end
36
37 class ContentForInsideHook < Redmine::Hook::ViewListener
38 render_on :view_welcome_index_left, :inline => <<-VIEW
39 <% content_for :header_tags do %>
40 <%= javascript_include_tag 'test_plugin.js', :plugin => 'test_plugin' %>
41 <%= stylesheet_link_tag 'test_plugin.css', :plugin => 'test_plugin' %>
42 <% end %>
43
44 <p>ContentForInsideHook content</p>
45 VIEW
46 end
47
48 def setup
49 Redmine::Hook.clear_listeners
50 end
51
52 def teardown
53 Redmine::Hook.clear_listeners
54 end
55
56 def test_html_head_hook_response
57 Redmine::Hook.add_listener(ProjectBasedTemplate)
58
59 get '/projects/ecookbook'
60 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
61 :parent => {:tag => 'head'}
62 end
63
64 def test_empty_sidebar_should_be_hidden
65 get '/'
66 assert_select 'div#main.nosidebar'
67 end
68
69 def test_sidebar_with_hook_content_should_not_be_hidden
70 Redmine::Hook.add_listener(SidebarContent)
71
72 get '/'
73 assert_select 'div#sidebar p', :text => 'Sidebar hook'
74 assert_select 'div#main'
75 assert_select 'div#main.nosidebar', 0
76 end
77
78 def test_hook_with_content_for_should_append_content
79 Redmine::Hook.add_listener(ContentForInsideHook)
80
81 get '/'
82 assert_response :success
83 assert_select 'p', :text => 'ContentForInsideHook content'
84 assert_select 'head' do
85 assert_select 'script[src=/plugin_assets/test_plugin/javascripts/test_plugin.js]'
86 assert_select 'link[href=/plugin_assets/test_plugin/stylesheets/test_plugin.css]'
87 end
88 end
89 end