##// END OF EJS Templates
Test failures....
Jean-Philippe Lang -
r15481:51227270bda4
parent child
Show More
@@ -1,283 +1,283
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2016 Jean-Philippe Lang
2 # Copyright (C) 2006-2016 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, :email_addresses,
22 :users, :email_addresses,
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 :attachments
35 :attachments
36
36
37 # create an issue
37 # create an issue
38 def test_add_issue
38 def test_add_issue
39 log_user('jsmith', 'jsmith')
39 log_user('jsmith', 'jsmith')
40
40
41 get '/projects/ecookbook/issues/new'
41 get '/projects/ecookbook/issues/new'
42 assert_response :success
42 assert_response :success
43
43
44 issue = new_record(Issue) do
44 issue = new_record(Issue) do
45 post '/projects/ecookbook/issues',
45 post '/projects/ecookbook/issues',
46 :issue => { :tracker_id => "1",
46 :issue => { :tracker_id => "1",
47 :start_date => "2006-12-26",
47 :start_date => "2006-12-26",
48 :priority_id => "4",
48 :priority_id => "4",
49 :subject => "new test issue",
49 :subject => "new test issue",
50 :category_id => "",
50 :category_id => "",
51 :description => "new issue",
51 :description => "new issue",
52 :done_ratio => "0",
52 :done_ratio => "0",
53 :due_date => "",
53 :due_date => "",
54 :assigned_to_id => "" },
54 :assigned_to_id => "" },
55 :custom_fields => {'2' => 'Value for field 2'}
55 :custom_fields => {'2' => 'Value for field 2'}
56 end
56 end
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
60
61 # check issue attributes
61 # check issue attributes
62 assert_equal 'jsmith', issue.author.login
62 assert_equal 'jsmith', issue.author.login
63 assert_equal 1, issue.project.id
63 assert_equal 1, issue.project.id
64 assert_equal 1, issue.status.id
64 assert_equal 1, issue.status.id
65 end
65 end
66
66
67 def test_create_issue_by_anonymous_without_permission_should_fail
67 def test_create_issue_by_anonymous_without_permission_should_fail
68 Role.anonymous.remove_permission! :add_issues
68 Role.anonymous.remove_permission! :add_issues
69
69
70 assert_no_difference 'Issue.count' do
70 assert_no_difference 'Issue.count' do
71 post '/projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
71 post '/projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
72 end
72 end
73 assert_response 302
73 assert_response 302
74 end
74 end
75
75
76 def test_create_issue_by_anonymous_with_custom_permission_should_succeed
76 def test_create_issue_by_anonymous_with_custom_permission_should_succeed
77 Role.anonymous.remove_permission! :add_issues
77 Role.anonymous.remove_permission! :add_issues
78 Member.create!(:project_id => 1, :principal => Group.anonymous, :role_ids => [3])
78 Member.create!(:project_id => 1, :principal => Group.anonymous, :role_ids => [3])
79
79
80 issue = new_record(Issue) do
80 issue = new_record(Issue) do
81 post '/projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
81 post '/projects/1/issues', :tracker_id => "1", :issue => {:subject => "new test issue"}
82 assert_response 302
82 assert_response 302
83 end
83 end
84 assert_equal User.anonymous, issue.author
84 assert_equal User.anonymous, issue.author
85 end
85 end
86
86
87 # add then remove 2 attachments to an issue
87 # add then remove 2 attachments to an issue
88 def test_issue_attachments
88 def test_issue_attachments
89 log_user('jsmith', 'jsmith')
89 log_user('jsmith', 'jsmith')
90 set_tmp_attachments_directory
90 set_tmp_attachments_directory
91
91
92 attachment = new_record(Attachment) do
92 attachment = new_record(Attachment) do
93 put '/issues/1',
93 put '/issues/1',
94 :notes => 'Some notes',
94 :notes => 'Some notes',
95 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
95 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
96 assert_redirected_to "/issues/1"
96 assert_redirected_to "/issues/1"
97 end
97 end
98
98
99 assert_equal Issue.find(1), attachment.container
99 assert_equal Issue.find(1), attachment.container
100 assert_equal 'testfile.txt', attachment.filename
100 assert_equal 'testfile.txt', attachment.filename
101 assert_equal 'This is an attachment', attachment.description
101 assert_equal 'This is an attachment', attachment.description
102 # verify the size of the attachment stored in db
102 # verify the size of the attachment stored in db
103 #assert_equal file_data_1.length, attachment.filesize
103 #assert_equal file_data_1.length, attachment.filesize
104 # verify that the attachment was written to disk
104 # verify that the attachment was written to disk
105 assert File.exist?(attachment.diskfile)
105 assert File.exist?(attachment.diskfile)
106
106
107 # remove the attachments
107 # remove the attachments
108 Issue.find(1).attachments.each(&:destroy)
108 Issue.find(1).attachments.each(&:destroy)
109 assert_equal 0, Issue.find(1).attachments.length
109 assert_equal 0, Issue.find(1).attachments.length
110 end
110 end
111
111
112 def test_next_and_previous_links_should_be_displayed_after_query_grouped_and_sorted_by_version
112 def test_next_and_previous_links_should_be_displayed_after_query_grouped_and_sorted_by_version
113 with_settings :default_language => 'en' do
113 with_settings :default_language => 'en' do
114 get '/projects/ecookbook/issues?set_filter=1&group_by=fixed_version&sort=priority:desc,fixed_version'
114 get '/projects/ecookbook/issues?set_filter=1&group_by=fixed_version&sort=priority:desc,fixed_version,id'
115 assert_response :success
115 assert_response :success
116 assert_select 'td.id', :text => '5'
116 assert_select 'td.id', :text => '5'
117
117
118 get '/issues/5'
118 get '/issues/5'
119 assert_response :success
119 assert_response :success
120 assert_select '.next-prev-links .position', :text => '5 of 6'
120 assert_select '.next-prev-links .position', :text => '5 of 6'
121 end
121 end
122 end
122 end
123
123
124 def test_next_and_previous_links_should_be_displayed_after_filter
124 def test_next_and_previous_links_should_be_displayed_after_filter
125 with_settings :default_language => 'en' do
125 with_settings :default_language => 'en' do
126 get '/projects/ecookbook/issues?set_filter=1&tracker_id=1'
126 get '/projects/ecookbook/issues?set_filter=1&tracker_id=1'
127 assert_response :success
127 assert_response :success
128 assert_select 'td.id', :text => '5'
128 assert_select 'td.id', :text => '5'
129
129
130 get '/issues/5'
130 get '/issues/5'
131 assert_response :success
131 assert_response :success
132 assert_select '.next-prev-links .position', :text => '3 of 5'
132 assert_select '.next-prev-links .position', :text => '3 of 5'
133 end
133 end
134 end
134 end
135
135
136 def test_next_and_previous_links_should_be_displayed_after_saved_query
136 def test_next_and_previous_links_should_be_displayed_after_saved_query
137 query = IssueQuery.create!(:name => 'Calendar Query',
137 query = IssueQuery.create!(:name => 'Calendar Query',
138 :visibility => IssueQuery::VISIBILITY_PUBLIC,
138 :visibility => IssueQuery::VISIBILITY_PUBLIC,
139 :filters => {'tracker_id' => {:operator => '=', :values => ['1']}}
139 :filters => {'tracker_id' => {:operator => '=', :values => ['1']}}
140 )
140 )
141
141
142 with_settings :default_language => 'en' do
142 with_settings :default_language => 'en' do
143 get "/projects/ecookbook/issues?set_filter=1&query_id=#{query.id}"
143 get "/projects/ecookbook/issues?set_filter=1&query_id=#{query.id}"
144 assert_response :success
144 assert_response :success
145 assert_select 'td.id', :text => '5'
145 assert_select 'td.id', :text => '5'
146
146
147 get '/issues/5'
147 get '/issues/5'
148 assert_response :success
148 assert_response :success
149 assert_select '.next-prev-links .position', :text => '6 of 8'
149 assert_select '.next-prev-links .position', :text => '6 of 8'
150 end
150 end
151 end
151 end
152
152
153 def test_other_formats_links_on_index
153 def test_other_formats_links_on_index
154 get '/projects/ecookbook/issues'
154 get '/projects/ecookbook/issues'
155
155
156 %w(Atom PDF CSV).each do |format|
156 %w(Atom PDF CSV).each do |format|
157 assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
157 assert_select 'a[rel=nofollow][href=?]', "/projects/ecookbook/issues.#{format.downcase}", :text => format
158 end
158 end
159 end
159 end
160
160
161 def test_other_formats_links_on_index_without_project_id_in_url
161 def test_other_formats_links_on_index_without_project_id_in_url
162 get '/issues', :project_id => 'ecookbook'
162 get '/issues', :project_id => 'ecookbook'
163
163
164 %w(Atom PDF CSV).each do |format|
164 %w(Atom PDF CSV).each do |format|
165 assert_select 'a[rel=nofollow][href=?]', "/issues.#{format.downcase}?project_id=ecookbook", :text => format
165 assert_select 'a[rel=nofollow][href=?]', "/issues.#{format.downcase}?project_id=ecookbook", :text => format
166 end
166 end
167 end
167 end
168
168
169 def test_pagination_links_on_index
169 def test_pagination_links_on_index
170 with_settings :per_page_options => '2' do
170 with_settings :per_page_options => '2' do
171 get '/projects/ecookbook/issues'
171 get '/projects/ecookbook/issues'
172
172
173 assert_select 'a[href=?]', '/projects/ecookbook/issues?page=2', :text => '2'
173 assert_select 'a[href=?]', '/projects/ecookbook/issues?page=2', :text => '2'
174 end
174 end
175 end
175 end
176
176
177 def test_pagination_links_should_preserve_query_parameters
177 def test_pagination_links_should_preserve_query_parameters
178 with_settings :per_page_options => '2' do
178 with_settings :per_page_options => '2' do
179 get '/projects/ecookbook/issues?foo=bar'
179 get '/projects/ecookbook/issues?foo=bar'
180
180
181 assert_select 'a[href=?]', '/projects/ecookbook/issues?foo=bar&page=2', :text => '2'
181 assert_select 'a[href=?]', '/projects/ecookbook/issues?foo=bar&page=2', :text => '2'
182 end
182 end
183 end
183 end
184
184
185 def test_pagination_links_should_not_use_params_as_url_options
185 def test_pagination_links_should_not_use_params_as_url_options
186 with_settings :per_page_options => '2' do
186 with_settings :per_page_options => '2' do
187 get '/projects/ecookbook/issues?host=foo'
187 get '/projects/ecookbook/issues?host=foo'
188
188
189 assert_select 'a[href=?]', '/projects/ecookbook/issues?host=foo&page=2', :text => '2'
189 assert_select 'a[href=?]', '/projects/ecookbook/issues?host=foo&page=2', :text => '2'
190 end
190 end
191 end
191 end
192
192
193 def test_sort_links_on_index
193 def test_sort_links_on_index
194 get '/projects/ecookbook/issues'
194 get '/projects/ecookbook/issues'
195
195
196 assert_select 'a[href=?]', '/projects/ecookbook/issues?sort=subject%2Cid%3Adesc', :text => 'Subject'
196 assert_select 'a[href=?]', '/projects/ecookbook/issues?sort=subject%2Cid%3Adesc', :text => 'Subject'
197 end
197 end
198
198
199 def test_sort_links_should_preserve_query_parameters
199 def test_sort_links_should_preserve_query_parameters
200 get '/projects/ecookbook/issues?foo=bar'
200 get '/projects/ecookbook/issues?foo=bar'
201
201
202 assert_select 'a[href=?]', '/projects/ecookbook/issues?foo=bar&sort=subject%2Cid%3Adesc', :text => 'Subject'
202 assert_select 'a[href=?]', '/projects/ecookbook/issues?foo=bar&sort=subject%2Cid%3Adesc', :text => 'Subject'
203 end
203 end
204
204
205 def test_sort_links_should_not_use_params_as_url_options
205 def test_sort_links_should_not_use_params_as_url_options
206 get '/projects/ecookbook/issues?host=foo'
206 get '/projects/ecookbook/issues?host=foo'
207
207
208 assert_select 'a[href=?]', '/projects/ecookbook/issues?host=foo&sort=subject%2Cid%3Adesc', :text => 'Subject'
208 assert_select 'a[href=?]', '/projects/ecookbook/issues?host=foo&sort=subject%2Cid%3Adesc', :text => 'Subject'
209 end
209 end
210
210
211 def test_issue_with_user_custom_field
211 def test_issue_with_user_custom_field
212 @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
212 @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
213 Role.anonymous.add_permission! :add_issues, :edit_issues
213 Role.anonymous.add_permission! :add_issues, :edit_issues
214 users = Project.find(1).users.sort
214 users = Project.find(1).users.sort
215 tester = users.first
215 tester = users.first
216
216
217 # Issue form
217 # Issue form
218 get '/projects/ecookbook/issues/new'
218 get '/projects/ecookbook/issues/new'
219 assert_response :success
219 assert_response :success
220 assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
220 assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
221 assert_select 'option', users.size + 1 # +1 for blank value
221 assert_select 'option', users.size + 1 # +1 for blank value
222 assert_select 'option[value=?]', tester.id.to_s, :text => tester.name
222 assert_select 'option[value=?]', tester.id.to_s, :text => tester.name
223 end
223 end
224
224
225 # Create issue
225 # Create issue
226 issue = new_record(Issue) do
226 issue = new_record(Issue) do
227 post '/projects/ecookbook/issues',
227 post '/projects/ecookbook/issues',
228 :issue => {
228 :issue => {
229 :tracker_id => '1',
229 :tracker_id => '1',
230 :priority_id => '4',
230 :priority_id => '4',
231 :subject => 'Issue with user custom field',
231 :subject => 'Issue with user custom field',
232 :custom_field_values => {@field.id.to_s => users.first.id.to_s}
232 :custom_field_values => {@field.id.to_s => users.first.id.to_s}
233 }
233 }
234 assert_response 302
234 assert_response 302
235 end
235 end
236
236
237 # Issue view
237 # Issue view
238 follow_redirect!
238 follow_redirect!
239 assert_select ".cf_#{@field.id}" do
239 assert_select ".cf_#{@field.id}" do
240 assert_select '.label', :text => 'Tester:'
240 assert_select '.label', :text => 'Tester:'
241 assert_select '.value', :text => tester.name
241 assert_select '.value', :text => tester.name
242 end
242 end
243 assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
243 assert_select 'select[name=?]', "issue[custom_field_values][#{@field.id}]" do
244 assert_select 'option', users.size + 1 # +1 for blank value
244 assert_select 'option', users.size + 1 # +1 for blank value
245 assert_select 'option[value=?][selected=selected]', tester.id.to_s, :text => tester.name
245 assert_select 'option[value=?][selected=selected]', tester.id.to_s, :text => tester.name
246 end
246 end
247
247
248 new_tester = users[1]
248 new_tester = users[1]
249 with_settings :default_language => 'en' do
249 with_settings :default_language => 'en' do
250 # Update issue
250 # Update issue
251 assert_difference 'Journal.count' do
251 assert_difference 'Journal.count' do
252 put "/issues/#{issue.id}",
252 put "/issues/#{issue.id}",
253 :notes => 'Updating custom field',
253 :notes => 'Updating custom field',
254 :issue => {
254 :issue => {
255 :custom_field_values => {@field.id.to_s => new_tester.id.to_s}
255 :custom_field_values => {@field.id.to_s => new_tester.id.to_s}
256 }
256 }
257 assert_redirected_to "/issues/#{issue.id}"
257 assert_redirected_to "/issues/#{issue.id}"
258 end
258 end
259 # Issue view
259 # Issue view
260 follow_redirect!
260 follow_redirect!
261 assert_select 'ul.details li', :text => "Tester changed from #{tester} to #{new_tester}"
261 assert_select 'ul.details li', :text => "Tester changed from #{tester} to #{new_tester}"
262 end
262 end
263 end
263 end
264
264
265 def test_update_using_invalid_http_verbs
265 def test_update_using_invalid_http_verbs
266 subject = 'Updated by an invalid http verb'
266 subject = 'Updated by an invalid http verb'
267
267
268 get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith')
268 get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith')
269 assert_response 404
269 assert_response 404
270 assert_not_equal subject, Issue.find(1).subject
270 assert_not_equal subject, Issue.find(1).subject
271
271
272 post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith')
272 post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith')
273 assert_response 404
273 assert_response 404
274 assert_not_equal subject, Issue.find(1).subject
274 assert_not_equal subject, Issue.find(1).subject
275 end
275 end
276
276
277 def test_get_watch_should_be_invalid
277 def test_get_watch_should_be_invalid
278 assert_no_difference 'Watcher.count' do
278 assert_no_difference 'Watcher.count' do
279 get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith')
279 get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith')
280 assert_response 404
280 assert_response 404
281 end
281 end
282 end
282 end
283 end
283 end
General Comments 0
You need to be logged in to leave comments. Login now