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