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