Chris@909: # Redmine - project management software Chris@1494: # Copyright (C) 2006-2014 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@909: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@909: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@119: require File.expand_path('../../test_helper', __FILE__) Chris@0: Chris@0: class AdminControllerTest < ActionController::TestCase Chris@0: fixtures :projects, :users, :roles Chris@909: Chris@0: def setup Chris@0: User.current = nil Chris@0: @request.session[:user_id] = 1 # admin Chris@0: end Chris@909: Chris@0: def test_index Chris@0: get :index Chris@1464: assert_select 'div.nodata', 0 Chris@0: end Chris@909: Chris@0: def test_index_with_no_configuration_data Chris@0: delete_configuration_data Chris@0: get :index Chris@1464: assert_select 'div.nodata' Chris@0: end Chris@909: Chris@0: def test_projects Chris@0: get :projects Chris@0: assert_response :success Chris@0: assert_template 'projects' Chris@0: assert_not_nil assigns(:projects) Chris@0: # active projects only Chris@0: assert_nil assigns(:projects).detect {|u| !u.active?} Chris@0: end Chris@909: Chris@1115: def test_projects_with_status_filter Chris@1115: get :projects, :status => 1 Chris@1115: assert_response :success Chris@1115: assert_template 'projects' Chris@1115: assert_not_nil assigns(:projects) Chris@1115: # active projects only Chris@1115: assert_nil assigns(:projects).detect {|u| !u.active?} Chris@1115: end Chris@1115: Chris@0: def test_projects_with_name_filter Chris@0: get :projects, :name => 'store', :status => '' Chris@0: assert_response :success Chris@0: assert_template 'projects' Chris@0: projects = assigns(:projects) Chris@0: assert_not_nil projects Chris@0: assert_equal 1, projects.size Chris@0: assert_equal 'OnlineStore', projects.first.name Chris@0: end Chris@909: Chris@0: def test_load_default_configuration_data Chris@0: delete_configuration_data Chris@0: post :default_configuration, :lang => 'fr' Chris@0: assert_response :redirect Chris@0: assert_nil flash[:error] Chris@0: assert IssueStatus.find_by_name('Nouveau') Chris@0: end Chris@909: Chris@1115: def test_load_default_configuration_data_should_rescue_error Chris@1115: delete_configuration_data Chris@1115: Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong")) Chris@1115: post :default_configuration, :lang => 'fr' Chris@1115: assert_response :redirect Chris@1115: assert_not_nil flash[:error] Chris@1115: assert_match /Something went wrong/, flash[:error] Chris@1115: end Chris@1115: Chris@0: def test_test_email Chris@1115: user = User.find(1) Chris@1464: user.pref.no_self_notified = '1' Chris@1115: user.pref.save! Chris@1115: ActionMailer::Base.deliveries.clear Chris@1115: Chris@0: get :test_email Chris@1464: assert_redirected_to '/settings?tab=notifications' Chris@0: mail = ActionMailer::Base.deliveries.last Chris@1115: assert_not_nil mail Chris@0: user = User.find(1) Chris@0: assert_equal [user.mail], mail.bcc Chris@0: end Chris@909: Chris@1115: def test_test_email_failure_should_display_the_error Chris@1115: Mailer.stubs(:test_email).raises(Exception, 'Some error message') Chris@1115: get :test_email Chris@1464: assert_redirected_to '/settings?tab=notifications' Chris@1115: assert_match /Some error message/, flash[:error] Chris@1115: end Chris@1115: Chris@0: def test_no_plugins Chris@0: Redmine::Plugin.clear Chris@909: Chris@0: get :plugins Chris@0: assert_response :success Chris@0: assert_template 'plugins' Chris@0: end Chris@909: Chris@0: def test_plugins Chris@0: # Register a few plugins Chris@0: Redmine::Plugin.register :foo do Chris@0: name 'Foo plugin' Chris@0: author 'John Smith' Chris@0: description 'This is a test plugin' Chris@0: version '0.0.1' Chris@0: settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' Chris@0: end Chris@0: Redmine::Plugin.register :bar do Chris@0: end Chris@909: Chris@0: get :plugins Chris@0: assert_response :success Chris@0: assert_template 'plugins' Chris@909: Chris@1464: assert_select 'tr#plugin-foo' do Chris@1464: assert_select 'td span.name', :text => 'Foo plugin' Chris@1464: assert_select 'td.configure a[href=/settings/plugin/foo]' Chris@1464: end Chris@1464: assert_select 'tr#plugin-bar' do Chris@1464: assert_select 'td span.name', :text => 'Bar' Chris@1464: assert_select 'td.configure a', 0 Chris@1464: end Chris@0: end Chris@0: Chris@0: def test_info Chris@0: get :info Chris@0: assert_response :success Chris@0: assert_template 'info' Chris@0: end Chris@909: Chris@0: def test_admin_menu_plugin_extension Chris@0: Redmine::MenuManager.map :admin_menu do |menu| Chris@0: menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test' Chris@0: end Chris@909: Chris@0: get :index Chris@0: assert_response :success Chris@1464: assert_select 'div#admin-menu a[href=/foo/bar]', :text => 'Test' Chris@909: Chris@0: Redmine::MenuManager.map :admin_menu do |menu| Chris@0: menu.delete :test_admin_menu_plugin_extension Chris@0: end Chris@0: end Chris@909: Chris@0: private Chris@909: Chris@0: def delete_configuration_data Chris@0: Role.delete_all('builtin = 0') Chris@0: Tracker.delete_all Chris@0: IssueStatus.delete_all Chris@0: Enumeration.delete_all Chris@0: end Chris@0: end