##// END OF EJS Templates
add functional attachment test of mercurial export file (#11868)...
Toshi MARUYAMA -
r10246:551c024b454d
parent child
Show More
@@ -0,0 +1,13
1 # HG changeset patch
2 # User test
3 # Date 1348014182 -32400
4 # Node ID d1c871b8ef113df7f1c56d41e6e3bfbaff976e1f
5 # Parent 180b6605936cdc7909c5f08b59746ec1a7c99b3e
6 modify test1.txt
7
8 diff -r 180b6605936c -r d1c871b8ef11 test1.txt
9 --- a/test1.txt
10 +++ b/test1.txt
11 @@ -1,1 +1,1 @@
12 -test1
13 +modify test1
@@ -1,363 +1,378
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2012 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 require File.expand_path('../../test_helper', __FILE__)
21 21 require 'attachments_controller'
22 22
23 23 # Re-raise errors caught by the controller.
24 24 class AttachmentsController; def rescue_action(e) raise e end; end
25 25
26 26 class AttachmentsControllerTest < ActionController::TestCase
27 27 fixtures :users, :projects, :roles, :members, :member_roles,
28 28 :enabled_modules, :issues, :trackers, :attachments,
29 29 :versions, :wiki_pages, :wikis, :documents
30 30
31 31 def setup
32 32 @controller = AttachmentsController.new
33 33 @request = ActionController::TestRequest.new
34 34 @response = ActionController::TestResponse.new
35 35 User.current = nil
36 36 set_fixtures_attachments_directory
37 37 end
38 38
39 39 def teardown
40 40 set_tmp_attachments_directory
41 41 end
42 42
43 43 def test_show_diff
44 44 ['inline', 'sbs'].each do |dt|
45 45 # 060719210727_changeset_utf8.diff
46 46 get :show, :id => 14, :type => dt
47 47 assert_response :success
48 48 assert_template 'diff'
49 49 assert_equal 'text/html', @response.content_type
50 50 assert_tag 'th',
51 51 :attributes => {:class => /filename/},
52 52 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
53 53 assert_tag 'td',
54 54 :attributes => {:class => /line-code/},
55 55 :content => /Demande créée avec succès/
56 56 end
57 57 set_tmp_attachments_directory
58 58 end
59 59
60 60 def test_show_diff_replcace_cannot_convert_content
61 61 with_settings :repositories_encodings => 'UTF-8' do
62 62 ['inline', 'sbs'].each do |dt|
63 63 # 060719210727_changeset_iso8859-1.diff
64 64 get :show, :id => 5, :type => dt
65 65 assert_response :success
66 66 assert_template 'diff'
67 67 assert_equal 'text/html', @response.content_type
68 68 assert_tag 'th',
69 69 :attributes => {:class => "filename"},
70 70 :content => /issues_controller.rb\t\(r\?vision 1484\)/
71 71 assert_tag 'td',
72 72 :attributes => {:class => /line-code/},
73 73 :content => /Demande cr\?\?e avec succ\?s/
74 74 end
75 75 end
76 76 set_tmp_attachments_directory
77 77 end
78 78
79 79 def test_show_diff_latin_1
80 80 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
81 81 ['inline', 'sbs'].each do |dt|
82 82 # 060719210727_changeset_iso8859-1.diff
83 83 get :show, :id => 5, :type => dt
84 84 assert_response :success
85 85 assert_template 'diff'
86 86 assert_equal 'text/html', @response.content_type
87 87 assert_tag 'th',
88 88 :attributes => {:class => "filename"},
89 89 :content => /issues_controller.rb\t\(rΓ©vision 1484\)/
90 90 assert_tag 'td',
91 91 :attributes => {:class => /line-code/},
92 92 :content => /Demande créée avec succès/
93 93 end
94 94 end
95 95 set_tmp_attachments_directory
96 96 end
97 97
98 98 def test_save_diff_type
99 99 @request.session[:user_id] = 1 # admin
100 100 user = User.find(1)
101 101 get :show, :id => 5
102 102 assert_response :success
103 103 assert_template 'diff'
104 104 user.reload
105 105 assert_equal "inline", user.pref[:diff_type]
106 106 get :show, :id => 5, :type => 'sbs'
107 107 assert_response :success
108 108 assert_template 'diff'
109 109 user.reload
110 110 assert_equal "sbs", user.pref[:diff_type]
111 111 end
112 112
113 def test_diff_show_filename_in_mercurial_export
114 set_tmp_attachments_directory
115 a = Attachment.new(:container => Issue.find(1),
116 :file => uploaded_test_file("hg-export.diff", "text/plain"),
117 :author => User.find(1))
118 assert a.save
119 assert_equal 'hg-export.diff', a.filename
120
121 get :show, :id => a.id, :type => 'inline'
122 assert_response :success
123 assert_template 'diff'
124 assert_equal 'text/html', @response.content_type
125 assert_select 'th.filename', :text => 'test1.txt'
126 end
127
113 128 def test_show_text_file
114 129 get :show, :id => 4
115 130 assert_response :success
116 131 assert_template 'file'
117 132 assert_equal 'text/html', @response.content_type
118 133 set_tmp_attachments_directory
119 134 end
120 135
121 136 def test_show_text_file_utf_8
122 137 set_tmp_attachments_directory
123 138 a = Attachment.new(:container => Issue.find(1),
124 139 :file => uploaded_test_file("japanese-utf-8.txt", "text/plain"),
125 140 :author => User.find(1))
126 141 assert a.save
127 142 assert_equal 'japanese-utf-8.txt', a.filename
128 143
129 144 str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
130 145 str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding)
131 146
132 147 get :show, :id => a.id
133 148 assert_response :success
134 149 assert_template 'file'
135 150 assert_equal 'text/html', @response.content_type
136 151 assert_tag :tag => 'th',
137 152 :content => '1',
138 153 :attributes => { :class => 'line-num' },
139 154 :sibling => { :tag => 'td', :content => /#{str_japanese}/ }
140 155 end
141 156
142 157 def test_show_text_file_replcace_cannot_convert_content
143 158 set_tmp_attachments_directory
144 159 with_settings :repositories_encodings => 'UTF-8' do
145 160 a = Attachment.new(:container => Issue.find(1),
146 161 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
147 162 :author => User.find(1))
148 163 assert a.save
149 164 assert_equal 'iso8859-1.txt', a.filename
150 165
151 166 get :show, :id => a.id
152 167 assert_response :success
153 168 assert_template 'file'
154 169 assert_equal 'text/html', @response.content_type
155 170 assert_tag :tag => 'th',
156 171 :content => '7',
157 172 :attributes => { :class => 'line-num' },
158 173 :sibling => { :tag => 'td', :content => /Demande cr\?\?e avec succ\?s/ }
159 174 end
160 175 end
161 176
162 177 def test_show_text_file_latin_1
163 178 set_tmp_attachments_directory
164 179 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
165 180 a = Attachment.new(:container => Issue.find(1),
166 181 :file => uploaded_test_file("iso8859-1.txt", "text/plain"),
167 182 :author => User.find(1))
168 183 assert a.save
169 184 assert_equal 'iso8859-1.txt', a.filename
170 185
171 186 get :show, :id => a.id
172 187 assert_response :success
173 188 assert_template 'file'
174 189 assert_equal 'text/html', @response.content_type
175 190 assert_tag :tag => 'th',
176 191 :content => '7',
177 192 :attributes => { :class => 'line-num' },
178 193 :sibling => { :tag => 'td', :content => /Demande créée avec succès/ }
179 194 end
180 195 end
181 196
182 197 def test_show_text_file_should_send_if_too_big
183 198 Setting.file_max_size_displayed = 512
184 199 Attachment.find(4).update_attribute :filesize, 754.kilobyte
185 200
186 201 get :show, :id => 4
187 202 assert_response :success
188 203 assert_equal 'application/x-ruby', @response.content_type
189 204 set_tmp_attachments_directory
190 205 end
191 206
192 207 def test_show_other
193 208 get :show, :id => 6
194 209 assert_response :success
195 210 assert_equal 'application/octet-stream', @response.content_type
196 211 set_tmp_attachments_directory
197 212 end
198 213
199 214 def test_show_file_from_private_issue_without_permission
200 215 get :show, :id => 15
201 216 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
202 217 set_tmp_attachments_directory
203 218 end
204 219
205 220 def test_show_file_from_private_issue_with_permission
206 221 @request.session[:user_id] = 2
207 222 get :show, :id => 15
208 223 assert_response :success
209 224 assert_tag 'h2', :content => /private.diff/
210 225 set_tmp_attachments_directory
211 226 end
212 227
213 228 def test_show_file_without_container_should_be_denied
214 229 set_tmp_attachments_directory
215 230 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
216 231
217 232 @request.session[:user_id] = 2
218 233 get :show, :id => attachment.id
219 234 assert_response 403
220 235 end
221 236
222 237 def test_show_invalid_should_respond_with_404
223 238 get :show, :id => 999
224 239 assert_response 404
225 240 end
226 241
227 242 def test_download_text_file
228 243 get :download, :id => 4
229 244 assert_response :success
230 245 assert_equal 'application/x-ruby', @response.content_type
231 246 set_tmp_attachments_directory
232 247 end
233 248
234 249 def test_download_version_file_with_issue_tracking_disabled
235 250 Project.find(1).disable_module! :issue_tracking
236 251 get :download, :id => 9
237 252 assert_response :success
238 253 end
239 254
240 255 def test_download_should_assign_content_type_if_blank
241 256 Attachment.find(4).update_attribute(:content_type, '')
242 257
243 258 get :download, :id => 4
244 259 assert_response :success
245 260 assert_equal 'text/x-ruby', @response.content_type
246 261 set_tmp_attachments_directory
247 262 end
248 263
249 264 def test_download_missing_file
250 265 get :download, :id => 2
251 266 assert_response 404
252 267 set_tmp_attachments_directory
253 268 end
254 269
255 270 def test_download_should_be_denied_without_permission
256 271 get :download, :id => 7
257 272 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
258 273 set_tmp_attachments_directory
259 274 end
260 275
261 276 if convert_installed?
262 277 def test_thumbnail
263 278 Attachment.clear_thumbnails
264 279 @request.session[:user_id] = 2
265 280
266 281 get :thumbnail, :id => 16
267 282 assert_response :success
268 283 assert_equal 'image/png', response.content_type
269 284 end
270 285
271 286 def test_thumbnail_should_not_exceed_maximum_size
272 287 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 800}
273 288
274 289 @request.session[:user_id] = 2
275 290 get :thumbnail, :id => 16, :size => 2000
276 291 end
277 292
278 293 def test_thumbnail_should_round_size
279 294 Redmine::Thumbnail.expects(:generate).with {|source, target, size| size == 250}
280 295
281 296 @request.session[:user_id] = 2
282 297 get :thumbnail, :id => 16, :size => 260
283 298 end
284 299
285 300 def test_thumbnail_should_return_404_for_non_image_attachment
286 301 @request.session[:user_id] = 2
287 302
288 303 get :thumbnail, :id => 15
289 304 assert_response 404
290 305 end
291 306
292 307 def test_thumbnail_should_return_404_if_thumbnail_generation_failed
293 308 Attachment.any_instance.stubs(:thumbnail).returns(nil)
294 309 @request.session[:user_id] = 2
295 310
296 311 get :thumbnail, :id => 16
297 312 assert_response 404
298 313 end
299 314
300 315 def test_thumbnail_should_be_denied_without_permission
301 316 get :thumbnail, :id => 16
302 317 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fthumbnail%2F16'
303 318 end
304 319 else
305 320 puts '(ImageMagick convert not available)'
306 321 end
307 322
308 323 def test_destroy_issue_attachment
309 324 set_tmp_attachments_directory
310 325 issue = Issue.find(3)
311 326 @request.session[:user_id] = 2
312 327
313 328 assert_difference 'issue.attachments.count', -1 do
314 329 assert_difference 'Journal.count' do
315 330 delete :destroy, :id => 1
316 331 assert_redirected_to '/projects/ecookbook'
317 332 end
318 333 end
319 334 assert_nil Attachment.find_by_id(1)
320 335 j = Journal.first(:order => 'id DESC')
321 336 assert_equal issue, j.journalized
322 337 assert_equal 'attachment', j.details.first.property
323 338 assert_equal '1', j.details.first.prop_key
324 339 assert_equal 'error281.txt', j.details.first.old_value
325 340 assert_equal User.find(2), j.user
326 341 end
327 342
328 343 def test_destroy_wiki_page_attachment
329 344 set_tmp_attachments_directory
330 345 @request.session[:user_id] = 2
331 346 assert_difference 'Attachment.count', -1 do
332 347 delete :destroy, :id => 3
333 348 assert_response 302
334 349 end
335 350 end
336 351
337 352 def test_destroy_project_attachment
338 353 set_tmp_attachments_directory
339 354 @request.session[:user_id] = 2
340 355 assert_difference 'Attachment.count', -1 do
341 356 delete :destroy, :id => 8
342 357 assert_response 302
343 358 end
344 359 end
345 360
346 361 def test_destroy_version_attachment
347 362 set_tmp_attachments_directory
348 363 @request.session[:user_id] = 2
349 364 assert_difference 'Attachment.count', -1 do
350 365 delete :destroy, :id => 9
351 366 assert_response 302
352 367 end
353 368 end
354 369
355 370 def test_destroy_without_permission
356 371 set_tmp_attachments_directory
357 372 assert_no_difference 'Attachment.count' do
358 373 delete :destroy, :id => 3
359 374 end
360 375 assert_response 302
361 376 assert Attachment.find_by_id(3)
362 377 end
363 378 end
General Comments 0
You need to be logged in to leave comments. Login now