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