Redmine 4.1.1

This commit is contained in:
Manuel Cillero 2020-11-22 21:20:06 +01:00
parent 33e7b881a5
commit 3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -25,6 +27,8 @@ class ProjectsControllerTest < Redmine::ControllerTest
:attachments, :custom_fields, :custom_values, :time_entries,
:wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
include Redmine::I18n
def setup
@request.session[:user_id] = nil
Setting.default_language = 'en'
@ -54,6 +58,198 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert_select 'feed>entry', :count => Project.visible(User.current).count
end
def test_index_with_project_filter_is_my_projects
@request.session[:user_id] = 2
get :index, :params => {
:f => ['id'],
:op => {'id' => '='},
:v => {'id' => ['mine']}
}
assert_response :success
assert_select 'div#projects-index ul' do
assert_select 'a.project', 3
assert_select 'a', :text => 'eCookbook'
assert_select 'a', :text => 'OnlineStore'
assert_select 'a', :text => 'Private child of eCookbook'
end
end
def test_index_with_subproject_filter
@request.session[:user_id] = 1
get :index, :params => {
:f => ['parent_id'],
:op => {'parent_id' => '='},
:v => {'parent_id' => ['1']}
}
assert_response :success
assert_select 'div#projects-index ul' do
assert_select 'a.project', 3
assert_select 'a', :text => 'eCookbook Subproject 1'
assert_select 'a', :text => 'eCookbook Subproject 2'
assert_select 'a', :text => 'Private child of eCookbook'
end
end
def test_index_as_list_should_format_column_value
get :index, :params => {
:c => ['name', 'status', 'short_description', 'homepage', 'parent_id', 'identifier', 'is_public', 'created_on', 'cf_3'],
:display_type => 'list'
}
assert_response :success
project = Project.find(1)
assert_select 'table.projects' do
assert_select 'tr[id=?]', 'project-1' do
assert_select 'td.name a[href=?]', '/projects/ecookbook', :text => 'eCookbook'
assert_select 'td.status', :text => 'active'
assert_select 'td.short_description', :text => 'Recipes management application'
assert_select 'td.homepage a.external', :text => 'http://ecookbook.somenet.foo/'
assert_select 'td.identifier', :text => 'ecookbook'
assert_select 'td.is_public', :text => 'Yes'
assert_select 'td.created_on', :text => format_time(project.created_on)
assert_select 'td.cf_3.list', :text => 'Stable'
end
assert_select 'tr[id=?]', 'project-4' do
assert_select 'td.parent_id a[href=?]', '/projects/ecookbook', :text => 'eCookbook'
end
end
end
def test_index_as_list_should_show_my_favourite_projects
@request.session[:user_id] = 1
get :index, :params => {
:display_type => 'list'
}
assert_response :success
assert_select 'tr[id=?] td.name span[class=?]', 'project-5', 'icon icon-user my-project'
end
def test_index_as_list_should_indent_projects
@request.session[:user_id] = 1
get :index, :params => {
:c => ['name', 'short_description'],
:sort => 'parent_id:desc,lft:desc',
:display_type => 'list'
}
assert_response :success
child_level1 = css_select('tr#project-5').map {|e| e.attr('class')}.first.split(' ')
child_level2 = css_select('tr#project-6').map {|e| e.attr('class')}.first.split(' ')
assert_include 'idnt', child_level1
assert_include 'idnt-1', child_level1
assert_include 'idnt', child_level2
assert_include 'idnt-2', child_level2
end
def test_index_with_default_query_setting
with_settings :project_list_defaults => {'column_names' => %w(name short_description status)} do
get :index, :params => {
:display_type => 'list'
}
assert_response :success
end
assert_equal ['Name', 'Description', 'Status'], columns_in_list
end
def test_index_as_board_should_not_include_csv_export
@request.session[:user_id] = 1
get :index
assert_response :success
assert_select 'p.other-formats a.csv', 0
assert_select '#csv-export-options', 0
end
def test_index_as_list_should_include_csv_export
@request.session[:user_id] = 1
get :index, :params => {
:display_type => 'list',
:f => ['parent_id'],
:op => {'parent_id' => '='},
:v => {'parent_id' => ['1']}
}
assert_response :success
# Assert CSV export link
assert_select 'p.other-formats a.csv'
# Assert export modal
assert_select '#csv-export-options' do
assert_select 'form[action=?][method=get]', '/projects.csv' do
# filter
assert_select 'input[name=?][value=?]', 'f[]', 'parent_id'
assert_select 'input[name=?][value=?]', 'op[parent_id]', '='
assert_select 'input[name=?][value=?]', 'v[parent_id][]', '1'
# columns
assert_select 'input[name=?][type=hidden][value=?]', 'c[]', 'name'
assert_select 'input[name=?][type=hidden][value=?]', 'c[]', 'identifier'
assert_select 'input[name=?][type=hidden][value=?]', 'c[]', 'short_description'
assert_select 'input[name=?][type=hidden]', 'c[]', 3
assert_select 'input[name=?][value=?]', 'c[]', 'all_inline'
end
end
end
def test_index_csv
with_settings :date_format => '%m/%d/%Y' do
get :index, :params => {:format => 'csv'}
assert_response :success
assert_equal 'text/csv', response.media_type
end
end
def test_index_sort_by_custom_field
@request.session[:user_id] = 1
cf = ProjectCustomField.find(3)
CustomValue.create!(:custom_field => cf, :customized => Project.find(2), :value => 'Beta')
get(
:index,
:params => {
:display_type => 'list',
:c => ['name', 'identifier', 'cf_3'],
:set_filter => 1,
:sort => "cf_#{cf.id}:asc"
}
)
assert_response :success
assert_equal(
['Beta', 'Stable'],
columns_values_in_list('cf_3').reject {|p| p.empty?}
)
end
def test_index_with_int_custom_field_total
@request.session[:user_id] = 1
field = ProjectCustomField.generate!(:field_format => 'int')
CustomValue.create!(:customized => Project.find(1), :custom_field => field, :value => '2')
CustomValue.create!(:customized => Project.find(2), :custom_field => field, :value => '7')
get(
:index,
:params => {
:display_type => 'list',
:t => ["cf_#{field.id}"]
}
)
assert_response :success
assert_select '.query-totals'
assert_select ".total-for-cf-#{field.id} span.value", :text => '9'
end
def test_autocomplete_js
get :autocomplete, :params => {
:format => 'js',
@ -64,6 +260,16 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert_equal 'text/javascript', response.content_type
end
def test_autocomplete_js_with_blank_search_term
get :autocomplete, :params => {
:format => 'js',
:q => ''
},
:xhr => true
assert_response :success
assert_equal 'text/javascript', response.content_type
end
test "#index by non-admin user with view_time_entries permission should show overall spent time link" do
@request.session[:user_id] = 3
get :index
@ -161,8 +367,8 @@ class ProjectsControllerTest < Redmine::ControllerTest
:identifier => "blog",
:is_public => 1,
:custom_field_values => {
'3' => 'Beta'
},
'3' => 'Beta'
},
:tracker_ids => ['1', '3'],
# an issue custom field that is not for all project
:issue_custom_field_ids => ['9'],
@ -195,10 +401,10 @@ class ProjectsControllerTest < Redmine::ControllerTest
:identifier => "blog",
:is_public => 1,
:custom_field_values => {
'3' => 'Beta'
},
'3' => 'Beta'
},
:parent_id => 1
}
}
assert_redirected_to '/projects/blog/settings'
@ -217,7 +423,7 @@ class ProjectsControllerTest < Redmine::ControllerTest
:project => {
:name => "blog",
:identifier => "blog"
},
},
:continue => 'Create and continue'
}
end
@ -235,11 +441,11 @@ class ProjectsControllerTest < Redmine::ControllerTest
:identifier => "blog",
:is_public => 1,
:custom_field_values => {
'3' => 'Beta'
},
'3' => 'Beta'
},
:tracker_ids => ['1', '3'],
:enabled_module_names => ['issue_tracking', 'news', 'repository']
}
}
@ -270,10 +476,10 @@ class ProjectsControllerTest < Redmine::ControllerTest
:identifier => "blog",
:is_public => 1,
:custom_field_values => {
'3' => 'Beta'
},
'3' => 'Beta'
},
:parent_id => 1
}
}
end
@ -293,10 +499,10 @@ class ProjectsControllerTest < Redmine::ControllerTest
:identifier => "blog",
:is_public => 1,
:custom_field_values => {
'3' => 'Beta'
},
'3' => 'Beta'
},
:parent_id => 1
}
}
assert_redirected_to '/projects/blog/settings'
@ -317,9 +523,9 @@ class ProjectsControllerTest < Redmine::ControllerTest
:identifier => "blog",
:is_public => 1,
:custom_field_values => {
'3' => 'Beta'
}
'3' => 'Beta'
}
}
}
end
@ -341,10 +547,10 @@ class ProjectsControllerTest < Redmine::ControllerTest
:identifier => "blog",
:is_public => 1,
:custom_field_values => {
'3' => 'Beta'
},
'3' => 'Beta'
},
:parent_id => 6
}
}
end
@ -365,7 +571,7 @@ class ProjectsControllerTest < Redmine::ControllerTest
:name => "blog1",
:identifier => "blog1",
:enabled_module_names => ["issue_tracking", "repository"]
}
}
end
@ -378,7 +584,7 @@ class ProjectsControllerTest < Redmine::ControllerTest
:name => "blog2",
:identifier => "blog2",
:enabled_module_names => ["issue_tracking", "repository"]
}
}
end
@ -398,7 +604,7 @@ class ProjectsControllerTest < Redmine::ControllerTest
:identifier => 'inherited',
:parent_id => parent.id,
:inherit_members => '1'
}
}
assert_response 302
@ -420,7 +626,7 @@ class ProjectsControllerTest < Redmine::ControllerTest
:name => "blog",
:identifier => "",
:enabled_module_names => %w(issue_tracking news)
}
}
end
@ -467,7 +673,7 @@ class ProjectsControllerTest < Redmine::ControllerTest
}
assert_response :success
assert_select 'li', :text => /Development status/
assert_select 'li[class=?]', 'cf_3', :text => /Development status/
end
def test_show_should_not_display_hidden_custom_fields
@ -514,9 +720,9 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert_response :success
end
def show_archived_project_should_be_denied
def test_show_archived_project_should_be_denied
project = Project.find_by_identifier('ecookbook')
project.archive!
project.archive
get :show, :params => {
:id => 'ecookbook'
@ -526,6 +732,18 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert_not_include project.name, response.body
end
def test_show_archived_project_should_show_unarchive_link_to_admins
@request.session[:user_id] = 1
project = Project.find_by_identifier('ecookbook')
project.archive
get :show, :params => {
:id => 'ecookbook'
}
assert_response 403
assert_select 'a', :text => "Unarchive"
end
def test_show_should_not_show_private_subprojects_that_are_not_visible
get :show, :params => {
:id => 'ecookbook'
@ -553,6 +771,18 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert_select 'table.issue-report td.total a', :text => %r{\A[1-9]\d*\z}
end
def test_show_should_spent_and_estimated_time
@request.session[:user_id] = 1
get :show, :params => {
:id => 'ecookbook'
}
assert_select 'div.spent_time.box>ul' do
assert_select '>li:nth-child(1)', :text => 'Estimated time: 203.50 hours'
assert_select '>li:nth-child(2)', :text => 'Spent time: 162.90 hours'
end
end
def test_settings
@request.session[:user_id] = 2 # manager
get :settings, :params => {
@ -589,22 +819,7 @@ class ProjectsControllerTest < Redmine::ControllerTest
get :settings, :params => {
:id => 1
}
assert_response 302
end
def test_setting_with_wiki_module_and_no_wiki
Project.find(1).wiki.destroy
Role.find(1).add_permission! :manage_wiki
@request.session[:user_id] = 2
get :settings, :params => {
:id => 1
}
assert_response :success
assert_select 'form[action=?]', '/projects/ecookbook/wiki' do
assert_select 'input[name=?]', 'wiki[start_page]'
end
assert_response 403
end
def test_settings_should_accept_version_status_filter
@ -646,6 +861,27 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert_select 'a#tab-versions[href=?]', '/projects/ecookbook/settings/versions?version_name=.1&version_status='
end
def test_settings_should_show_default_version_in_versions_tab
project = Project.find(1)
project.default_version_id = 3
project.save!
@request.session[:user_id] = 2
get :settings, :params => {
:id => 'ecookbook',
:tab => 'versions',
}
assert_response :success
assert_select 'table.versions tbody' do
# asserts that only one version is marked as default
assert_select 'td.tick span.icon-checked', 1
# asserts which version is marked as default
assert_select 'tr:first-child td.tick span.icon-checked', 1
end
end
def test_settings_should_show_locked_members
user = User.generate!
member = User.add_to_project(user, Project.find(1))
@ -684,6 +920,18 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert_select 'a#tab-activities'
end
def test_settings_should_not_display_custom_fields_not_visible_for_user
@request.session[:user_id] = 2
ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
get :settings, :params => {
:id => 'ecookbook'
}
assert_response :success
assert_select 'select#project_custom_field_values_3', :count => 0
end
def test_update
@request.session[:user_id] = 2 # manager
post :update, :params => {
@ -733,7 +981,7 @@ class ProjectsControllerTest < Redmine::ControllerTest
:name => 'Closed'
}
}
assert_response 302
assert_response 403
assert_equal 'eCookbook', Project.find(1).name
end
@ -753,15 +1001,17 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert_match /Successful update/, flash[:notice]
end
def test_modules
def test_update_modules
@request.session[:user_id] = 2
Project.find(1).enabled_module_names = ['issue_tracking', 'news']
post :modules, :params => {
post :update, :params => {
:id => 1,
:enabled_module_names => ['issue_tracking', 'repository', 'documents']
:project => {
:enabled_module_names => ['issue_tracking', 'repository', 'documents']
}
}
assert_redirected_to '/projects/ecookbook/settings/modules'
assert_redirected_to '/projects/ecookbook/settings'
assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort
end
@ -778,6 +1028,7 @@ class ProjectsControllerTest < Redmine::ControllerTest
end
def test_destroy_without_confirmation_should_show_confirmation_with_subprojects
set_tmp_attachments_directory
@request.session[:user_id] = 1 # admin
assert_no_difference 'Project.count' do
@ -793,6 +1044,7 @@ class ProjectsControllerTest < Redmine::ControllerTest
end
def test_destroy_with_confirmation_should_destroy_the_project_and_subprojects
set_tmp_attachments_directory
@request.session[:user_id] = 1 # admin
assert_difference 'Project.count', -5 do
@ -900,10 +1152,8 @@ class ProjectsControllerTest < Redmine::ControllerTest
:id => source.id
}
assert_response :success
assert_select 'fieldset#project_issue_custom_fields' do
assert_select 'input[type=checkbox][value=?][checked=checked]', field1.id.to_s
assert_select 'input[type=checkbox][value=?]:not([checked])', field2.id.to_s
end
assert_select 'input[type=hidden][name=?][value=?]', 'project[issue_custom_field_ids][]', field1.id.to_s
assert_select 'input[type=hidden][name=?][value=?]', 'project[issue_custom_field_ids][]', field2.id.to_s, 0
end
def test_post_copy_should_copy_requested_items
@ -918,8 +1168,8 @@ class ProjectsControllerTest < Redmine::ControllerTest
:identifier => 'unique-copy',
:tracker_ids => ['1', '2', '3', ''],
:enabled_module_names => %w(issue_tracking time_tracking)
},
},
:only => %w(issues versions)
}
end
@ -958,21 +1208,42 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert_select_error /Identifier cannot be blank/
end
def test_jump_without_project_id_should_redirect_to_active_tab
def test_bookmark_should_create_bookmark
@request.session[:user_id] = 3
post :bookmark, params: { id: 'ecookbook' }
assert_redirected_to controller: 'projects', action: 'show', id: 'ecookbook'
jb = Redmine::ProjectJumpBox.new(User.find(3))
assert jb.bookmark?(Project.find('ecookbook'))
refute jb.bookmark?(Project.find('onlinestore'))
end
def test_bookmark_should_delete_bookmark
@request.session[:user_id] = 3
jb = Redmine::ProjectJumpBox.new(User.find(3))
project = Project.find('ecookbook')
jb.bookmark_project project
delete :bookmark, params: { id: 'ecookbook' }
assert_redirected_to controller: 'projects', action: 'show', id: 'ecookbook'
jb = Redmine::ProjectJumpBox.new(User.find(3))
refute jb.bookmark?(Project.find('ecookbook'))
end
def test_index_jump_without_project_id_should_redirect_to_active_tab
get :index, :params => {
:jump => 'issues'
}
assert_redirected_to '/issues'
end
def test_jump_should_not_redirect_to_unknown_tab
def test_index_jump_should_not_redirect_to_unknown_tab
get :index, :params => {
:jump => 'foobar'
}
assert_response :success
end
def test_jump_should_redirect_to_active_tab
def test_show_jump_should_redirect_to_active_tab
get :show, :params => {
:id => 1,
:jump => 'issues'
@ -980,7 +1251,7 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert_redirected_to '/projects/ecookbook/issues'
end
def test_jump_should_not_redirect_to_inactive_tab
def test_show_jump_should_not_redirect_to_inactive_tab
get :show, :params => {
:id => 3,
:jump => 'documents'
@ -988,7 +1259,7 @@ class ProjectsControllerTest < Redmine::ControllerTest
assert_response :success
end
def test_jump_should_not_redirect_to_unknown_tab
def test_show_jump_should_not_redirect_to_unknown_tab
get :show, :params => {
:id => 3,
:jump => 'foobar'