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

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