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