Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

repositories_filesystem_controller_test.rb 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  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
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../test_helper', __FILE__)
  18. class RepositoriesFilesystemControllerTest < Redmine::RepositoryControllerTest
  19. tests RepositoriesController
  20. fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
  21. :repositories, :enabled_modules
  22. REPOSITORY_PATH = Rails.root.join('tmp/test/filesystem_repository').to_s
  23. PRJ_ID = 3
  24. def setup
  25. super
  26. @ruby19_non_utf8_pass = Encoding.default_external.to_s != 'UTF-8'
  27. User.current = nil
  28. Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
  29. @project = Project.find(PRJ_ID)
  30. @repository = Repository::Filesystem.create(
  31. :project => @project,
  32. :url => REPOSITORY_PATH,
  33. :path_encoding => ''
  34. )
  35. assert @repository
  36. end
  37. if File.directory?(REPOSITORY_PATH)
  38. def test_get_new
  39. @request.session[:user_id] = 1
  40. @project.repository.destroy
  41. get :new, :params => {
  42. :project_id => 'subproject1',
  43. :repository_scm => 'Filesystem'
  44. }
  45. assert_response :success
  46. assert_select 'select[name=?]', 'repository_scm' do
  47. assert_select 'option[value=?][selected=selected]', 'Filesystem'
  48. end
  49. end
  50. def test_browse_root
  51. @repository.fetch_changesets
  52. @repository.reload
  53. get :show, :params => {
  54. :id => PRJ_ID
  55. }
  56. assert_response :success
  57. assert_select 'table.entries tbody' do
  58. assert_select 'tr', 3
  59. assert_select 'tr.dir td.filename a', :text => 'dir'
  60. assert_select 'tr.dir td.filename a', :text => 'japanese'
  61. assert_select 'tr.file td.filename a', :text => 'test'
  62. end
  63. assert_select 'table.changesets tbody', 0
  64. assert_select 'input[name=rev]', 0
  65. assert_select 'a', :text => 'Statistics', :count => 0
  66. assert_select 'a', :text => 'Atom', :count => 0
  67. end
  68. def test_show_no_extension
  69. get :entry, :params => {
  70. :id => PRJ_ID,
  71. :repository_id => @repository.id,
  72. :path => repository_path_hash(['test'])[:param]
  73. }
  74. assert_response :success
  75. assert_select 'tr#L1 td.line-code', :text => /TEST CAT/
  76. end
  77. def test_entry_download_no_extension
  78. get :raw, :params => {
  79. :id => PRJ_ID,
  80. :repository_id => @repository.id,
  81. :path => repository_path_hash(['test'])[:param]
  82. }
  83. assert_response :success
  84. assert_equal 'application/octet-stream', @response.content_type
  85. end
  86. def test_show_non_ascii_contents
  87. with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
  88. get :entry, :params => {
  89. :id => PRJ_ID,
  90. :repository_id => @repository.id,
  91. :path => repository_path_hash(['japanese', 'euc-jp.txt'])[:param]
  92. }
  93. assert_response :success
  94. assert_select 'tr#L2 td.line-code', :text => /japanese/
  95. if @ruby19_non_utf8_pass
  96. puts "TODO: show repository file contents test fails " +
  97. "when Encoding.default_external is not UTF-8. " +
  98. "Current value is '#{Encoding.default_external.to_s}'"
  99. else
  100. str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e".force_encoding('UTF-8')
  101. assert_select 'tr#L3 td.line-code', :text => /#{str_japanese}/
  102. end
  103. end
  104. end
  105. def test_show_utf16
  106. enc = 'UTF-16'
  107. with_settings :repositories_encodings => enc do
  108. get :entry, :params => {
  109. :id => PRJ_ID,
  110. :repository_id => @repository.id,
  111. :path => repository_path_hash(['japanese', 'utf-16.txt'])[:param]
  112. }
  113. assert_response :success
  114. assert_select 'tr#L2 td.line-code', :text => /japanese/
  115. end
  116. end
  117. def test_show_text_file_should_show_other_if_too_big
  118. with_settings :file_max_size_displayed => 1 do
  119. get :entry, :params => {
  120. :id => PRJ_ID,
  121. :repository_id => @repository.id,
  122. :path => repository_path_hash(['japanese', 'big-file.txt'])[:param]
  123. }
  124. assert_response :success
  125. assert_equal 'text/html', @response.content_type
  126. assert_select 'p.nodata'
  127. end
  128. end
  129. def test_destroy_valid_repository
  130. @request.session[:user_id] = 1 # admin
  131. assert_difference 'Repository.count', -1 do
  132. delete :destroy, :params => {
  133. :id => @repository.id
  134. }
  135. end
  136. assert_response 302
  137. @project.reload
  138. assert_nil @project.repository
  139. end
  140. def test_destroy_invalid_repository
  141. @request.session[:user_id] = 1 # admin
  142. @project.repository.destroy
  143. @repository = Repository::Filesystem.create!(
  144. :project => @project,
  145. :url => "/invalid",
  146. :path_encoding => ''
  147. )
  148. assert_difference 'Repository.count', -1 do
  149. delete :destroy, :params => {
  150. :id => @repository.id
  151. }
  152. end
  153. assert_response 302
  154. @project.reload
  155. assert_nil @project.repository
  156. end
  157. else
  158. puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!"
  159. def test_fake; assert true end
  160. end
  161. end