To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / functional / .svn / text-base / admin_controller_test.rb.svn-base @ 441:cbce1fd3b1b7

History | View | Annotate | Download (3.99 KB)

1
# redMine - project management software
2
# Copyright (C) 2006-2007  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

    
18
require File.expand_path('../../test_helper', __FILE__)
19
require 'admin_controller'
20

    
21
# Re-raise errors caught by the controller.
22
class AdminController; def rescue_action(e) raise e end; end
23

    
24
class AdminControllerTest < ActionController::TestCase
25
  fixtures :projects, :users, :roles
26
  
27
  def setup
28
    @controller = AdminController.new
29
    @request    = ActionController::TestRequest.new
30
    @response   = ActionController::TestResponse.new
31
    User.current = nil
32
    @request.session[:user_id] = 1 # admin
33
  end
34
  
35
  def test_index
36
    get :index
37
    assert_no_tag :tag => 'div',
38
                  :attributes => { :class => /nodata/ }
39
  end
40
  
41
  def test_index_with_no_configuration_data
42
    delete_configuration_data
43
    get :index
44
    assert_tag :tag => 'div',
45
               :attributes => { :class => /nodata/ }
46
  end
47
  
48
  def test_projects
49
    get :projects
50
    assert_response :success
51
    assert_template 'projects'
52
    assert_not_nil assigns(:projects)
53
    # active projects only
54
    assert_nil assigns(:projects).detect {|u| !u.active?}
55
  end
56
  
57
  def test_projects_with_name_filter
58
    get :projects, :name => 'store', :status => ''
59
    assert_response :success
60
    assert_template 'projects'
61
    projects = assigns(:projects)
62
    assert_not_nil projects
63
    assert_equal 1, projects.size
64
    assert_equal 'OnlineStore', projects.first.name
65
  end
66
  
67
  def test_load_default_configuration_data
68
    delete_configuration_data
69
    post :default_configuration, :lang => 'fr'
70
    assert_response :redirect
71
    assert_nil flash[:error]
72
    assert IssueStatus.find_by_name('Nouveau')
73
  end
74
  
75
  def test_test_email
76
    get :test_email
77
    assert_redirected_to '/settings/edit?tab=notifications'
78
    mail = ActionMailer::Base.deliveries.last
79
    assert_kind_of TMail::Mail, mail
80
    user = User.find(1)
81
    assert_equal [user.mail], mail.bcc
82
  end
83
  
84
  def test_no_plugins
85
    Redmine::Plugin.clear
86
    
87
    get :plugins
88
    assert_response :success
89
    assert_template 'plugins'
90
  end
91
  
92
  def test_plugins
93
    # Register a few plugins
94
    Redmine::Plugin.register :foo do
95
      name 'Foo plugin'
96
      author 'John Smith'
97
      description 'This is a test plugin'
98
      version '0.0.1'
99
      settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
100
    end
101
    Redmine::Plugin.register :bar do
102
    end
103
  
104
    get :plugins
105
    assert_response :success
106
    assert_template 'plugins'
107
    
108
    assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' }
109
    assert_tag :td, :child => { :tag => 'span', :content => 'Bar' }
110
  end
111

    
112
  def test_info
113
    get :info
114
    assert_response :success
115
    assert_template 'info'
116
  end
117
  
118
  def test_admin_menu_plugin_extension
119
    Redmine::MenuManager.map :admin_menu do |menu|
120
      menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test'
121
    end
122
    
123
    get :index
124
    assert_response :success
125
    assert_tag :a, :attributes => { :href => '/foo/bar' },
126
                   :content => 'Test'
127
    
128
    Redmine::MenuManager.map :admin_menu do |menu|
129
      menu.delete :test_admin_menu_plugin_extension
130
    end
131
  end
132
  
133
  private
134
  
135
  def delete_configuration_data
136
    Role.delete_all('builtin = 0')
137
    Tracker.delete_all
138
    IssueStatus.delete_all
139
    Enumeration.delete_all
140
  end
141
end