annotate .svn/pristine/b3/b310ea90d1cc21b916ac58fa7a6d02313034a444.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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