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