You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repositories_filesystem_controller_test.rb 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../test_helper', __FILE__)
  19. class RepositoriesFilesystemControllerTest < Redmine::RepositoryControllerTest
  20. tests RepositoriesController
  21. fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
  22. :repositories, :enabled_modules
  23. REPOSITORY_PATH = Rails.root.join('tmp/test/filesystem_repository').to_s
  24. PRJ_ID = 3
  25. def setup
  26. super
  27. @ruby19_non_utf8_pass = Encoding.default_external.to_s != 'UTF-8'
  28. User.current = nil
  29. Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
  30. @project = Project.find(PRJ_ID)
  31. @repository = Repository::Filesystem.create(
  32. :project => @project,
  33. :url => REPOSITORY_PATH,
  34. :path_encoding => ''
  35. )
  36. assert @repository
  37. end
  38. if File.directory?(REPOSITORY_PATH)
  39. def test_get_new
  40. @request.session[:user_id] = 1
  41. @project.repository.destroy
  42. get :new, :params => {
  43. :project_id => 'subproject1',
  44. :repository_scm => 'Filesystem'
  45. }
  46. assert_response :success
  47. assert_select 'select[name=?]', 'repository_scm' do
  48. assert_select 'option[value=?][selected=selected]', 'Filesystem'
  49. end
  50. end
  51. def test_browse_root
  52. @repository.fetch_changesets
  53. @repository.reload
  54. get :show, :params => {
  55. :id => PRJ_ID
  56. }
  57. assert_response :success
  58. assert_select 'table.entries tbody' do
  59. assert_select 'tr', 3
  60. assert_select 'tr.dir td.filename a', :text => 'dir'
  61. assert_select 'tr.dir td.filename a', :text => 'japanese'
  62. assert_select 'tr.file td.filename a', :text => 'test'
  63. end
  64. assert_select 'table.changesets tbody', 0
  65. assert_select 'input[name=rev]', 0
  66. assert_select 'a', :text => 'Statistics', :count => 0
  67. assert_select 'a', :text => 'Atom', :count => 0
  68. end
  69. def test_show_no_extension
  70. get :entry, :params => {
  71. :id => PRJ_ID,
  72. :repository_id => @repository.id,
  73. :path => repository_path_hash(['test'])[:param]
  74. }
  75. assert_response :success
  76. assert_select 'tr#L1 td.line-code', :text => /TEST CAT/
  77. end
  78. def test_entry_download_no_extension
  79. get :raw, :params => {
  80. :id => PRJ_ID,
  81. :repository_id => @repository.id,
  82. :path => repository_path_hash(['test'])[:param]
  83. }
  84. assert_response :success
  85. assert_equal 'application/octet-stream', @response.content_type
  86. end
  87. def test_show_non_ascii_contents
  88. with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
  89. get :entry, :params => {
  90. :id => PRJ_ID,
  91. :repository_id => @repository.id,
  92. :path => repository_path_hash(['japanese', 'euc-jp.txt'])[:param]
  93. }
  94. assert_response :success
  95. assert_select 'tr#L2 td.line-code', :text => /japanese/
  96. if @ruby19_non_utf8_pass
  97. puts "TODO: show repository file contents test fails " +
  98. "when Encoding.default_external is not UTF-8. " +
  99. "Current value is '#{Encoding.default_external.to_s}'"
  100. else
  101. assert_select 'tr#L3 td.line-code', :text => /日本語/
  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