2019-03-16 15:03:47 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2011-04-01 13:44:58 +00:00
|
|
|
# Redmine - project management software
|
2023-01-01 06:19:35 +00:00
|
|
|
# Copyright (C) 2006-2023 Jean-Philippe Lang
|
2008-06-09 18:40:59 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-08-27 02:10:59 +00:00
|
|
|
#
|
2008-06-09 18:40:59 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
2011-08-27 02:10:59 +00:00
|
|
|
#
|
2008-06-09 18:40:59 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
2010-12-12 23:24:34 +00:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2006-12-26 20:14:03 +00:00
|
|
|
|
2014-11-30 15:16:43 +00:00
|
|
|
class IssuesTest < Redmine::IntegrationTest
|
2011-08-27 02:10:59 +00:00
|
|
|
fixtures :projects,
|
2015-01-17 14:14:12 +00:00
|
|
|
:users, :email_addresses,
|
2008-07-04 17:58:14 +00:00
|
|
|
:roles,
|
|
|
|
|
:members,
|
2012-11-01 22:47:59 +00:00
|
|
|
:member_roles,
|
2008-01-20 21:29:51 +00:00
|
|
|
:trackers,
|
|
|
|
|
:projects_trackers,
|
2008-07-04 17:58:14 +00:00
|
|
|
:enabled_modules,
|
2008-01-20 21:29:51 +00:00
|
|
|
:issue_statuses,
|
|
|
|
|
:issues,
|
|
|
|
|
:enumerations,
|
|
|
|
|
:custom_fields,
|
|
|
|
|
:custom_values,
|
2021-06-30 12:23:04 +00:00
|
|
|
:custom_fields_trackers, :custom_fields_projects,
|
2022-10-29 08:24:03 +00:00
|
|
|
:attachments,
|
|
|
|
|
:issue_categories
|
2006-12-26 20:14:03 +00:00
|
|
|
|
|
|
|
|
# create an issue
|
|
|
|
|
def test_add_issue
|
|
|
|
|
log_user('jsmith', 'jsmith')
|
2015-10-30 19:45:32 +00:00
|
|
|
|
|
|
|
|
get '/projects/ecookbook/issues/new'
|
2006-12-26 20:14:03 +00:00
|
|
|
assert_response :success
|
2011-08-27 02:10:59 +00:00
|
|
|
|
2015-10-30 19:44:33 +00:00
|
|
|
issue = new_record(Issue) do
|
2019-11-24 05:43:46 +00:00
|
|
|
post(
|
|
|
|
|
'/projects/ecookbook/issues',
|
|
|
|
|
:params => {
|
2017-06-01 18:17:27 +00:00
|
|
|
:issue => {
|
|
|
|
|
:tracker_id => "1",
|
|
|
|
|
:start_date => "2006-12-26",
|
|
|
|
|
:priority_id => "4",
|
|
|
|
|
:subject => "new test issue",
|
|
|
|
|
:category_id => "",
|
|
|
|
|
:description => "new issue",
|
|
|
|
|
:done_ratio => "0",
|
|
|
|
|
:due_date => "",
|
|
|
|
|
:assigned_to_id => "",
|
|
|
|
|
:custom_field_values => {'2' => 'Value for field 2'}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-24 05:43:46 +00:00
|
|
|
)
|
2015-10-30 19:44:33 +00:00
|
|
|
end
|
2006-12-26 20:14:03 +00:00
|
|
|
# check redirection
|
2009-02-21 11:04:50 +00:00
|
|
|
assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
|
2006-12-26 20:14:03 +00:00
|
|
|
follow_redirect!
|
|
|
|
|
|
2011-08-27 02:10:59 +00:00
|
|
|
# check issue attributes
|
2006-12-26 20:14:03 +00:00
|
|
|
assert_equal 'jsmith', issue.author.login
|
|
|
|
|
assert_equal 1, issue.project.id
|
|
|
|
|
assert_equal 1, issue.status.id
|
|
|
|
|
end
|
|
|
|
|
|
2014-09-28 14:51:08 +00:00
|
|
|
def test_create_issue_by_anonymous_without_permission_should_fail
|
|
|
|
|
Role.anonymous.remove_permission! :add_issues
|
|
|
|
|
|
|
|
|
|
assert_no_difference 'Issue.count' do
|
2019-11-24 05:43:46 +00:00
|
|
|
post(
|
|
|
|
|
'/projects/1/issues',
|
|
|
|
|
:params => {
|
2017-06-01 18:17:27 +00:00
|
|
|
:issue => {
|
|
|
|
|
:tracker_id => "1",
|
|
|
|
|
:subject => "new test issue"
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-24 05:43:46 +00:00
|
|
|
)
|
2014-09-28 14:51:08 +00:00
|
|
|
end
|
|
|
|
|
assert_response 302
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_issue_by_anonymous_with_custom_permission_should_succeed
|
|
|
|
|
Role.anonymous.remove_permission! :add_issues
|
|
|
|
|
Member.create!(:project_id => 1, :principal => Group.anonymous, :role_ids => [3])
|
|
|
|
|
|
2015-10-30 19:44:33 +00:00
|
|
|
issue = new_record(Issue) do
|
2019-11-24 05:43:46 +00:00
|
|
|
post(
|
|
|
|
|
'/projects/1/issues',
|
|
|
|
|
:params => {
|
2017-06-01 18:17:27 +00:00
|
|
|
:issue => {
|
|
|
|
|
:tracker_id => "1",
|
|
|
|
|
:subject => "new test issue"
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-24 05:43:46 +00:00
|
|
|
)
|
2015-10-30 19:44:33 +00:00
|
|
|
assert_response 302
|
2014-09-28 14:51:08 +00:00
|
|
|
end
|
|
|
|
|
assert_equal User.anonymous, issue.author
|
|
|
|
|
end
|
|
|
|
|
|
2006-12-26 20:14:03 +00:00
|
|
|
# add then remove 2 attachments to an issue
|
2011-04-02 08:01:06 +00:00
|
|
|
def test_issue_attachments
|
2006-12-26 20:14:03 +00:00
|
|
|
log_user('jsmith', 'jsmith')
|
2008-06-09 18:40:59 +00:00
|
|
|
set_tmp_attachments_directory
|
2015-10-30 19:44:33 +00:00
|
|
|
attachment = new_record(Attachment) do
|
2019-11-24 05:43:46 +00:00
|
|
|
put(
|
|
|
|
|
'/issues/1',
|
|
|
|
|
:params => {
|
2017-06-01 18:17:27 +00:00
|
|
|
:issue => {:notes => 'Some notes'},
|
2019-10-07 13:07:12 +00:00
|
|
|
:attachments => {
|
2019-11-24 05:43:46 +00:00
|
|
|
'1' => {
|
|
|
|
|
'file' => uploaded_test_file('testfile.txt', 'text/plain'),
|
|
|
|
|
'description' => 'This is an attachment'
|
|
|
|
|
}
|
2019-10-07 13:07:12 +00:00
|
|
|
}
|
2017-06-01 18:17:27 +00:00
|
|
|
}
|
2019-11-24 05:43:46 +00:00
|
|
|
)
|
2015-10-30 19:44:33 +00:00
|
|
|
assert_redirected_to "/issues/1"
|
|
|
|
|
end
|
2006-12-26 20:14:03 +00:00
|
|
|
assert_equal Issue.find(1), attachment.container
|
2015-10-30 19:44:33 +00:00
|
|
|
assert_equal 'testfile.txt', attachment.filename
|
2008-02-29 19:46:58 +00:00
|
|
|
assert_equal 'This is an attachment', attachment.description
|
2006-12-26 20:14:03 +00:00
|
|
|
# verify the size of the attachment stored in db
|
2019-10-07 13:07:00 +00:00
|
|
|
assert_equal 59, attachment.filesize
|
2006-12-26 20:14:03 +00:00
|
|
|
# verify that the attachment was written to disk
|
|
|
|
|
assert File.exist?(attachment.diskfile)
|
|
|
|
|
# remove the attachments
|
|
|
|
|
Issue.find(1).attachments.each(&:destroy)
|
|
|
|
|
assert_equal 0, Issue.find(1).attachments.length
|
|
|
|
|
end
|
2011-08-27 02:10:59 +00:00
|
|
|
|
2016-10-01 08:53:31 +00:00
|
|
|
def test_next_and_previous_links_should_be_displayed_after_query_grouped_and_sorted_by_version
|
|
|
|
|
with_settings :default_language => 'en' do
|
2016-10-01 14:34:38 +00:00
|
|
|
get '/projects/ecookbook/issues?set_filter=1&group_by=fixed_version&sort=priority:desc,fixed_version,id'
|
2016-10-01 08:53:31 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_select 'td.id', :text => '5'
|
2019-06-06 14:53:23 +00:00
|
|
|
|
2016-10-01 08:53:31 +00:00
|
|
|
get '/issues/5'
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_select '.next-prev-links .position', :text => '5 of 6'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2016-10-01 08:13:40 +00:00
|
|
|
def test_next_and_previous_links_should_be_displayed_after_filter
|
|
|
|
|
with_settings :default_language => 'en' do
|
|
|
|
|
get '/projects/ecookbook/issues?set_filter=1&tracker_id=1'
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_select 'td.id', :text => '5'
|
2019-06-06 14:53:23 +00:00
|
|
|
|
2016-10-01 08:13:40 +00:00
|
|
|
get '/issues/5'
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_select '.next-prev-links .position', :text => '3 of 5'
|
2017-04-04 17:49:40 +00:00
|
|
|
assert_select '.next-prev-links .position a[href^=?]', '/projects/ecookbook/issues?'
|
2016-10-01 08:13:40 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_next_and_previous_links_should_be_displayed_after_saved_query
|
2019-11-23 09:04:15 +00:00
|
|
|
query =
|
|
|
|
|
IssueQuery.create!(
|
|
|
|
|
:name => 'Calendar Query',
|
|
|
|
|
:visibility => IssueQuery::VISIBILITY_PUBLIC,
|
|
|
|
|
:filters => {'tracker_id' => {:operator => '=', :values => ['1']}}
|
|
|
|
|
)
|
2016-10-01 08:13:40 +00:00
|
|
|
with_settings :default_language => 'en' do
|
|
|
|
|
get "/projects/ecookbook/issues?set_filter=1&query_id=#{query.id}"
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_select 'td.id', :text => '5'
|
2019-06-06 14:53:23 +00:00
|
|
|
|
2016-10-01 08:13:40 +00:00
|
|
|
get '/issues/5'
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_select '.next-prev-links .position', :text => '6 of 8'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2011-12-01 18:02:21 +00:00
|
|
|
def test_other_formats_links_on_index
|
2009-03-06 22:46:49 +00:00
|
|
|
get '/projects/ecookbook/issues'
|
2011-08-27 02:10:59 +00:00
|
|
|
|
2009-03-06 22:46:49 +00:00
|
|
|
%w(Atom PDF CSV).each do |format|
|
2014-11-22 09:38:21 +00:00
|
|
|
assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
|
2009-03-06 22:46:49 +00:00
|
|
|
end
|
|
|
|
|
end
|
2011-08-27 02:10:59 +00:00
|
|
|
|
2011-12-01 18:02:21 +00:00
|
|
|
def test_other_formats_links_on_index_without_project_id_in_url
|
2019-11-24 05:43:46 +00:00
|
|
|
get('/issues', :params => {:project_id => 'ecookbook'})
|
2009-03-06 22:46:49 +00:00
|
|
|
%w(Atom PDF CSV).each do |format|
|
2016-07-10 19:18:12 +00:00
|
|
|
assert_select 'a[rel=nofollow][href=?]', "/issues.#{format.downcase}?project_id=ecookbook", :text => format
|
2009-03-06 22:46:49 +00:00
|
|
|
end
|
|
|
|
|
end
|
2011-08-27 02:10:59 +00:00
|
|
|
|
2011-12-01 18:02:21 +00:00
|
|
|
def test_pagination_links_on_index
|
2014-10-22 17:37:16 +00:00
|
|
|
with_settings :per_page_options => '2' do
|
|
|
|
|
get '/projects/ecookbook/issues'
|
2011-08-27 02:10:59 +00:00
|
|
|
|
2014-11-22 09:38:21 +00:00
|
|
|
assert_select 'a[href=?]', '/projects/ecookbook/issues?page=2', :text => '2'
|
2014-10-22 17:37:16 +00:00
|
|
|
end
|
2009-03-06 22:46:49 +00:00
|
|
|
end
|
2011-08-27 02:10:59 +00:00
|
|
|
|
2016-07-10 16:47:49 +00:00
|
|
|
def test_pagination_links_should_preserve_query_parameters
|
2014-10-22 17:37:16 +00:00
|
|
|
with_settings :per_page_options => '2' do
|
2016-07-10 16:47:49 +00:00
|
|
|
get '/projects/ecookbook/issues?foo=bar'
|
|
|
|
|
|
|
|
|
|
assert_select 'a[href=?]', '/projects/ecookbook/issues?foo=bar&page=2', :text => '2'
|
2014-10-22 17:37:16 +00:00
|
|
|
end
|
2009-03-06 22:46:49 +00:00
|
|
|
end
|
2011-08-27 02:10:59 +00:00
|
|
|
|
2016-07-10 16:58:43 +00:00
|
|
|
def test_pagination_links_should_not_use_params_as_url_options
|
|
|
|
|
with_settings :per_page_options => '2' do
|
|
|
|
|
get '/projects/ecookbook/issues?host=foo'
|
|
|
|
|
|
|
|
|
|
assert_select 'a[href=?]', '/projects/ecookbook/issues?host=foo&page=2', :text => '2'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_sort_links_on_index
|
|
|
|
|
get '/projects/ecookbook/issues'
|
|
|
|
|
|
|
|
|
|
assert_select 'a[href=?]', '/projects/ecookbook/issues?sort=subject%2Cid%3Adesc', :text => 'Subject'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_sort_links_should_preserve_query_parameters
|
|
|
|
|
get '/projects/ecookbook/issues?foo=bar'
|
|
|
|
|
|
|
|
|
|
assert_select 'a[href=?]', '/projects/ecookbook/issues?foo=bar&sort=subject%2Cid%3Adesc', :text => 'Subject'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_sort_links_should_not_use_params_as_url_options
|
|
|
|
|
get '/projects/ecookbook/issues?host=foo'
|
|
|
|
|
|
|
|
|
|
assert_select 'a[href=?]', '/projects/ecookbook/issues?host=foo&sort=subject%2Cid%3Adesc', :text => 'Subject'
|
|
|
|
|
end
|
|
|
|
|
|
2011-04-01 13:44:58 +00:00
|
|
|
def test_issue_with_user_custom_field
|
|
|
|
|
@field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
|
|
|
|
|
Role.anonymous.add_permission! :add_issues, :edit_issues
|
2016-07-14 07:15:13 +00:00
|
|
|
users = Project.find(1).users.sort
|
2011-04-01 13:44:58 +00:00
|
|
|
tester = users.first
|
2011-08-27 02:10:59 +00:00
|
|
|
|
2011-04-01 13:44:58 +00:00
|
|
|
# Issue form
|
|
|
|
|
get '/projects/ecookbook/issues/new'
|
|
|
|
|
assert_response :success
|
2014-11-22 09:38:21 +00:00
|
|
|
assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
|
|
|
|
|
assert_select 'option', users.size + 1 # +1 for blank value
|
|
|
|
|
assert_select 'option[value=?]', tester.id.to_s, :text => tester.name
|
|
|
|
|
end
|
2011-08-27 02:10:59 +00:00
|
|
|
|
2011-04-01 13:44:58 +00:00
|
|
|
# Create issue
|
2015-10-30 19:44:33 +00:00
|
|
|
issue = new_record(Issue) do
|
2019-11-24 05:43:46 +00:00
|
|
|
post(
|
|
|
|
|
'/projects/ecookbook/issues',
|
|
|
|
|
:params => {
|
2017-06-01 18:17:27 +00:00
|
|
|
:issue => {
|
|
|
|
|
:tracker_id => '1',
|
|
|
|
|
:priority_id => '4',
|
|
|
|
|
:subject => 'Issue with user custom field',
|
|
|
|
|
:custom_field_values => {@field.id.to_s => users.first.id.to_s}
|
|
|
|
|
}
|
2011-04-01 13:44:58 +00:00
|
|
|
}
|
2019-11-24 05:43:46 +00:00
|
|
|
)
|
2015-10-30 19:44:33 +00:00
|
|
|
assert_response 302
|
2011-04-01 13:44:58 +00:00
|
|
|
end
|
2011-08-27 02:10:59 +00:00
|
|
|
|
2011-04-01 13:44:58 +00:00
|
|
|
# Issue view
|
|
|
|
|
follow_redirect!
|
2015-11-08 11:50:36 +00:00
|
|
|
assert_select ".cf_#{@field.id}" do
|
|
|
|
|
assert_select '.label', :text => 'Tester:'
|
|
|
|
|
assert_select '.value', :text => tester.name
|
|
|
|
|
end
|
2014-11-22 09:38:21 +00:00
|
|
|
assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
|
|
|
|
|
assert_select 'option', users.size + 1 # +1 for blank value
|
|
|
|
|
assert_select 'option[value=?][selected=selected]', tester.id.to_s, :text => tester.name
|
|
|
|
|
end
|
2011-08-27 02:10:59 +00:00
|
|
|
|
2011-04-01 13:44:58 +00:00
|
|
|
new_tester = users[1]
|
2014-11-25 11:22:23 +00:00
|
|
|
with_settings :default_language => 'en' do
|
|
|
|
|
# Update issue
|
|
|
|
|
assert_difference 'Journal.count' do
|
2019-11-24 05:43:46 +00:00
|
|
|
put(
|
|
|
|
|
"/issues/#{issue.id}",
|
|
|
|
|
:params => {
|
2014-11-25 11:22:23 +00:00
|
|
|
:issue => {
|
2017-06-01 18:17:27 +00:00
|
|
|
:notes => 'Updating custom field',
|
|
|
|
|
:custom_field_values => {@field.id.to_s => new_tester.id.to_s}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-24 05:43:46 +00:00
|
|
|
)
|
2014-11-25 11:22:23 +00:00
|
|
|
assert_redirected_to "/issues/#{issue.id}"
|
|
|
|
|
end
|
|
|
|
|
# Issue view
|
|
|
|
|
follow_redirect!
|
|
|
|
|
assert_select 'ul.details li', :text => "Tester changed from #{tester} to #{new_tester}"
|
2011-04-01 13:44:58 +00:00
|
|
|
end
|
|
|
|
|
end
|
2012-03-03 15:09:20 +00:00
|
|
|
|
|
|
|
|
def test_update_using_invalid_http_verbs
|
2017-06-01 18:17:27 +00:00
|
|
|
log_user('jsmith', 'jsmith')
|
2012-03-03 15:09:20 +00:00
|
|
|
subject = 'Updated by an invalid http verb'
|
|
|
|
|
|
2017-06-01 18:17:27 +00:00
|
|
|
get '/issues/update/1', :params => {:issue => {:subject => subject}}
|
2012-03-03 15:09:20 +00:00
|
|
|
assert_response 404
|
|
|
|
|
assert_not_equal subject, Issue.find(1).subject
|
|
|
|
|
|
2017-06-01 18:17:27 +00:00
|
|
|
post '/issues/1', :params => {:issue => {:subject => subject}}
|
2012-04-25 17:17:49 +00:00
|
|
|
assert_response 404
|
2012-03-03 15:09:20 +00:00
|
|
|
assert_not_equal subject, Issue.find(1).subject
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_get_watch_should_be_invalid
|
2017-06-01 18:17:27 +00:00
|
|
|
log_user('jsmith', 'jsmith')
|
|
|
|
|
|
2012-03-03 15:09:20 +00:00
|
|
|
assert_no_difference 'Watcher.count' do
|
2017-06-01 18:17:27 +00:00
|
|
|
get '/watchers/watch?object_type=issue&object_id=1'
|
2012-04-25 17:17:49 +00:00
|
|
|
assert_response 404
|
2012-03-03 15:09:20 +00:00
|
|
|
end
|
|
|
|
|
end
|
2021-05-28 03:58:01 +00:00
|
|
|
|
|
|
|
|
def test_invalid_operators_should_render_404
|
|
|
|
|
get '/projects/ecookbook/issues', :params => {
|
|
|
|
|
'set_filter' => '1',
|
|
|
|
|
'f' => ['status_id', 'cf_9'],
|
|
|
|
|
'op' => {'status_id' => 'o', 'cf_9' => '=6546546546'},
|
|
|
|
|
'v' => {'cf_9' => ['2021-05-25']}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert_response 404
|
|
|
|
|
end
|
2006-12-26 20:14:03 +00:00
|
|
|
end
|