@@ -0,0 +1,67 | |||
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2012 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 MenuManagerTest < ActionController::IntegrationTest | |
|
21 | ||
|
22 | fixtures :users, :roles, :projects, :members, :member_roles | |
|
23 | ||
|
24 | # Hooks that are manually registered later | |
|
25 | class ProjectBasedTemplate < Redmine::Hook::ViewListener | |
|
26 | def view_layouts_base_html_head(context) | |
|
27 | # Adds a project stylesheet | |
|
28 | stylesheet_link_tag(context[:project].identifier) if context[:project] | |
|
29 | end | |
|
30 | end | |
|
31 | ||
|
32 | class SidebarContent < Redmine::Hook::ViewListener | |
|
33 | def view_layouts_base_sidebar(context) | |
|
34 | content_tag('p', 'Sidebar hook') | |
|
35 | end | |
|
36 | end | |
|
37 | ||
|
38 | def setup | |
|
39 | Redmine::Hook.clear_listeners | |
|
40 | end | |
|
41 | ||
|
42 | def teardown | |
|
43 | Redmine::Hook.clear_listeners | |
|
44 | end | |
|
45 | ||
|
46 | def test_html_head_hook_response | |
|
47 | Redmine::Hook.add_listener(ProjectBasedTemplate) | |
|
48 | ||
|
49 | get '/projects/ecookbook' | |
|
50 | assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'}, | |
|
51 | :parent => {:tag => 'head'} | |
|
52 | end | |
|
53 | ||
|
54 | def test_empty_sidebar_should_be_hidden | |
|
55 | get '/' | |
|
56 | assert_select 'div#main.nosidebar' | |
|
57 | end | |
|
58 | ||
|
59 | def test_sidebar_with_hook_content_should_not_be_hidden | |
|
60 | Redmine::Hook.add_listener(SidebarContent) | |
|
61 | ||
|
62 | get '/' | |
|
63 | assert_select 'div#sidebar p', :text => 'Sidebar hook' | |
|
64 | assert_select 'div#main' | |
|
65 | assert_select 'div#main.nosidebar', 0 | |
|
66 | end | |
|
67 | end |
@@ -1108,6 +1108,14 module ApplicationHelper | |||
|
1108 | 1108 | (@has_content && @has_content[name]) || false |
|
1109 | 1109 | end |
|
1110 | 1110 | |
|
1111 | def sidebar_content? | |
|
1112 | has_content?(:sidebar) || view_layouts_base_sidebar_hook_response.present? | |
|
1113 | end | |
|
1114 | ||
|
1115 | def view_layouts_base_sidebar_hook_response | |
|
1116 | @view_layouts_base_sidebar_hook_response ||= call_hook(:view_layouts_base_sidebar) | |
|
1117 | end | |
|
1118 | ||
|
1111 | 1119 | def email_delivery_enabled? |
|
1112 | 1120 | !!ActionMailer::Base.perform_deliveries |
|
1113 | 1121 | end |
@@ -56,10 +56,10 | |||
|
56 | 56 | <% end %> |
|
57 | 57 | </div> |
|
58 | 58 | |
|
59 |
<%= tag('div', {:id => 'main', :class => ( |
|
|
59 | <%= tag('div', {:id => 'main', :class => (sidebar_content? ? '' : 'nosidebar')}, true) %> | |
|
60 | 60 | <div id="sidebar"> |
|
61 | 61 | <%= yield :sidebar %> |
|
62 |
<%= |
|
|
62 | <%= view_layouts_base_sidebar_hook_response %> | |
|
63 | 63 | </div> |
|
64 | 64 | |
|
65 | 65 | <div id="content"> |
@@ -520,23 +520,4 class ProjectsControllerTest < ActionController::TestCase | |||
|
520 | 520 | assert_response :success |
|
521 | 521 | assert_template 'show' |
|
522 | 522 | end |
|
523 | ||
|
524 | # A hook that is manually registered later | |
|
525 | class ProjectBasedTemplate < Redmine::Hook::ViewListener | |
|
526 | def view_layouts_base_html_head(context) | |
|
527 | # Adds a project stylesheet | |
|
528 | stylesheet_link_tag(context[:project].identifier) if context[:project] | |
|
529 | end | |
|
530 | end | |
|
531 | # Don't use this hook now | |
|
532 | Redmine::Hook.clear_listeners | |
|
533 | ||
|
534 | def test_hook_response | |
|
535 | Redmine::Hook.add_listener(ProjectBasedTemplate) | |
|
536 | get :show, :id => 1 | |
|
537 | assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'}, | |
|
538 | :parent => {:tag => 'head'} | |
|
539 | ||
|
540 | Redmine::Hook.clear_listeners | |
|
541 | end | |
|
542 | 523 | end |
General Comments 0
You need to be logged in to leave comments.
Login now