##// END OF EJS Templates
Don't clear plugins in tests (#16258)....
Jean-Philippe Lang -
r12712:913c8cd2e649
parent child
Show More
@@ -1,167 +1,168
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 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_select 'div.nodata', 0
31 31 end
32 32
33 33 def test_index_with_no_configuration_data
34 34 delete_configuration_data
35 35 get :index
36 36 assert_select 'div.nodata'
37 37 end
38 38
39 39 def test_projects
40 40 get :projects
41 41 assert_response :success
42 42 assert_template 'projects'
43 43 assert_not_nil assigns(:projects)
44 44 # active projects only
45 45 assert_nil assigns(:projects).detect {|u| !u.active?}
46 46 end
47 47
48 48 def test_projects_with_status_filter
49 49 get :projects, :status => 1
50 50 assert_response :success
51 51 assert_template 'projects'
52 52 assert_not_nil assigns(:projects)
53 53 # active projects only
54 54 assert_nil assigns(:projects).detect {|u| !u.active?}
55 55 end
56 56
57 57 def test_projects_with_name_filter
58 58 get :projects, :name => 'store', :status => ''
59 59 assert_response :success
60 60 assert_template 'projects'
61 61 projects = assigns(:projects)
62 62 assert_not_nil projects
63 63 assert_equal 1, projects.size
64 64 assert_equal 'OnlineStore', projects.first.name
65 65 end
66 66
67 67 def test_load_default_configuration_data
68 68 delete_configuration_data
69 69 post :default_configuration, :lang => 'fr'
70 70 assert_response :redirect
71 71 assert_nil flash[:error]
72 72 assert IssueStatus.find_by_name('Nouveau')
73 73 end
74 74
75 75 def test_load_default_configuration_data_should_rescue_error
76 76 delete_configuration_data
77 77 Redmine::DefaultData::Loader.stubs(:load).raises(Exception.new("Something went wrong"))
78 78 post :default_configuration, :lang => 'fr'
79 79 assert_response :redirect
80 80 assert_not_nil flash[:error]
81 81 assert_match /Something went wrong/, flash[:error]
82 82 end
83 83
84 84 def test_test_email
85 85 user = User.find(1)
86 86 user.pref.no_self_notified = '1'
87 87 user.pref.save!
88 88 ActionMailer::Base.deliveries.clear
89 89
90 90 get :test_email
91 91 assert_redirected_to '/settings?tab=notifications'
92 92 mail = ActionMailer::Base.deliveries.last
93 93 assert_not_nil mail
94 94 user = User.find(1)
95 95 assert_equal [user.mail], mail.bcc
96 96 end
97 97
98 98 def test_test_email_failure_should_display_the_error
99 99 Mailer.stubs(:test_email).raises(Exception, 'Some error message')
100 100 get :test_email
101 101 assert_redirected_to '/settings?tab=notifications'
102 102 assert_match /Some error message/, flash[:error]
103 103 end
104 104
105 105 def test_no_plugins
106 Redmine::Plugin.clear
106 Redmine::Plugin.stubs(:registered_plugins).returns({})
107 107
108 108 get :plugins
109 109 assert_response :success
110 110 assert_template 'plugins'
111 assert_equal [], assigns(:plugins)
111 112 end
112 113
113 114 def test_plugins
114 115 # Register a few plugins
115 116 Redmine::Plugin.register :foo do
116 117 name 'Foo plugin'
117 118 author 'John Smith'
118 119 description 'This is a test plugin'
119 120 version '0.0.1'
120 121 settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings'
121 122 end
122 123 Redmine::Plugin.register :bar do
123 124 end
124 125
125 126 get :plugins
126 127 assert_response :success
127 128 assert_template 'plugins'
128 129
129 130 assert_select 'tr#plugin-foo' do
130 131 assert_select 'td span.name', :text => 'Foo plugin'
131 132 assert_select 'td.configure a[href=/settings/plugin/foo]'
132 133 end
133 134 assert_select 'tr#plugin-bar' do
134 135 assert_select 'td span.name', :text => 'Bar'
135 136 assert_select 'td.configure a', 0
136 137 end
137 138 end
138 139
139 140 def test_info
140 141 get :info
141 142 assert_response :success
142 143 assert_template 'info'
143 144 end
144 145
145 146 def test_admin_menu_plugin_extension
146 147 Redmine::MenuManager.map :admin_menu do |menu|
147 148 menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test'
148 149 end
149 150
150 151 get :index
151 152 assert_response :success
152 153 assert_select 'div#admin-menu a[href=/foo/bar]', :text => 'Test'
153 154
154 155 Redmine::MenuManager.map :admin_menu do |menu|
155 156 menu.delete :test_admin_menu_plugin_extension
156 157 end
157 158 end
158 159
159 160 private
160 161
161 162 def delete_configuration_data
162 163 Role.delete_all('builtin = 0')
163 164 Tracker.delete_all
164 165 IssueStatus.delete_all
165 166 Enumeration.delete_all
166 167 end
167 168 end
General Comments 0
You need to be logged in to leave comments. Login now