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 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- 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_relative '../test_helper'
  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 =
  32. Repository::Filesystem.create(
  33. :project => @project,
  34. :url => REPOSITORY_PATH,
  35. :path_encoding => ''
  36. )
  37. assert @repository
  38. end
  39. if File.directory?(REPOSITORY_PATH)
  40. def test_get_new
  41. @request.session[:user_id] = 1
  42. @project.repository.destroy
  43. get(
  44. :new,
  45. :params => {
  46. :project_id => 'subproject1',
  47. :repository_scm => 'Filesystem'
  48. }
  49. )
  50. assert_response :success
  51. assert_select 'select[name=?]', 'repository_scm' do
  52. assert_select 'option[value=?][selected=selected]', 'Filesystem'
  53. end
  54. end
  55. def test_browse_root
  56. @repository.fetch_changesets
  57. @repository.reload
  58. get(
  59. :show,
  60. :params => {
  61. :id => PRJ_ID
  62. }
  63. )
  64. assert_response :success
  65. assert_select 'table.entries tbody' do
  66. assert_select 'tr', 3
  67. assert_select 'tr.dir td.filename a', :text => 'dir'
  68. assert_select 'tr.dir td.filename a', :text => 'japanese'
  69. assert_select 'tr.file td.filename a', :text => 'test'
  70. end
  71. assert_select 'table.changesets tbody', 0
  72. assert_select 'input[name=rev]', 0
  73. assert_select 'a', :text => 'Statistics', :count => 0
  74. assert_select 'a', :text => 'Atom', :count => 0
  75. end
  76. def test_show_no_extension
  77. get(
  78. :entry,
  79. :params => {
  80. :id => PRJ_ID,
  81. :repository_id => @repository.id,
  82. :path => repository_path_hash(['test'])[:param]
  83. }
  84. )
  85. assert_response :success
  86. assert_select 'tr#L1 td.line-code', :text => /TEST CAT/
  87. end
  88. def test_entry_download_no_extension
  89. get(
  90. :raw,
  91. :params => {
  92. :id => PRJ_ID,
  93. :repository_id => @repository.id,
  94. :path => repository_path_hash(['test'])[:param]
  95. }
  96. )
  97. assert_response :success
  98. assert_equal 'application/octet-stream', @response.media_type
  99. end
  100. def test_show_non_ascii_contents
  101. with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
  102. get(
  103. :entry,
  104. :params => {
  105. :id => PRJ_ID,
  106. :repository_id => @repository.id,
  107. :path => repository_path_hash(['japanese', 'euc-jp.txt'])[:param]
  108. }
  109. )
  110. assert_response :success
  111. assert_select 'tr#L2 td.line-code', :text => /japanese/
  112. if @ruby19_non_utf8_pass
  113. puts "TODO: show repository file contents test fails " \
  114. "when Encoding.default_external is not UTF-8. " \
  115. "Current value is '#{Encoding.default_external.to_s}'"
  116. else
  117. assert_select 'tr#L3 td.line-code', :text => /日本語/
  118. end
  119. end
  120. end
  121. def test_show_utf16
  122. enc = 'UTF-16'
  123. with_settings :repositories_encodings => enc do
  124. get(
  125. :entry,
  126. :params => {
  127. :id => PRJ_ID,
  128. :repository_id => @repository.id,
  129. :path => repository_path_hash(['japanese', 'utf-16.txt'])[:param]
  130. }
  131. )
  132. assert_response :success
  133. assert_select 'tr#L2 td.line-code', :text => /japanese/
  134. end
  135. end
  136. def test_show_text_file_should_show_other_if_too_big
  137. with_settings :file_max_size_displayed => 1 do
  138. get(
  139. :entry,
  140. :params => {
  141. :id => PRJ_ID,
  142. :repository_id => @repository.id,
  143. :path => repository_path_hash(['japanese', 'big-file.txt'])[:param]
  144. }
  145. )
  146. assert_response :success
  147. assert_equal 'text/html', @response.media_type
  148. assert_select 'p.nodata'
  149. end
  150. end
  151. def test_destroy_valid_repository
  152. @request.session[:user_id] = 1 # admin
  153. assert_difference 'Repository.count', -1 do
  154. delete(
  155. :destroy,
  156. :params => {
  157. :id => @repository.id
  158. }
  159. )
  160. end
  161. assert_response 302
  162. @project.reload
  163. assert_nil @project.repository
  164. end
  165. def test_destroy_invalid_repository
  166. @request.session[:user_id] = 1 # admin
  167. @project.repository.destroy
  168. @repository =
  169. Repository::Filesystem.create!(
  170. :project => @project,
  171. :url => "/invalid",
  172. :path_encoding => ''
  173. )
  174. assert_difference 'Repository.count', -1 do
  175. delete(
  176. :destroy,
  177. :params => {
  178. :id => @repository.id
  179. }
  180. )
  181. end
  182. assert_response 302
  183. @project.reload
  184. assert_nil @project.repository
  185. end
  186. def test_show_should_only_show_view_tab
  187. get(
  188. :entry,
  189. :params => {
  190. :id => PRJ_ID,
  191. :repository_id => @repository.id,
  192. :path => repository_path_hash(['test'])[:param]
  193. }
  194. )
  195. assert_response :success
  196. assert @repository.supports_cat?
  197. assert_select 'a#tab-entry', :text => /View/
  198. assert_not @repository.supports_history?
  199. assert_select 'a#tab-changes', 0
  200. assert_not @repository.supports_annotate?
  201. assert_select 'a#tab-annotate', 0
  202. end
  203. else
  204. puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!"
  205. def test_fake; assert true end
  206. end
  207. end