@@ -1,16 +1,16 | |||
|
1 | 1 | # Redmine - project management software |
|
2 |
# Copyright (C) 2006-20 |
|
|
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. |
@@ -33,13 +33,13 class ProjectsControllerTest < ActionController::TestCase | |||
|
33 | 33 | @request.session[:user_id] = nil |
|
34 | 34 | Setting.default_language = 'en' |
|
35 | 35 | end |
|
36 | ||
|
36 | ||
|
37 | 37 | def test_index |
|
38 | 38 | get :index |
|
39 | 39 | assert_response :success |
|
40 | 40 | assert_template 'index' |
|
41 | 41 | assert_not_nil assigns(:projects) |
|
42 | ||
|
42 | ||
|
43 | 43 | assert_tag :ul, :child => {:tag => 'li', |
|
44 | 44 | :descendant => {:tag => 'a', :content => 'eCookbook'}, |
|
45 | 45 | :child => { :tag => 'ul', |
@@ -48,10 +48,10 class ProjectsControllerTest < ActionController::TestCase | |||
|
48 | 48 | } |
|
49 | 49 | } |
|
50 | 50 | } |
|
51 | ||
|
51 | ||
|
52 | 52 | assert_no_tag :a, :content => /Private child of eCookbook/ |
|
53 | 53 | end |
|
54 | ||
|
54 | ||
|
55 | 55 | def test_index_atom |
|
56 | 56 | get :index, :format => 'atom' |
|
57 | 57 | assert_response :success |
@@ -59,7 +59,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
59 | 59 | assert_select 'feed>title', :text => 'Redmine: Latest projects' |
|
60 | 60 | assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current)) |
|
61 | 61 | end |
|
62 | ||
|
62 | ||
|
63 | 63 | context "#index" do |
|
64 | 64 | context "by non-admin user with view_time_entries permission" do |
|
65 | 65 | setup do |
@@ -71,7 +71,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
71 | 71 | assert_tag :a, :attributes => {:href => '/time_entries'} |
|
72 | 72 | end |
|
73 | 73 | end |
|
74 | ||
|
74 | ||
|
75 | 75 | context "by non-admin user without view_time_entries permission" do |
|
76 | 76 | setup do |
|
77 | 77 | Role.find(2).remove_permission! :view_time_entries |
@@ -84,15 +84,15 class ProjectsControllerTest < ActionController::TestCase | |||
|
84 | 84 | assert_template 'index' |
|
85 | 85 | assert_no_tag :a, :attributes => {:href => '/time_entries'} |
|
86 | 86 | end |
|
87 |
end |
|
|
87 | end | |
|
88 | 88 | end |
|
89 | ||
|
89 | ||
|
90 | 90 | context "#new" do |
|
91 | 91 | context "by admin user" do |
|
92 | 92 | setup do |
|
93 | 93 | @request.session[:user_id] = 1 |
|
94 | 94 | end |
|
95 | ||
|
95 | ||
|
96 | 96 | should "accept get" do |
|
97 | 97 | get :new |
|
98 | 98 | assert_response :success |
@@ -121,7 +121,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
121 | 121 | Role.find(1).add_permission! :add_subprojects |
|
122 | 122 | @request.session[:user_id] = 2 |
|
123 | 123 | end |
|
124 | ||
|
124 | ||
|
125 | 125 | should "accept get" do |
|
126 | 126 | get :new, :parent_id => 'ecookbook' |
|
127 | 127 | assert_response :success |
@@ -134,7 +134,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
134 | 134 | :child => {:tag => 'option', :attributes => {:value => ''}} |
|
135 | 135 | end |
|
136 | 136 | end |
|
137 | ||
|
137 | ||
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | context "POST :create" do |
@@ -142,11 +142,11 class ProjectsControllerTest < ActionController::TestCase | |||
|
142 | 142 | setup do |
|
143 | 143 | @request.session[:user_id] = 1 |
|
144 | 144 | end |
|
145 | ||
|
145 | ||
|
146 | 146 | should "create a new project" do |
|
147 | 147 | post :create, |
|
148 | 148 | :project => { |
|
149 |
:name => "blog", |
|
|
149 | :name => "blog", | |
|
150 | 150 | :description => "weblog", |
|
151 | 151 | :homepage => 'http://weblog', |
|
152 | 152 | :identifier => "blog", |
@@ -158,11 +158,11 class ProjectsControllerTest < ActionController::TestCase | |||
|
158 | 158 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] |
|
159 | 159 | } |
|
160 | 160 | assert_redirected_to '/projects/blog/settings' |
|
161 | ||
|
161 | ||
|
162 | 162 | project = Project.find_by_name('blog') |
|
163 | 163 | assert_kind_of Project, project |
|
164 | 164 | assert project.active? |
|
165 |
assert_equal 'weblog', project.description |
|
|
165 | assert_equal 'weblog', project.description | |
|
166 | 166 | assert_equal 'http://weblog', project.homepage |
|
167 | 167 | assert_equal true, project.is_public? |
|
168 | 168 | assert_nil project.parent |
@@ -171,9 +171,9 class ProjectsControllerTest < ActionController::TestCase | |||
|
171 | 171 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort |
|
172 | 172 | assert project.issue_custom_fields.include?(IssueCustomField.find(9)) |
|
173 | 173 | end |
|
174 | ||
|
174 | ||
|
175 | 175 | should "create a new subproject" do |
|
176 |
post :create, :project => { :name => "blog", |
|
|
176 | post :create, :project => { :name => "blog", | |
|
177 | 177 | :description => "weblog", |
|
178 | 178 | :identifier => "blog", |
|
179 | 179 | :is_public => 1, |
@@ -181,21 +181,21 class ProjectsControllerTest < ActionController::TestCase | |||
|
181 | 181 | :parent_id => 1 |
|
182 | 182 | } |
|
183 | 183 | assert_redirected_to '/projects/blog/settings' |
|
184 | ||
|
184 | ||
|
185 | 185 | project = Project.find_by_name('blog') |
|
186 | 186 | assert_kind_of Project, project |
|
187 | 187 | assert_equal Project.find(1), project.parent |
|
188 | 188 | end |
|
189 | 189 | end |
|
190 | ||
|
190 | ||
|
191 | 191 | context "by non-admin user with add_project permission" do |
|
192 | 192 | setup do |
|
193 | 193 | Role.non_member.add_permission! :add_project |
|
194 | 194 | @request.session[:user_id] = 9 |
|
195 | 195 | end |
|
196 | ||
|
196 | ||
|
197 | 197 | should "accept create a Project" do |
|
198 |
post :create, :project => { :name => "blog", |
|
|
198 | post :create, :project => { :name => "blog", | |
|
199 | 199 | :description => "weblog", |
|
200 | 200 | :identifier => "blog", |
|
201 | 201 | :is_public => 1, |
@@ -203,24 +203,24 class ProjectsControllerTest < ActionController::TestCase | |||
|
203 | 203 | :tracker_ids => ['1', '3'], |
|
204 | 204 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] |
|
205 | 205 | } |
|
206 | ||
|
206 | ||
|
207 | 207 | assert_redirected_to '/projects/blog/settings' |
|
208 | ||
|
208 | ||
|
209 | 209 | project = Project.find_by_name('blog') |
|
210 | 210 | assert_kind_of Project, project |
|
211 |
assert_equal 'weblog', project.description |
|
|
211 | assert_equal 'weblog', project.description | |
|
212 | 212 | assert_equal true, project.is_public? |
|
213 | 213 | assert_equal [1, 3], project.trackers.map(&:id).sort |
|
214 | 214 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort |
|
215 | ||
|
215 | ||
|
216 | 216 | # User should be added as a project member |
|
217 | 217 | assert User.find(9).member_of?(project) |
|
218 | 218 | assert_equal 1, project.members.size |
|
219 | 219 | end |
|
220 | ||
|
220 | ||
|
221 | 221 | should "fail with parent_id" do |
|
222 | 222 | assert_no_difference 'Project.count' do |
|
223 |
post :create, :project => { :name => "blog", |
|
|
223 | post :create, :project => { :name => "blog", | |
|
224 | 224 | :description => "weblog", |
|
225 | 225 | :identifier => "blog", |
|
226 | 226 | :is_public => 1, |
@@ -234,16 +234,16 class ProjectsControllerTest < ActionController::TestCase | |||
|
234 | 234 | assert_not_nil project.errors.on(:parent_id) |
|
235 | 235 | end |
|
236 | 236 | end |
|
237 | ||
|
237 | ||
|
238 | 238 | context "by non-admin user with add_subprojects permission" do |
|
239 | 239 | setup do |
|
240 | 240 | Role.find(1).remove_permission! :add_project |
|
241 | 241 | Role.find(1).add_permission! :add_subprojects |
|
242 | 242 | @request.session[:user_id] = 2 |
|
243 | 243 | end |
|
244 | ||
|
244 | ||
|
245 | 245 | should "create a project with a parent_id" do |
|
246 |
post :create, :project => { :name => "blog", |
|
|
246 | post :create, :project => { :name => "blog", | |
|
247 | 247 | :description => "weblog", |
|
248 | 248 | :identifier => "blog", |
|
249 | 249 | :is_public => 1, |
@@ -253,10 +253,10 class ProjectsControllerTest < ActionController::TestCase | |||
|
253 | 253 | assert_redirected_to '/projects/blog/settings' |
|
254 | 254 | project = Project.find_by_name('blog') |
|
255 | 255 | end |
|
256 | ||
|
256 | ||
|
257 | 257 | should "fail without parent_id" do |
|
258 | 258 | assert_no_difference 'Project.count' do |
|
259 |
post :create, :project => { :name => "blog", |
|
|
259 | post :create, :project => { :name => "blog", | |
|
260 | 260 | :description => "weblog", |
|
261 | 261 | :identifier => "blog", |
|
262 | 262 | :is_public => 1, |
@@ -268,11 +268,11 class ProjectsControllerTest < ActionController::TestCase | |||
|
268 | 268 | assert_kind_of Project, project |
|
269 | 269 | assert_not_nil project.errors.on(:parent_id) |
|
270 | 270 | end |
|
271 | ||
|
271 | ||
|
272 | 272 | should "fail with unauthorized parent_id" do |
|
273 | 273 | assert !User.find(2).member_of?(Project.find(6)) |
|
274 | 274 | assert_no_difference 'Project.count' do |
|
275 |
post :create, :project => { :name => "blog", |
|
|
275 | post :create, :project => { :name => "blog", | |
|
276 | 276 | :description => "weblog", |
|
277 | 277 | :identifier => "blog", |
|
278 | 278 | :is_public => 1, |
@@ -287,7 +287,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
287 | 287 | end |
|
288 | 288 | end |
|
289 | 289 | end |
|
290 | ||
|
290 | ||
|
291 | 291 | def test_create_should_preserve_modules_on_validation_failure |
|
292 | 292 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
293 | 293 | @request.session[:user_id] = 1 |
@@ -303,13 +303,13 class ProjectsControllerTest < ActionController::TestCase | |||
|
303 | 303 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort |
|
304 | 304 | end |
|
305 | 305 | end |
|
306 | ||
|
306 | ||
|
307 | 307 | def test_create_should_not_accept_get |
|
308 | 308 | @request.session[:user_id] = 1 |
|
309 | 309 | get :create |
|
310 | 310 | assert_response :method_not_allowed |
|
311 | 311 | end |
|
312 | ||
|
312 | ||
|
313 | 313 | def test_show_by_id |
|
314 | 314 | get :show, :id => 1 |
|
315 | 315 | assert_response :success |
@@ -323,7 +323,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
323 | 323 | assert_template 'show' |
|
324 | 324 | assert_not_nil assigns(:project) |
|
325 | 325 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
326 | ||
|
326 | ||
|
327 | 327 | assert_tag 'li', :content => /Development status/ |
|
328 | 328 | end |
|
329 | 329 | |
@@ -333,10 +333,10 class ProjectsControllerTest < ActionController::TestCase | |||
|
333 | 333 | assert_response :success |
|
334 | 334 | assert_template 'show' |
|
335 | 335 | assert_not_nil assigns(:project) |
|
336 | ||
|
336 | ||
|
337 | 337 | assert_no_tag 'li', :content => /Development status/ |
|
338 | 338 | end |
|
339 | ||
|
339 | ||
|
340 | 340 | def test_show_should_not_fail_when_custom_values_are_nil |
|
341 | 341 | project = Project.find_by_identifier('ecookbook') |
|
342 | 342 | project.custom_values.first.update_attribute(:value, nil) |
@@ -346,17 +346,17 class ProjectsControllerTest < ActionController::TestCase | |||
|
346 | 346 | assert_not_nil assigns(:project) |
|
347 | 347 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
348 | 348 | end |
|
349 | ||
|
349 | ||
|
350 | 350 | def show_archived_project_should_be_denied |
|
351 | 351 | project = Project.find_by_identifier('ecookbook') |
|
352 | 352 | project.archive! |
|
353 | ||
|
353 | ||
|
354 | 354 | get :show, :id => 'ecookbook' |
|
355 | 355 | assert_response 403 |
|
356 | 356 | assert_nil assigns(:project) |
|
357 | 357 | assert_tag :tag => 'p', :content => /archived/ |
|
358 | 358 | end |
|
359 | ||
|
359 | ||
|
360 | 360 | def test_private_subprojects_hidden |
|
361 | 361 | get :show, :id => 'ecookbook' |
|
362 | 362 | assert_response :success |
@@ -371,14 +371,14 class ProjectsControllerTest < ActionController::TestCase | |||
|
371 | 371 | assert_template 'show' |
|
372 | 372 | assert_tag :tag => 'a', :content => /Private child/ |
|
373 | 373 | end |
|
374 | ||
|
374 | ||
|
375 | 375 | def test_settings |
|
376 | 376 | @request.session[:user_id] = 2 # manager |
|
377 | 377 | get :settings, :id => 1 |
|
378 | 378 | assert_response :success |
|
379 | 379 | assert_template 'settings' |
|
380 | 380 | end |
|
381 | ||
|
381 | ||
|
382 | 382 | def test_update |
|
383 | 383 | @request.session[:user_id] = 2 # manager |
|
384 | 384 | post :update, :id => 1, :project => {:name => 'Test changed name', |
@@ -391,7 +391,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
391 | 391 | def test_modules |
|
392 | 392 | @request.session[:user_id] = 2 |
|
393 | 393 | Project.find(1).enabled_module_names = ['issue_tracking', 'news'] |
|
394 | ||
|
394 | ||
|
395 | 395 | post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] |
|
396 | 396 | assert_redirected_to '/projects/ecookbook/settings/modules' |
|
397 | 397 | assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort |
@@ -402,7 +402,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
402 | 402 | get :modules, :id => 1 |
|
403 | 403 | assert_response :method_not_allowed |
|
404 | 404 | end |
|
405 | ||
|
405 | ||
|
406 | 406 | def test_get_destroy |
|
407 | 407 | @request.session[:user_id] = 1 # admin |
|
408 | 408 | get :destroy, :id => 1 |
@@ -417,14 +417,14 class ProjectsControllerTest < ActionController::TestCase | |||
|
417 | 417 | assert_redirected_to '/admin/projects' |
|
418 | 418 | assert_nil Project.find_by_id(1) |
|
419 | 419 | end |
|
420 | ||
|
420 | ||
|
421 | 421 | def test_archive |
|
422 | 422 | @request.session[:user_id] = 1 # admin |
|
423 | 423 | post :archive, :id => 1 |
|
424 | 424 | assert_redirected_to '/admin/projects' |
|
425 | 425 | assert !Project.find(1).active? |
|
426 | 426 | end |
|
427 | ||
|
427 | ||
|
428 | 428 | def test_unarchive |
|
429 | 429 | @request.session[:user_id] = 1 # admin |
|
430 | 430 | Project.find(1).archive |
@@ -432,7 +432,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
432 | 432 | assert_redirected_to '/admin/projects' |
|
433 | 433 | assert Project.find(1).active? |
|
434 | 434 | end |
|
435 | ||
|
435 | ||
|
436 | 436 | def test_project_breadcrumbs_should_be_limited_to_3_ancestors |
|
437 | 437 | CustomField.delete_all |
|
438 | 438 | parent = nil |
@@ -443,7 +443,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
443 | 443 | assert_tag :h1, :parent => { :attributes => {:id => 'header'}}, |
|
444 | 444 | :children => { :count => [i, 3].min, |
|
445 | 445 | :only => { :tag => 'a' } } |
|
446 | ||
|
446 | ||
|
447 | 447 | parent = p |
|
448 | 448 | end |
|
449 | 449 | end |
@@ -456,7 +456,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
456 | 456 | assert assigns(:project) |
|
457 | 457 | assert_equal Project.find(1).description, assigns(:project).description |
|
458 | 458 | assert_nil assigns(:project).id |
|
459 | ||
|
459 | ||
|
460 | 460 | assert_tag :tag => 'input', |
|
461 | 461 | :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'} |
|
462 | 462 | end |
@@ -467,11 +467,11 class ProjectsControllerTest < ActionController::TestCase | |||
|
467 | 467 | assert_response :redirect |
|
468 | 468 | assert_redirected_to :controller => 'admin', :action => 'projects' |
|
469 | 469 | end |
|
470 | ||
|
470 | ||
|
471 | 471 | def test_post_copy_should_copy_requested_items |
|
472 | 472 | @request.session[:user_id] = 1 # admin |
|
473 | 473 | CustomField.delete_all |
|
474 | ||
|
474 | ||
|
475 | 475 | assert_difference 'Project.count' do |
|
476 | 476 | post :copy, :id => 1, |
|
477 | 477 | :project => { |
@@ -485,7 +485,7 class ProjectsControllerTest < ActionController::TestCase | |||
|
485 | 485 | project = Project.find('unique-copy') |
|
486 | 486 | source = Project.find(1) |
|
487 | 487 | assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort |
|
488 | ||
|
488 | ||
|
489 | 489 | assert_equal source.versions.count, project.versions.count, "All versions were not copied" |
|
490 | 490 | # issues assigned to a closed version won't be copied |
|
491 | 491 | assert_equal source.issues.select {|i| i.fixed_version.nil? || i.fixed_version.open?}.size, |
@@ -504,13 +504,13 class ProjectsControllerTest < ActionController::TestCase | |||
|
504 | 504 | get :show, :id => 1, :jump => 'issues' |
|
505 | 505 | assert_redirected_to '/projects/ecookbook/issues' |
|
506 | 506 | end |
|
507 | ||
|
507 | ||
|
508 | 508 | def test_jump_should_not_redirect_to_inactive_tab |
|
509 | 509 | get :show, :id => 3, :jump => 'documents' |
|
510 | 510 | assert_response :success |
|
511 | 511 | assert_template 'show' |
|
512 | 512 | end |
|
513 | ||
|
513 | ||
|
514 | 514 | def test_jump_should_not_redirect_to_unknown_tab |
|
515 | 515 | get :show, :id => 3, :jump => 'foobar' |
|
516 | 516 | assert_response :success |
@@ -526,13 +526,13 class ProjectsControllerTest < ActionController::TestCase | |||
|
526 | 526 | end |
|
527 | 527 | # Don't use this hook now |
|
528 | 528 | Redmine::Hook.clear_listeners |
|
529 | ||
|
529 | ||
|
530 | 530 | def test_hook_response |
|
531 | 531 | Redmine::Hook.add_listener(ProjectBasedTemplate) |
|
532 | 532 | get :show, :id => 1 |
|
533 | 533 | assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'}, |
|
534 | 534 | :parent => {:tag => 'head'} |
|
535 | ||
|
535 | ||
|
536 | 536 | Redmine::Hook.clear_listeners |
|
537 | 537 | end |
|
538 | 538 | end |
General Comments 0
You need to be logged in to leave comments.
Login now