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