##// END OF EJS Templates
Leading slash required with Rails 4.2....
Jean-Philippe Lang -
r13401:7296b569a3de
parent child
Show More
@@ -1,291 +1,291
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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 AccountTest < Redmine::IntegrationTest
20 class AccountTest < Redmine::IntegrationTest
21 fixtures :users, :roles
21 fixtures :users, :roles
22
22
23 def test_login
23 def test_login
24 get "my/page"
24 get "/my/page"
25 assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fmy%2Fpage"
25 assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fmy%2Fpage"
26 log_user('jsmith', 'jsmith')
26 log_user('jsmith', 'jsmith')
27
27
28 get "my/account"
28 get "/my/account"
29 assert_response :success
29 assert_response :success
30 assert_template "my/account"
30 assert_template "my/account"
31 end
31 end
32
32
33 def test_autologin
33 def test_autologin
34 user = User.find(1)
34 user = User.find(1)
35 Setting.autologin = "7"
35 Setting.autologin = "7"
36 Token.delete_all
36 Token.delete_all
37
37
38 # User logs in with 'autologin' checked
38 # User logs in with 'autologin' checked
39 post '/login', :username => user.login, :password => 'admin', :autologin => 1
39 post '/login', :username => user.login, :password => 'admin', :autologin => 1
40 assert_redirected_to '/my/page'
40 assert_redirected_to '/my/page'
41 token = Token.first
41 token = Token.first
42 assert_not_nil token
42 assert_not_nil token
43 assert_equal user, token.user
43 assert_equal user, token.user
44 assert_equal 'autologin', token.action
44 assert_equal 'autologin', token.action
45 assert_equal user.id, session[:user_id]
45 assert_equal user.id, session[:user_id]
46 assert_equal token.value, cookies['autologin']
46 assert_equal token.value, cookies['autologin']
47
47
48 # Session is cleared
48 # Session is cleared
49 reset!
49 reset!
50 User.current = nil
50 User.current = nil
51 # Clears user's last login timestamp
51 # Clears user's last login timestamp
52 user.update_attribute :last_login_on, nil
52 user.update_attribute :last_login_on, nil
53 assert_nil user.reload.last_login_on
53 assert_nil user.reload.last_login_on
54
54
55 # User comes back with user's autologin cookie
55 # User comes back with user's autologin cookie
56 cookies[:autologin] = token.value
56 cookies[:autologin] = token.value
57 get '/my/page'
57 get '/my/page'
58 assert_response :success
58 assert_response :success
59 assert_template 'my/page'
59 assert_template 'my/page'
60 assert_equal user.id, session[:user_id]
60 assert_equal user.id, session[:user_id]
61 assert_not_nil user.reload.last_login_on
61 assert_not_nil user.reload.last_login_on
62 end
62 end
63
63
64 def test_autologin_should_use_autologin_cookie_name
64 def test_autologin_should_use_autologin_cookie_name
65 Token.delete_all
65 Token.delete_all
66 Redmine::Configuration.stubs(:[]).with('autologin_cookie_name').returns('custom_autologin')
66 Redmine::Configuration.stubs(:[]).with('autologin_cookie_name').returns('custom_autologin')
67 Redmine::Configuration.stubs(:[]).with('autologin_cookie_path').returns('/')
67 Redmine::Configuration.stubs(:[]).with('autologin_cookie_path').returns('/')
68 Redmine::Configuration.stubs(:[]).with('autologin_cookie_secure').returns(false)
68 Redmine::Configuration.stubs(:[]).with('autologin_cookie_secure').returns(false)
69
69
70 with_settings :autologin => '7' do
70 with_settings :autologin => '7' do
71 assert_difference 'Token.count' do
71 assert_difference 'Token.count' do
72 post '/login', :username => 'admin', :password => 'admin', :autologin => 1
72 post '/login', :username => 'admin', :password => 'admin', :autologin => 1
73 end
73 end
74 assert_response 302
74 assert_response 302
75 assert cookies['custom_autologin'].present?
75 assert cookies['custom_autologin'].present?
76 token = cookies['custom_autologin']
76 token = cookies['custom_autologin']
77
77
78 # Session is cleared
78 # Session is cleared
79 reset!
79 reset!
80 cookies['custom_autologin'] = token
80 cookies['custom_autologin'] = token
81 get '/my/page'
81 get '/my/page'
82 assert_response :success
82 assert_response :success
83
83
84 assert_difference 'Token.count', -1 do
84 assert_difference 'Token.count', -1 do
85 post '/logout'
85 post '/logout'
86 end
86 end
87 assert cookies['custom_autologin'].blank?
87 assert cookies['custom_autologin'].blank?
88 end
88 end
89 end
89 end
90
90
91 def test_lost_password
91 def test_lost_password
92 Token.delete_all
92 Token.delete_all
93
93
94 get "account/lost_password"
94 get "/account/lost_password"
95 assert_response :success
95 assert_response :success
96 assert_template "account/lost_password"
96 assert_template "account/lost_password"
97 assert_select 'input[name=mail]'
97 assert_select 'input[name=mail]'
98
98
99 post "account/lost_password", :mail => 'jSmith@somenet.foo'
99 post "/account/lost_password", :mail => 'jSmith@somenet.foo'
100 assert_redirected_to "/login"
100 assert_redirected_to "/login"
101
101
102 token = Token.first
102 token = Token.first
103 assert_equal 'recovery', token.action
103 assert_equal 'recovery', token.action
104 assert_equal 'jsmith@somenet.foo', token.user.mail
104 assert_equal 'jsmith@somenet.foo', token.user.mail
105 assert !token.expired?
105 assert !token.expired?
106
106
107 get "account/lost_password", :token => token.value
107 get "/account/lost_password", :token => token.value
108 assert_response :success
108 assert_response :success
109 assert_template "account/password_recovery"
109 assert_template "account/password_recovery"
110 assert_select 'input[type=hidden][name=token][value=?]', token.value
110 assert_select 'input[type=hidden][name=token][value=?]', token.value
111 assert_select 'input[name=new_password]'
111 assert_select 'input[name=new_password]'
112 assert_select 'input[name=new_password_confirmation]'
112 assert_select 'input[name=new_password_confirmation]'
113
113
114 post "account/lost_password",
114 post "/account/lost_password",
115 :token => token.value, :new_password => 'newpass123',
115 :token => token.value, :new_password => 'newpass123',
116 :new_password_confirmation => 'newpass123'
116 :new_password_confirmation => 'newpass123'
117 assert_redirected_to "/login"
117 assert_redirected_to "/login"
118 assert_equal 'Password was successfully updated.', flash[:notice]
118 assert_equal 'Password was successfully updated.', flash[:notice]
119
119
120 log_user('jsmith', 'newpass123')
120 log_user('jsmith', 'newpass123')
121 assert_equal 0, Token.count
121 assert_equal 0, Token.count
122 end
122 end
123
123
124 def test_user_with_must_change_passwd_should_be_forced_to_change_its_password
124 def test_user_with_must_change_passwd_should_be_forced_to_change_its_password
125 User.find_by_login('jsmith').update_attribute :must_change_passwd, true
125 User.find_by_login('jsmith').update_attribute :must_change_passwd, true
126
126
127 post '/login', :username => 'jsmith', :password => 'jsmith'
127 post '/login', :username => 'jsmith', :password => 'jsmith'
128 assert_redirected_to '/my/page'
128 assert_redirected_to '/my/page'
129 follow_redirect!
129 follow_redirect!
130 assert_redirected_to '/my/password'
130 assert_redirected_to '/my/password'
131
131
132 get '/issues'
132 get '/issues'
133 assert_redirected_to '/my/password'
133 assert_redirected_to '/my/password'
134 end
134 end
135
135
136 def test_user_with_must_change_passwd_should_be_able_to_change_its_password
136 def test_user_with_must_change_passwd_should_be_able_to_change_its_password
137 User.find_by_login('jsmith').update_attribute :must_change_passwd, true
137 User.find_by_login('jsmith').update_attribute :must_change_passwd, true
138
138
139 post '/login', :username => 'jsmith', :password => 'jsmith'
139 post '/login', :username => 'jsmith', :password => 'jsmith'
140 assert_redirected_to '/my/page'
140 assert_redirected_to '/my/page'
141 follow_redirect!
141 follow_redirect!
142 assert_redirected_to '/my/password'
142 assert_redirected_to '/my/password'
143 follow_redirect!
143 follow_redirect!
144 assert_response :success
144 assert_response :success
145 post '/my/password', :password => 'jsmith', :new_password => 'newpassword', :new_password_confirmation => 'newpassword'
145 post '/my/password', :password => 'jsmith', :new_password => 'newpassword', :new_password_confirmation => 'newpassword'
146 assert_redirected_to '/my/account'
146 assert_redirected_to '/my/account'
147 follow_redirect!
147 follow_redirect!
148 assert_response :success
148 assert_response :success
149
149
150 assert_equal false, User.find_by_login('jsmith').must_change_passwd?
150 assert_equal false, User.find_by_login('jsmith').must_change_passwd?
151 end
151 end
152
152
153 def test_register_with_automatic_activation
153 def test_register_with_automatic_activation
154 Setting.self_registration = '3'
154 Setting.self_registration = '3'
155
155
156 get 'account/register'
156 get '/account/register'
157 assert_response :success
157 assert_response :success
158 assert_template 'account/register'
158 assert_template 'account/register'
159
159
160 post 'account/register',
160 post '/account/register',
161 :user => {:login => "newuser", :language => "en",
161 :user => {:login => "newuser", :language => "en",
162 :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
162 :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
163 :password => "newpass123", :password_confirmation => "newpass123"}
163 :password => "newpass123", :password_confirmation => "newpass123"}
164 assert_redirected_to '/my/account'
164 assert_redirected_to '/my/account'
165 follow_redirect!
165 follow_redirect!
166 assert_response :success
166 assert_response :success
167 assert_template 'my/account'
167 assert_template 'my/account'
168
168
169 user = User.find_by_login('newuser')
169 user = User.find_by_login('newuser')
170 assert_not_nil user
170 assert_not_nil user
171 assert user.active?
171 assert user.active?
172 assert_not_nil user.last_login_on
172 assert_not_nil user.last_login_on
173 end
173 end
174
174
175 def test_register_with_manual_activation
175 def test_register_with_manual_activation
176 Setting.self_registration = '2'
176 Setting.self_registration = '2'
177
177
178 post 'account/register',
178 post '/account/register',
179 :user => {:login => "newuser", :language => "en",
179 :user => {:login => "newuser", :language => "en",
180 :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
180 :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
181 :password => "newpass123", :password_confirmation => "newpass123"}
181 :password => "newpass123", :password_confirmation => "newpass123"}
182 assert_redirected_to '/login'
182 assert_redirected_to '/login'
183 assert !User.find_by_login('newuser').active?
183 assert !User.find_by_login('newuser').active?
184 end
184 end
185
185
186 def test_register_with_email_activation
186 def test_register_with_email_activation
187 Setting.self_registration = '1'
187 Setting.self_registration = '1'
188 Token.delete_all
188 Token.delete_all
189
189
190 post 'account/register',
190 post '/account/register',
191 :user => {:login => "newuser", :language => "en",
191 :user => {:login => "newuser", :language => "en",
192 :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
192 :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
193 :password => "newpass123", :password_confirmation => "newpass123"}
193 :password => "newpass123", :password_confirmation => "newpass123"}
194 assert_redirected_to '/login'
194 assert_redirected_to '/login'
195 assert !User.find_by_login('newuser').active?
195 assert !User.find_by_login('newuser').active?
196
196
197 token = Token.first
197 token = Token.first
198 assert_equal 'register', token.action
198 assert_equal 'register', token.action
199 assert_equal 'newuser@foo.bar', token.user.mail
199 assert_equal 'newuser@foo.bar', token.user.mail
200 assert !token.expired?
200 assert !token.expired?
201
201
202 get 'account/activate', :token => token.value
202 get '/account/activate', :token => token.value
203 assert_redirected_to '/login'
203 assert_redirected_to '/login'
204 log_user('newuser', 'newpass123')
204 log_user('newuser', 'newpass123')
205 end
205 end
206
206
207 def test_onthefly_registration
207 def test_onthefly_registration
208 # disable registration
208 # disable registration
209 Setting.self_registration = '0'
209 Setting.self_registration = '0'
210 AuthSource.expects(:authenticate).returns(
210 AuthSource.expects(:authenticate).returns(
211 {:login => 'foo', :firstname => 'Foo', :lastname => 'Smith',
211 {:login => 'foo', :firstname => 'Foo', :lastname => 'Smith',
212 :mail => 'foo@bar.com', :auth_source_id => 66})
212 :mail => 'foo@bar.com', :auth_source_id => 66})
213
213
214 post '/login', :username => 'foo', :password => 'bar'
214 post '/login', :username => 'foo', :password => 'bar'
215 assert_redirected_to '/my/page'
215 assert_redirected_to '/my/page'
216
216
217 user = User.find_by_login('foo')
217 user = User.find_by_login('foo')
218 assert user.is_a?(User)
218 assert user.is_a?(User)
219 assert_equal 66, user.auth_source_id
219 assert_equal 66, user.auth_source_id
220 assert user.hashed_password.blank?
220 assert user.hashed_password.blank?
221 end
221 end
222
222
223 def test_onthefly_registration_with_invalid_attributes
223 def test_onthefly_registration_with_invalid_attributes
224 # disable registration
224 # disable registration
225 Setting.self_registration = '0'
225 Setting.self_registration = '0'
226 AuthSource.expects(:authenticate).returns(
226 AuthSource.expects(:authenticate).returns(
227 {:login => 'foo', :lastname => 'Smith', :auth_source_id => 66})
227 {:login => 'foo', :lastname => 'Smith', :auth_source_id => 66})
228
228
229 post '/login', :username => 'foo', :password => 'bar'
229 post '/login', :username => 'foo', :password => 'bar'
230 assert_response :success
230 assert_response :success
231 assert_template 'account/register'
231 assert_template 'account/register'
232 assert_select 'input[name=?][value=""]', 'user[firstname]'
232 assert_select 'input[name=?][value=""]', 'user[firstname]'
233 assert_select 'input[name=?][value=Smith]', 'user[lastname]'
233 assert_select 'input[name=?][value=Smith]', 'user[lastname]'
234 assert_select 'input[name=?]', 'user[login]', 0
234 assert_select 'input[name=?]', 'user[login]', 0
235 assert_select 'input[name=?]', 'user[password]', 0
235 assert_select 'input[name=?]', 'user[password]', 0
236
236
237 post 'account/register',
237 post '/account/register',
238 :user => {:firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com'}
238 :user => {:firstname => 'Foo', :lastname => 'Smith', :mail => 'foo@bar.com'}
239 assert_redirected_to '/my/account'
239 assert_redirected_to '/my/account'
240
240
241 user = User.find_by_login('foo')
241 user = User.find_by_login('foo')
242 assert user.is_a?(User)
242 assert user.is_a?(User)
243 assert_equal 66, user.auth_source_id
243 assert_equal 66, user.auth_source_id
244 assert user.hashed_password.blank?
244 assert user.hashed_password.blank?
245 end
245 end
246
246
247 def test_registered_user_should_be_able_to_get_a_new_activation_email
247 def test_registered_user_should_be_able_to_get_a_new_activation_email
248 Token.delete_all
248 Token.delete_all
249
249
250 with_settings :self_registration => '1', :default_language => 'en' do
250 with_settings :self_registration => '1', :default_language => 'en' do
251 # register a new account
251 # register a new account
252 assert_difference 'User.count' do
252 assert_difference 'User.count' do
253 assert_difference 'Token.count' do
253 assert_difference 'Token.count' do
254 post 'account/register',
254 post '/account/register',
255 :user => {:login => "newuser", :language => "en",
255 :user => {:login => "newuser", :language => "en",
256 :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
256 :firstname => "New", :lastname => "User", :mail => "newuser@foo.bar",
257 :password => "newpass123", :password_confirmation => "newpass123"}
257 :password => "newpass123", :password_confirmation => "newpass123"}
258 end
258 end
259 end
259 end
260 user = User.order('id desc').first
260 user = User.order('id desc').first
261 assert_equal User::STATUS_REGISTERED, user.status
261 assert_equal User::STATUS_REGISTERED, user.status
262 reset!
262 reset!
263
263
264 # try to use "lost password"
264 # try to use "lost password"
265 assert_no_difference 'ActionMailer::Base.deliveries.size' do
265 assert_no_difference 'ActionMailer::Base.deliveries.size' do
266 post '/account/lost_password', :mail => 'newuser@foo.bar'
266 post '/account/lost_password', :mail => 'newuser@foo.bar'
267 end
267 end
268 assert_redirected_to '/account/lost_password'
268 assert_redirected_to '/account/lost_password'
269 follow_redirect!
269 follow_redirect!
270 assert_response :success
270 assert_response :success
271 assert_select 'div.flash', :text => /new activation email/
271 assert_select 'div.flash', :text => /new activation email/
272 assert_select 'div.flash a[href="/account/activation_email"]'
272 assert_select 'div.flash a[href="/account/activation_email"]'
273
273
274 # request a new action activation email
274 # request a new action activation email
275 assert_difference 'ActionMailer::Base.deliveries.size' do
275 assert_difference 'ActionMailer::Base.deliveries.size' do
276 get '/account/activation_email'
276 get '/account/activation_email'
277 end
277 end
278 assert_redirected_to '/login'
278 assert_redirected_to '/login'
279 token = Token.order('id desc').first
279 token = Token.order('id desc').first
280 activation_path = "/account/activate?token=#{token.value}"
280 activation_path = "/account/activate?token=#{token.value}"
281 assert_include activation_path, mail_body(ActionMailer::Base.deliveries.last)
281 assert_include activation_path, mail_body(ActionMailer::Base.deliveries.last)
282
282
283 # activate the account
283 # activate the account
284 get activation_path
284 get activation_path
285 assert_redirected_to '/login'
285 assert_redirected_to '/login'
286
286
287 post '/login', :username => 'newuser', :password => 'newpass123'
287 post '/login', :username => 'newuser', :password => 'newpass123'
288 assert_redirected_to '/my/page'
288 assert_redirected_to '/my/page'
289 end
289 end
290 end
290 end
291 end
291 end
@@ -1,61 +1,61
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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 AdminTest < Redmine::IntegrationTest
20 class AdminTest < Redmine::IntegrationTest
21 fixtures :projects, :trackers, :issue_statuses, :issues,
21 fixtures :projects, :trackers, :issue_statuses, :issues,
22 :enumerations, :users, :issue_categories,
22 :enumerations, :users, :issue_categories,
23 :projects_trackers,
23 :projects_trackers,
24 :roles,
24 :roles,
25 :member_roles,
25 :member_roles,
26 :members,
26 :members,
27 :enabled_modules
27 :enabled_modules
28
28
29 def test_add_user
29 def test_add_user
30 log_user("admin", "admin")
30 log_user("admin", "admin")
31 get "/users/new"
31 get "/users/new"
32 assert_response :success
32 assert_response :success
33 assert_template "users/new"
33 assert_template "users/new"
34 post "/users",
34 post "/users",
35 :user => { :login => "psmith", :firstname => "Paul",
35 :user => { :login => "psmith", :firstname => "Paul",
36 :lastname => "Smith", :mail => "psmith@somenet.foo",
36 :lastname => "Smith", :mail => "psmith@somenet.foo",
37 :language => "en", :password => "psmith09",
37 :language => "en", :password => "psmith09",
38 :password_confirmation => "psmith09" }
38 :password_confirmation => "psmith09" }
39
39
40 user = User.find_by_login("psmith")
40 user = User.find_by_login("psmith")
41 assert_kind_of User, user
41 assert_kind_of User, user
42 assert_redirected_to "/users/#{ user.id }/edit"
42 assert_redirected_to "/users/#{ user.id }/edit"
43
43
44 logged_user = User.try_to_login("psmith", "psmith09")
44 logged_user = User.try_to_login("psmith", "psmith09")
45 assert_kind_of User, logged_user
45 assert_kind_of User, logged_user
46 assert_equal "Paul", logged_user.firstname
46 assert_equal "Paul", logged_user.firstname
47
47
48 put "users/#{user.id}", :id => user.id, :user => { :status => User::STATUS_LOCKED }
48 put "/users/#{user.id}", :id => user.id, :user => { :status => User::STATUS_LOCKED }
49 assert_redirected_to "/users/#{ user.id }/edit"
49 assert_redirected_to "/users/#{ user.id }/edit"
50 locked_user = User.try_to_login("psmith", "psmith09")
50 locked_user = User.try_to_login("psmith", "psmith09")
51 assert_equal nil, locked_user
51 assert_equal nil, locked_user
52 end
52 end
53
53
54 test "Add a user as an anonymous user should fail" do
54 test "Add a user as an anonymous user should fail" do
55 post '/users',
55 post '/users',
56 :user => { :login => 'psmith', :firstname => 'Paul'},
56 :user => { :login => 'psmith', :firstname => 'Paul'},
57 :password => "psmith09", :password_confirmation => "psmith09"
57 :password => "psmith09", :password_confirmation => "psmith09"
58 assert_response :redirect
58 assert_response :redirect
59 assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fusers"
59 assert_redirected_to "/login?back_url=http%3A%2F%2Fwww.example.com%2Fusers"
60 end
60 end
61 end
61 end
@@ -1,90 +1,90
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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 ApplicationTest < Redmine::IntegrationTest
20 class ApplicationTest < Redmine::IntegrationTest
21 include Redmine::I18n
21 include Redmine::I18n
22
22
23 fixtures :projects, :trackers, :issue_statuses, :issues,
23 fixtures :projects, :trackers, :issue_statuses, :issues,
24 :enumerations, :users, :issue_categories,
24 :enumerations, :users, :issue_categories,
25 :projects_trackers,
25 :projects_trackers,
26 :roles,
26 :roles,
27 :member_roles,
27 :member_roles,
28 :members,
28 :members,
29 :enabled_modules
29 :enabled_modules
30
30
31 def test_set_localization
31 def test_set_localization
32 Setting.default_language = 'en'
32 Setting.default_language = 'en'
33
33
34 # a french user
34 # a french user
35 get 'projects', { }, 'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
35 get '/projects', { }, 'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
36 assert_response :success
36 assert_response :success
37 assert_select 'h2', :text => 'Projets'
37 assert_select 'h2', :text => 'Projets'
38 assert_equal :fr, current_language
38 assert_equal :fr, current_language
39 assert_select "html[lang=?]", "fr"
39 assert_select "html[lang=?]", "fr"
40
40
41 # then an italien user
41 # then an italien user
42 get 'projects', { }, 'HTTP_ACCEPT_LANGUAGE' => 'it;q=0.8,en-us;q=0.5,en;q=0.3'
42 get '/projects', { }, 'HTTP_ACCEPT_LANGUAGE' => 'it;q=0.8,en-us;q=0.5,en;q=0.3'
43 assert_response :success
43 assert_response :success
44 assert_select 'h2', :text => 'Progetti'
44 assert_select 'h2', :text => 'Progetti'
45 assert_equal :it, current_language
45 assert_equal :it, current_language
46 assert_select "html[lang=?]", "it"
46 assert_select "html[lang=?]", "it"
47
47
48 # not a supported language: default language should be used
48 # not a supported language: default language should be used
49 get 'projects', { }, 'HTTP_ACCEPT_LANGUAGE' => 'zz'
49 get '/projects', { }, 'HTTP_ACCEPT_LANGUAGE' => 'zz'
50 assert_response :success
50 assert_response :success
51 assert_select 'h2', :text => 'Projects'
51 assert_select 'h2', :text => 'Projects'
52 assert_select "html[lang=?]", "en"
52 assert_select "html[lang=?]", "en"
53 end
53 end
54
54
55 def test_token_based_access_should_not_start_session
55 def test_token_based_access_should_not_start_session
56 # issue of a private project
56 # issue of a private project
57 get 'issues/4.atom'
57 get '/issues/4.atom'
58 assert_response 302
58 assert_response 302
59
59
60 rss_key = User.find(2).rss_key
60 rss_key = User.find(2).rss_key
61 get "issues/4.atom?key=#{rss_key}"
61 get "/issues/4.atom?key=#{rss_key}"
62 assert_response 200
62 assert_response 200
63 assert_nil session[:user_id]
63 assert_nil session[:user_id]
64 end
64 end
65
65
66 def test_missing_template_should_respond_with_404
66 def test_missing_template_should_respond_with_404
67 get '/login.png'
67 get '/login.png'
68 assert_response 404
68 assert_response 404
69 end
69 end
70
70
71 def test_invalid_token_should_call_custom_handler
71 def test_invalid_token_should_call_custom_handler
72 ActionController::Base.allow_forgery_protection = true
72 ActionController::Base.allow_forgery_protection = true
73 post '/issues'
73 post '/issues'
74 assert_response 422
74 assert_response 422
75 assert_include "Invalid form authenticity token.", response.body
75 assert_include "Invalid form authenticity token.", response.body
76 ensure
76 ensure
77 ActionController::Base.allow_forgery_protection = false
77 ActionController::Base.allow_forgery_protection = false
78 end
78 end
79
79
80 def test_localization_should_be_set_correctly_on_invalid_token
80 def test_localization_should_be_set_correctly_on_invalid_token
81 ActionController::Base.allow_forgery_protection = true
81 ActionController::Base.allow_forgery_protection = true
82 Setting.default_language = 'en'
82 Setting.default_language = 'en'
83 post 'issues', { }, 'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
83 post '/issues', { }, 'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
84 assert_response 422
84 assert_response 422
85 assert_equal :fr, current_language
85 assert_equal :fr, current_language
86 assert_select "html[lang=?]", "fr"
86 assert_select "html[lang=?]", "fr"
87 ensure
87 ensure
88 ActionController::Base.allow_forgery_protection = false
88 ActionController::Base.allow_forgery_protection = false
89 end
89 end
90 end
90 end
@@ -1,216 +1,216
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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 IssuesTest < Redmine::IntegrationTest
20 class IssuesTest < Redmine::IntegrationTest
21 fixtures :projects,
21 fixtures :projects,
22 :users,
22 :users,
23 :roles,
23 :roles,
24 :members,
24 :members,
25 :member_roles,
25 :member_roles,
26 :trackers,
26 :trackers,
27 :projects_trackers,
27 :projects_trackers,
28 :enabled_modules,
28 :enabled_modules,
29 :issue_statuses,
29 :issue_statuses,
30 :issues,
30 :issues,
31 :enumerations,
31 :enumerations,
32 :custom_fields,
32 :custom_fields,
33 :custom_values,
33 :custom_values,
34 :custom_fields_trackers
34 :custom_fields_trackers
35
35
36 # create an issue
36 # create an issue
37 def test_add_issue
37 def test_add_issue
38 log_user('jsmith', 'jsmith')
38 log_user('jsmith', 'jsmith')
39 get 'projects/1/issues/new', :tracker_id => '1'
39 get '/projects/1/issues/new', :tracker_id => '1'
40 assert_response :success
40 assert_response :success
41 assert_template 'issues/new'
41 assert_template 'issues/new'
42
42
43 post 'projects/1/issues', :tracker_id => "1",
43 post '/projects/1/issues', :tracker_id => "1",
44 :issue => { :start_date => "2006-12-26",
44 :issue => { :start_date => "2006-12-26",
45 :priority_id => "4",
45 :priority_id => "4",
46 :subject => "new test issue",
46 :subject => "new test issue",
47 :category_id => "",
47 :category_id => "",
48 :description => "new issue",
48 :description => "new issue",
49 :done_ratio => "0",
49 :done_ratio => "0",
50 :due_date => "",
50 :due_date => "",
51 :assigned_to_id => "" },
51 :assigned_to_id => "" },
52 :custom_fields => {'2' => 'Value for field 2'}
52 :custom_fields => {'2' => 'Value for field 2'}
53 # find created issue
53 # find created issue
54 issue = Issue.find_by_subject("new test issue")
54 issue = Issue.find_by_subject("new test issue")
55 assert_kind_of Issue, issue
55 assert_kind_of Issue, issue
56
56
57 # check redirection
57 # check redirection
58 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
58 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
59 follow_redirect!
59 follow_redirect!
60 assert_equal issue, assigns(:issue)
60 assert_equal issue, assigns(:issue)
61
61
62 # check issue attributes
62 # check issue attributes
63 assert_equal 'jsmith', issue.author.login
63 assert_equal 'jsmith', issue.author.login
64 assert_equal 1, issue.project.id
64 assert_equal 1, issue.project.id
65 assert_equal 1, issue.status.id
65 assert_equal 1, issue.status.id
66 end
66 end
67
67
68 def test_create_issue_by_anonymous_without_permission_should_fail
68 def test_create_issue_by_anonymous_without_permission_should_fail
69 Role.anonymous.remove_permission! :add_issues
69 Role.anonymous.remove_permission! :add_issues
70
70
71 assert_no_difference 'Issue.count' do
71 assert_no_difference 'Issue.count' do
72 post 'projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
72 post '/projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
73 end
73 end
74 assert_response 302
74 assert_response 302
75 end
75 end
76
76
77 def test_create_issue_by_anonymous_with_custom_permission_should_succeed
77 def test_create_issue_by_anonymous_with_custom_permission_should_succeed
78 Role.anonymous.remove_permission! :add_issues
78 Role.anonymous.remove_permission! :add_issues
79 Member.create!(:project_id => 1, :principal => Group.anonymous, :role_ids => [3])
79 Member.create!(:project_id => 1, :principal => Group.anonymous, :role_ids => [3])
80
80
81 assert_difference 'Issue.count' do
81 assert_difference 'Issue.count' do
82 post 'projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
82 post '/projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
83 end
83 end
84 assert_response 302
84 assert_response 302
85 issue = Issue.order("id DESC").first
85 issue = Issue.order("id DESC").first
86 assert_equal User.anonymous, issue.author
86 assert_equal User.anonymous, issue.author
87 end
87 end
88
88
89 # add then remove 2 attachments to an issue
89 # add then remove 2 attachments to an issue
90 def test_issue_attachments
90 def test_issue_attachments
91 log_user('jsmith', 'jsmith')
91 log_user('jsmith', 'jsmith')
92 set_tmp_attachments_directory
92 set_tmp_attachments_directory
93
93
94 put 'issues/1',
94 put '/issues/1',
95 :notes => 'Some notes',
95 :notes => 'Some notes',
96 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
96 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
97 assert_redirected_to "/issues/1"
97 assert_redirected_to "/issues/1"
98
98
99 # make sure attachment was saved
99 # make sure attachment was saved
100 attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
100 attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
101 assert_kind_of Attachment, attachment
101 assert_kind_of Attachment, attachment
102 assert_equal Issue.find(1), attachment.container
102 assert_equal Issue.find(1), attachment.container
103 assert_equal 'This is an attachment', attachment.description
103 assert_equal 'This is an attachment', attachment.description
104 # verify the size of the attachment stored in db
104 # verify the size of the attachment stored in db
105 #assert_equal file_data_1.length, attachment.filesize
105 #assert_equal file_data_1.length, attachment.filesize
106 # verify that the attachment was written to disk
106 # verify that the attachment was written to disk
107 assert File.exist?(attachment.diskfile)
107 assert File.exist?(attachment.diskfile)
108
108
109 # remove the attachments
109 # remove the attachments
110 Issue.find(1).attachments.each(&:destroy)
110 Issue.find(1).attachments.each(&:destroy)
111 assert_equal 0, Issue.find(1).attachments.length
111 assert_equal 0, Issue.find(1).attachments.length
112 end
112 end
113
113
114 def test_other_formats_links_on_index
114 def test_other_formats_links_on_index
115 get '/projects/ecookbook/issues'
115 get '/projects/ecookbook/issues'
116
116
117 %w(Atom PDF CSV).each do |format|
117 %w(Atom PDF CSV).each do |format|
118 assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
118 assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
119 end
119 end
120 end
120 end
121
121
122 def test_other_formats_links_on_index_without_project_id_in_url
122 def test_other_formats_links_on_index_without_project_id_in_url
123 get '/issues', :project_id => 'ecookbook'
123 get '/issues', :project_id => 'ecookbook'
124
124
125 %w(Atom PDF CSV).each do |format|
125 %w(Atom PDF CSV).each do |format|
126 assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
126 assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
127 end
127 end
128 end
128 end
129
129
130 def test_pagination_links_on_index
130 def test_pagination_links_on_index
131 with_settings :per_page_options => '2' do
131 with_settings :per_page_options => '2' do
132 get '/projects/ecookbook/issues'
132 get '/projects/ecookbook/issues'
133
133
134 assert_select 'a[href=?]', '/projects/ecookbook/issues?page=2', :text => '2'
134 assert_select 'a[href=?]', '/projects/ecookbook/issues?page=2', :text => '2'
135 end
135 end
136 end
136 end
137
137
138 def test_pagination_links_on_index_without_project_id_in_url
138 def test_pagination_links_on_index_without_project_id_in_url
139 with_settings :per_page_options => '2' do
139 with_settings :per_page_options => '2' do
140 get '/issues', :project_id => 'ecookbook'
140 get '/issues', :project_id => 'ecookbook'
141
141
142 assert_select 'a[href=?]', '/projects/ecookbook/issues?page=2', :text => '2'
142 assert_select 'a[href=?]', '/projects/ecookbook/issues?page=2', :text => '2'
143 end
143 end
144 end
144 end
145
145
146 def test_issue_with_user_custom_field
146 def test_issue_with_user_custom_field
147 @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
147 @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
148 Role.anonymous.add_permission! :add_issues, :edit_issues
148 Role.anonymous.add_permission! :add_issues, :edit_issues
149 users = Project.find(1).users.uniq.sort
149 users = Project.find(1).users.uniq.sort
150 tester = users.first
150 tester = users.first
151
151
152 # Issue form
152 # Issue form
153 get '/projects/ecookbook/issues/new'
153 get '/projects/ecookbook/issues/new'
154 assert_response :success
154 assert_response :success
155 assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
155 assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
156 assert_select 'option', users.size + 1 # +1 for blank value
156 assert_select 'option', users.size + 1 # +1 for blank value
157 assert_select 'option[value=?]', tester.id.to_s, :text => tester.name
157 assert_select 'option[value=?]', tester.id.to_s, :text => tester.name
158 end
158 end
159
159
160 # Create issue
160 # Create issue
161 assert_difference 'Issue.count' do
161 assert_difference 'Issue.count' do
162 post '/projects/ecookbook/issues',
162 post '/projects/ecookbook/issues',
163 :issue => {
163 :issue => {
164 :tracker_id => '1',
164 :tracker_id => '1',
165 :priority_id => '4',
165 :priority_id => '4',
166 :subject => 'Issue with user custom field',
166 :subject => 'Issue with user custom field',
167 :custom_field_values => {@field.id.to_s => users.first.id.to_s}
167 :custom_field_values => {@field.id.to_s => users.first.id.to_s}
168 }
168 }
169 end
169 end
170 issue = Issue.order('id DESC').first
170 issue = Issue.order('id DESC').first
171 assert_response 302
171 assert_response 302
172
172
173 # Issue view
173 # Issue view
174 follow_redirect!
174 follow_redirect!
175 assert_select 'th:content(Tester:) + td', :text => tester.name
175 assert_select 'th:content(Tester:) + td', :text => tester.name
176 assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
176 assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
177 assert_select 'option', users.size + 1 # +1 for blank value
177 assert_select 'option', users.size + 1 # +1 for blank value
178 assert_select 'option[value=?][selected=selected]', tester.id.to_s, :text => tester.name
178 assert_select 'option[value=?][selected=selected]', tester.id.to_s, :text => tester.name
179 end
179 end
180
180
181 new_tester = users[1]
181 new_tester = users[1]
182 with_settings :default_language => 'en' do
182 with_settings :default_language => 'en' do
183 # Update issue
183 # Update issue
184 assert_difference 'Journal.count' do
184 assert_difference 'Journal.count' do
185 put "/issues/#{issue.id}",
185 put "/issues/#{issue.id}",
186 :notes => 'Updating custom field',
186 :notes => 'Updating custom field',
187 :issue => {
187 :issue => {
188 :custom_field_values => {@field.id.to_s => new_tester.id.to_s}
188 :custom_field_values => {@field.id.to_s => new_tester.id.to_s}
189 }
189 }
190 assert_redirected_to "/issues/#{issue.id}"
190 assert_redirected_to "/issues/#{issue.id}"
191 end
191 end
192 # Issue view
192 # Issue view
193 follow_redirect!
193 follow_redirect!
194 assert_select 'ul.details li', :text => "Tester changed from #{tester} to #{new_tester}"
194 assert_select 'ul.details li', :text => "Tester changed from #{tester} to #{new_tester}"
195 end
195 end
196 end
196 end
197
197
198 def test_update_using_invalid_http_verbs
198 def test_update_using_invalid_http_verbs
199 subject = 'Updated by an invalid http verb'
199 subject = 'Updated by an invalid http verb'
200
200
201 get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith')
201 get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith')
202 assert_response 404
202 assert_response 404
203 assert_not_equal subject, Issue.find(1).subject
203 assert_not_equal subject, Issue.find(1).subject
204
204
205 post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith')
205 post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith')
206 assert_response 404
206 assert_response 404
207 assert_not_equal subject, Issue.find(1).subject
207 assert_not_equal subject, Issue.find(1).subject
208 end
208 end
209
209
210 def test_get_watch_should_be_invalid
210 def test_get_watch_should_be_invalid
211 assert_no_difference 'Watcher.count' do
211 assert_no_difference 'Watcher.count' do
212 get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith')
212 get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith')
213 assert_response 404
213 assert_response 404
214 end
214 end
215 end
215 end
216 end
216 end
@@ -1,66 +1,66
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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 MenuManagerTest < Redmine::IntegrationTest
20 class MenuManagerTest < Redmine::IntegrationTest
21 include Redmine::I18n
21 include Redmine::I18n
22
22
23 fixtures :projects, :trackers, :issue_statuses, :issues,
23 fixtures :projects, :trackers, :issue_statuses, :issues,
24 :enumerations, :users, :issue_categories,
24 :enumerations, :users, :issue_categories,
25 :projects_trackers,
25 :projects_trackers,
26 :roles,
26 :roles,
27 :member_roles,
27 :member_roles,
28 :members,
28 :members,
29 :enabled_modules
29 :enabled_modules
30
30
31 def test_project_menu_with_specific_locale
31 def test_project_menu_with_specific_locale
32 get 'projects/ecookbook/issues', { }, 'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
32 get '/projects/ecookbook/issues', { }, 'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
33
33
34 assert_select 'div#main-menu' do
34 assert_select 'div#main-menu' do
35 assert_select 'li a.activity[href=?]', '/projects/ecookbook/activity', :text => ll('fr', :label_activity)
35 assert_select 'li a.activity[href=?]', '/projects/ecookbook/activity', :text => ll('fr', :label_activity)
36 assert_select 'li a.issues.selected[href=?]', '/projects/ecookbook/issues', :text => ll('fr', :label_issue_plural)
36 assert_select 'li a.issues.selected[href=?]', '/projects/ecookbook/issues', :text => ll('fr', :label_issue_plural)
37 end
37 end
38 end
38 end
39
39
40 def test_project_menu_with_additional_menu_items
40 def test_project_menu_with_additional_menu_items
41 Setting.default_language = 'en'
41 Setting.default_language = 'en'
42 assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do
42 assert_no_difference 'Redmine::MenuManager.items(:project_menu).size' do
43 Redmine::MenuManager.map :project_menu do |menu|
43 Redmine::MenuManager.map :project_menu do |menu|
44 menu.push :foo, { :controller => 'projects', :action => 'show' }, :caption => 'Foo'
44 menu.push :foo, { :controller => 'projects', :action => 'show' }, :caption => 'Foo'
45 menu.push :bar, { :controller => 'projects', :action => 'show' }, :before => :activity
45 menu.push :bar, { :controller => 'projects', :action => 'show' }, :before => :activity
46 menu.push :hello, { :controller => 'projects', :action => 'show' }, :caption => Proc.new {|p| p.name.upcase }, :after => :bar
46 menu.push :hello, { :controller => 'projects', :action => 'show' }, :caption => Proc.new {|p| p.name.upcase }, :after => :bar
47 end
47 end
48
48
49 get 'projects/ecookbook'
49 get '/projects/ecookbook'
50
50
51 assert_select 'div#main-menu ul' do
51 assert_select 'div#main-menu ul' do
52 assert_select 'li:last-child a.foo[href=?]', '/projects/ecookbook', :text => 'Foo'
52 assert_select 'li:last-child a.foo[href=?]', '/projects/ecookbook', :text => 'Foo'
53 assert_select 'li:nth-child(2) a.bar[href=?]', '/projects/ecookbook', :text => 'Bar'
53 assert_select 'li:nth-child(2) a.bar[href=?]', '/projects/ecookbook', :text => 'Bar'
54 assert_select 'li:nth-child(3) a.hello[href=?]', '/projects/ecookbook', :text => 'ECOOKBOOK'
54 assert_select 'li:nth-child(3) a.hello[href=?]', '/projects/ecookbook', :text => 'ECOOKBOOK'
55 assert_select 'li:nth-child(4) a', :text => 'Activity'
55 assert_select 'li:nth-child(4) a', :text => 'Activity'
56 end
56 end
57
57
58 # Remove the menu items
58 # Remove the menu items
59 Redmine::MenuManager.map :project_menu do |menu|
59 Redmine::MenuManager.map :project_menu do |menu|
60 menu.delete :foo
60 menu.delete :foo
61 menu.delete :bar
61 menu.delete :bar
62 menu.delete :hello
62 menu.delete :hello
63 end
63 end
64 end
64 end
65 end
65 end
66 end
66 end
@@ -1,51 +1,51
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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 ProjectsTest < Redmine::IntegrationTest
20 class ProjectsTest < Redmine::IntegrationTest
21 fixtures :projects, :users, :members, :enabled_modules
21 fixtures :projects, :users, :members, :enabled_modules
22
22
23 def test_archive_project
23 def test_archive_project
24 subproject = Project.find(1).children.first
24 subproject = Project.find(1).children.first
25 log_user("admin", "admin")
25 log_user("admin", "admin")
26 get "admin/projects"
26 get "/admin/projects"
27 assert_response :success
27 assert_response :success
28 assert_template "admin/projects"
28 assert_template "admin/projects"
29 post "projects/1/archive"
29 post "/projects/1/archive"
30 assert_redirected_to "/admin/projects"
30 assert_redirected_to "/admin/projects"
31 assert !Project.find(1).active?
31 assert !Project.find(1).active?
32
32
33 get 'projects/1'
33 get '/projects/1'
34 assert_response 403
34 assert_response 403
35 get "projects/#{subproject.id}"
35 get "/projects/#{subproject.id}"
36 assert_response 403
36 assert_response 403
37
37
38 post "projects/1/unarchive"
38 post "/projects/1/unarchive"
39 assert_redirected_to "/admin/projects"
39 assert_redirected_to "/admin/projects"
40 assert Project.find(1).active?
40 assert Project.find(1).active?
41 get "projects/1"
41 get "/projects/1"
42 assert_response :success
42 assert_response :success
43 end
43 end
44
44
45 def test_modules_should_not_allow_get
45 def test_modules_should_not_allow_get
46 assert_no_difference 'EnabledModule.count' do
46 assert_no_difference 'EnabledModule.count' do
47 get '/projects/1/modules', {:enabled_module_names => ['']}, credentials('jsmith')
47 get '/projects/1/modules', {:enabled_module_names => ['']}, credentials('jsmith')
48 assert_response 404
48 assert_response 404
49 end
49 end
50 end
50 end
51 end
51 end
General Comments 0
You need to be logged in to leave comments. Login now