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