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_cvs_controller_test.rb 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2020 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 RepositoriesCvsControllerTest < 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/cvs_repository').to_s
  24. REPOSITORY_PATH.tr!('/', "\\") if Redmine::Platform.mswin?
  25. # CVS module
  26. MODULE_NAME = 'test'
  27. PRJ_ID = 3
  28. NUM_REV = 7
  29. def setup
  30. super
  31. Setting.default_language = 'en'
  32. User.current = nil
  33. @project = Project.find(PRJ_ID)
  34. @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
  35. :root_url => REPOSITORY_PATH,
  36. :url => MODULE_NAME,
  37. :log_encoding => 'UTF-8')
  38. assert @repository
  39. end
  40. if File.directory?(REPOSITORY_PATH)
  41. def test_get_new
  42. @request.session[:user_id] = 1
  43. @project.repository.destroy
  44. get :new, :params => {
  45. :project_id => 'subproject1',
  46. :repository_scm => 'Cvs'
  47. }
  48. assert_response :success
  49. assert_select 'select[name=?]', 'repository_scm' do
  50. assert_select 'option[value=?][selected=selected]', 'Cvs'
  51. end
  52. end
  53. def test_browse_root
  54. assert_equal 0, @repository.changesets.count
  55. @repository.fetch_changesets
  56. @project.reload
  57. assert_equal NUM_REV, @repository.changesets.count
  58. get :show, :params => {
  59. :id => PRJ_ID
  60. }
  61. assert_response :success
  62. assert_select 'table.entries tbody' do
  63. assert_select 'tr', 3
  64. assert_select 'tr.dir td.filename a', :text => 'images'
  65. assert_select 'tr.file td.filename a', :text => 'README'
  66. end
  67. assert_select 'table.changesets tbody' do
  68. assert_select 'tr'
  69. end
  70. end
  71. def test_browse_directory
  72. assert_equal 0, @repository.changesets.count
  73. @repository.fetch_changesets
  74. @project.reload
  75. assert_equal NUM_REV, @repository.changesets.count
  76. get :show, :params => {
  77. :id => PRJ_ID,
  78. :repository_id => @repository.id,
  79. :path => repository_path_hash(['images'])[:param]
  80. }
  81. assert_response :success
  82. assert_select 'table.entries tbody' do
  83. assert_select 'tr', 3
  84. assert_select 'tr.file td.filename a', :text => 'add.png'
  85. assert_select 'tr.file td.filename a', :text => 'delete.png'
  86. assert_select 'tr.file td.filename a', :text => 'edit.png'
  87. end
  88. end
  89. def test_browse_at_given_revision
  90. assert_equal 0, @repository.changesets.count
  91. @repository.fetch_changesets
  92. @project.reload
  93. assert_equal NUM_REV, @repository.changesets.count
  94. get :show, :params => {
  95. :id => PRJ_ID,
  96. :repository_id => @repository.id,
  97. :path => repository_path_hash(['images'])[:param],
  98. :rev => 1
  99. }
  100. assert_response :success
  101. assert_select 'table.entries tbody' do
  102. assert_select 'tr', 2
  103. assert_select 'tr.file td.filename a', :text => 'delete.png'
  104. assert_select 'tr.file td.filename a', :text => 'edit.png'
  105. end
  106. end
  107. def test_entry
  108. assert_equal 0, @repository.changesets.count
  109. @repository.fetch_changesets
  110. @project.reload
  111. assert_equal NUM_REV, @repository.changesets.count
  112. get :entry, :params => {
  113. :id => PRJ_ID,
  114. :repository_id => @repository.id,
  115. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  116. }
  117. assert_response :success
  118. assert_select 'td.line-code', :text => /before_filter/, :count => 0
  119. end
  120. def test_entry_at_given_revision
  121. # changesets must be loaded
  122. assert_equal 0, @repository.changesets.count
  123. @repository.fetch_changesets
  124. @project.reload
  125. assert_equal NUM_REV, @repository.changesets.count
  126. get :entry, :params => {
  127. :id => PRJ_ID,
  128. :repository_id => @repository.id,
  129. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  130. :rev => 2
  131. }
  132. assert_response :success
  133. # this line was removed in r3
  134. assert_select 'td.line-code', :text => /before_filter/
  135. end
  136. def test_entry_not_found
  137. assert_equal 0, @repository.changesets.count
  138. @repository.fetch_changesets
  139. @project.reload
  140. assert_equal NUM_REV, @repository.changesets.count
  141. get :entry, :params => {
  142. :id => PRJ_ID,
  143. :repository_id => @repository.id,
  144. :path => repository_path_hash(['sources', 'zzz.c'])[:param]
  145. }
  146. assert_select 'p#errorExplanation', :text => /The entry or revision was not found in the repository/
  147. end
  148. def test_entry_download
  149. assert_equal 0, @repository.changesets.count
  150. @repository.fetch_changesets
  151. @project.reload
  152. assert_equal NUM_REV, @repository.changesets.count
  153. get :entry, :params => {
  154. :id => PRJ_ID,
  155. :repository_id => @repository.id,
  156. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  157. :format => 'raw'
  158. }
  159. assert_response :success
  160. end
  161. def test_directory_entry
  162. assert_equal 0, @repository.changesets.count
  163. @repository.fetch_changesets
  164. @project.reload
  165. assert_equal NUM_REV, @repository.changesets.count
  166. get :entry, :params => {
  167. :id => PRJ_ID,
  168. :repository_id => @repository.id,
  169. :path => repository_path_hash(['sources'])[:param]
  170. }
  171. assert_response :success
  172. assert_select 'table.entries tbody'
  173. end
  174. def test_diff
  175. assert_equal 0, @repository.changesets.count
  176. @repository.fetch_changesets
  177. @project.reload
  178. assert_equal NUM_REV, @repository.changesets.count
  179. ['inline', 'sbs'].each do |dt|
  180. get :diff, :params => {
  181. :id => PRJ_ID,
  182. :repository_id => @repository.id,
  183. :rev => 3,
  184. :type => dt
  185. }
  186. assert_response :success
  187. assert_select 'td.line-code.diff_out', :text => /before_filter :require_login/
  188. assert_select 'td.line-code.diff_in', :text => /with one change/
  189. end
  190. end
  191. def test_diff_new_files
  192. assert_equal 0, @repository.changesets.count
  193. @repository.fetch_changesets
  194. @project.reload
  195. assert_equal NUM_REV, @repository.changesets.count
  196. ['inline', 'sbs'].each do |dt|
  197. get :diff, :params => {
  198. :id => PRJ_ID,
  199. :repository_id => @repository.id,
  200. :rev => 1,
  201. :type => dt
  202. }
  203. assert_response :success
  204. assert_select 'td.line-code.diff_in', :text => /watched.remove_watcher/
  205. assert_select 'th.filename', :text => /test\/README/
  206. assert_select 'th.filename', :text => /test\/images\/delete.png/
  207. assert_select 'th.filename', :text => /test\/images\/edit.png/
  208. assert_select 'th.filename', :text => /test\/sources\/watchers_controller.rb/
  209. end
  210. end
  211. def test_annotate
  212. assert_equal 0, @repository.changesets.count
  213. @repository.fetch_changesets
  214. @project.reload
  215. assert_equal NUM_REV, @repository.changesets.count
  216. get :annotate, :params => {
  217. :id => PRJ_ID,
  218. :repository_id => @repository.id,
  219. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  220. }
  221. assert_response :success
  222. # 1.1 line
  223. assert_select 'tr' do
  224. assert_select 'th.line-num', :text => '21'
  225. assert_select 'td.revision', :text => /1.1/
  226. assert_select 'td.author', :text => /LANG/
  227. end
  228. # 1.2 line
  229. assert_select 'tr' do
  230. assert_select 'th.line-num', :text => '32'
  231. assert_select 'td.revision', :text => /1.2/
  232. assert_select 'td.author', :text => /LANG/
  233. end
  234. end
  235. def test_destroy_valid_repository
  236. @request.session[:user_id] = 1 # admin
  237. assert_equal 0, @repository.changesets.count
  238. @repository.fetch_changesets
  239. @project.reload
  240. assert_equal NUM_REV, @repository.changesets.count
  241. assert_difference 'Repository.count', -1 do
  242. delete :destroy, :params => {
  243. :id => @repository.id
  244. }
  245. end
  246. assert_response 302
  247. @project.reload
  248. assert_nil @project.repository
  249. end
  250. def test_destroy_invalid_repository
  251. @request.session[:user_id] = 1 # admin
  252. @project.repository.destroy
  253. @repository = Repository::Cvs.create!(
  254. :project => Project.find(PRJ_ID),
  255. :root_url => "/invalid",
  256. :url => MODULE_NAME,
  257. :log_encoding => 'UTF-8'
  258. )
  259. @repository.fetch_changesets
  260. @project.reload
  261. assert_equal 0, @repository.changesets.count
  262. assert_difference 'Repository.count', -1 do
  263. delete :destroy, :params => {
  264. :id => @repository.id
  265. }
  266. end
  267. assert_response 302
  268. @project.reload
  269. assert_nil @project.repository
  270. end
  271. else
  272. puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
  273. def test_fake; assert true end
  274. end
  275. end