annotate .svn/pristine/fb/fb831ceb031f77a301df0cd90da94f30274b8153.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 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1296 19
Chris@1296 20 class AdminControllerTest < ActionController::TestCase
Chris@1296 21 fixtures :projects, :users, :roles
Chris@1296 22
Chris@1296 23 def setup
Chris@1296 24 User.current = nil
Chris@1296 25 @request.session[:user_id] = 1 # admin
Chris@1296 26 end
Chris@1296 27
Chris@1296 28 def test_index
Chris@1296 29 get :index
Chris@1296 30 assert_no_tag :tag => 'div',
Chris@1296 31 :attributes => { :class => /nodata/ }
Chris@1296 32 end
Chris@1296 33
Chris@1296 34 def test_index_with_no_configuration_data
Chris@1296 35 delete_configuration_data
Chris@1296 36 get :index
Chris@1296 37 assert_tag :tag => 'div',
Chris@1296 38 :attributes => { :class => /nodata/ }
Chris@1296 39 end
Chris@1296 40
Chris@1296 41 def test_projects
Chris@1296 42 get :projects
Chris@1296 43 assert_response :success
Chris@1296 44 assert_template 'projects'
Chris@1296 45 assert_not_nil assigns(:projects)
Chris@1296 46 # active projects only
Chris@1296 47 assert_nil assigns(:projects).detect {|u| !u.active?}
Chris@1296 48 end
Chris@1296 49
Chris@1296 50 def test_projects_with_status_filter
Chris@1296 51 get :projects, :status => 1
Chris@1296 52 assert_response :success
Chris@1296 53 assert_template 'projects'
Chris@1296 54 assert_not_nil assigns(:projects)
Chris@1296 55 # active projects only
Chris@1296 56 assert_nil assigns(:projects).detect {|u| !u.active?}
Chris@1296 57 end
Chris@1296 58
Chris@1296 59 def test_projects_with_name_filter
Chris@1296 60 get :projects, :name => 'store', :status => ''
Chris@1296 61 assert_response :success
Chris@1296 62 assert_template 'projects'
Chris@1296 63 projects = assigns(:projects)
Chris@1296 64 assert_not_nil projects
Chris@1296 65 assert_equal 1, projects.size
Chris@1296 66 assert_equal 'OnlineStore', projects.first.name
Chris@1296 67 end
Chris@1296 68
Chris@1296 69 def test_load_default_configuration_data
Chris@1296 70 delete_configuration_data
Chris@1296 71 post :default_configuration, :lang => 'fr'
Chris@1296 72 assert_response :redirect
Chris@1296 73 assert_nil flash[:error]
Chris@1296 74 assert IssueStatus.find_by_name('Nouveau')
Chris@1296 75 end
Chris@1296 76
Chris@1296 77 def test_load_default_configuration_data_should_rescue_error
Chris@1296 78 delete_configuration_data
Chris@1296 79 Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong"))
Chris@1296 80 post :default_configuration, :lang => 'fr'
Chris@1296 81 assert_response :redirect
Chris@1296 82 assert_not_nil flash[:error]
Chris@1296 83 assert_match /Something went wrong/, flash[:error]
Chris@1296 84 end
Chris@1296 85
Chris@1296 86 def test_test_email
Chris@1296 87 user = User.find(1)
Chris@1296 88 user.pref[:no_self_notified] = '1'
Chris@1296 89 user.pref.save!
Chris@1296 90 ActionMailer::Base.deliveries.clear
Chris@1296 91
Chris@1296 92 get :test_email
Chris@1296 93 assert_redirected_to '/settings/edit?tab=notifications'
Chris@1296 94 mail = ActionMailer::Base.deliveries.last
Chris@1296 95 assert_not_nil mail
Chris@1296 96 user = User.find(1)
Chris@1296 97 assert_equal [user.mail], mail.bcc
Chris@1296 98 end
Chris@1296 99
Chris@1296 100 def test_test_email_failure_should_display_the_error
Chris@1296 101 Mailer.stubs(:test_email).raises(Exception, 'Some error message')
Chris@1296 102 get :test_email
Chris@1296 103 assert_redirected_to '/settings/edit?tab=notifications'
Chris@1296 104 assert_match /Some error message/, flash[:error]
Chris@1296 105 end
Chris@1296 106
Chris@1296 107 def test_no_plugins
Chris@1296 108 Redmine::Plugin.clear
Chris@1296 109
Chris@1296 110 get :plugins
Chris@1296 111 assert_response :success
Chris@1296 112 assert_template 'plugins'
Chris@1296 113 end
Chris@1296 114
Chris@1296 115 def test_plugins
Chris@1296 116 # Register a few plugins
Chris@1296 117 Redmine::Plugin.register :foo do
Chris@1296 118 name 'Foo plugin'
Chris@1296 119 author 'John Smith'
Chris@1296 120 description 'This is a test plugin'
Chris@1296 121 version '0.0.1'
Chris@1296 122 settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
Chris@1296 123 end
Chris@1296 124 Redmine::Plugin.register :bar do
Chris@1296 125 end
Chris@1296 126
Chris@1296 127 get :plugins
Chris@1296 128 assert_response :success
Chris@1296 129 assert_template 'plugins'
Chris@1296 130
Chris@1296 131 assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' }
Chris@1296 132 assert_tag :td, :child => { :tag => 'span', :content => 'Bar' }
Chris@1296 133 end
Chris@1296 134
Chris@1296 135 def test_info
Chris@1296 136 get :info
Chris@1296 137 assert_response :success
Chris@1296 138 assert_template 'info'
Chris@1296 139 end
Chris@1296 140
Chris@1296 141 def test_admin_menu_plugin_extension
Chris@1296 142 Redmine::MenuManager.map :admin_menu do |menu|
Chris@1296 143 menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test'
Chris@1296 144 end
Chris@1296 145
Chris@1296 146 get :index
Chris@1296 147 assert_response :success
Chris@1296 148 assert_tag :a, :attributes => { :href => '/foo/bar' },
Chris@1296 149 :content => 'Test'
Chris@1296 150
Chris@1296 151 Redmine::MenuManager.map :admin_menu do |menu|
Chris@1296 152 menu.delete :test_admin_menu_plugin_extension
Chris@1296 153 end
Chris@1296 154 end
Chris@1296 155
Chris@1296 156 private
Chris@1296 157
Chris@1296 158 def delete_configuration_data
Chris@1296 159 Role.delete_all('builtin = 0')
Chris@1296 160 Tracker.delete_all
Chris@1296 161 IssueStatus.delete_all
Chris@1296 162 Enumeration.delete_all
Chris@1296 163 end
Chris@1296 164 end