Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

repositories_cvs_controller_test.rb 10.0KB

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