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_subversion_controller_test.rb 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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 RepositoriesSubversionControllerTest < Redmine::RepositoryControllerTest
  19. tests RepositoriesController
  20. fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules,
  21. :repositories, :issues, :issue_statuses, :changesets, :changes,
  22. :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
  23. PRJ_ID = 3
  24. NUM_REV = 11
  25. def setup
  26. super
  27. Setting.default_language = 'en'
  28. User.current = nil
  29. @project = Project.find(PRJ_ID)
  30. @repository = Repository::Subversion.create(:project => @project,
  31. :url => self.class.subversion_repository_url)
  32. assert @repository
  33. end
  34. if repository_configured?('subversion')
  35. def test_new
  36. @request.session[:user_id] = 1
  37. @project.repository.destroy
  38. get :new, :params => {
  39. :project_id => 'subproject1',
  40. :repository_scm => 'Subversion'
  41. }
  42. assert_response :success
  43. assert_select 'select[name=?]', 'repository_scm' do
  44. assert_select 'option[value=?][selected=selected]', 'Subversion'
  45. end
  46. end
  47. def test_show
  48. assert_equal 0, @repository.changesets.count
  49. @repository.fetch_changesets
  50. @project.reload
  51. assert_equal NUM_REV, @repository.changesets.count
  52. get :show, :params => {
  53. :id => PRJ_ID
  54. }
  55. assert_response :success
  56. assert_select 'table.entries tbody' do
  57. assert_select 'tr', 1
  58. assert_select 'tr.dir td.filename a', :text => 'subversion_test'
  59. assert_select 'tr.dir td.filename a[href=?]', "/projects/subproject1/repository/#{@repository.id}/show/subversion_test"
  60. end
  61. assert_select 'table.changesets tbody' do
  62. assert_select 'tr', 10
  63. assert_select 'tr td.id a', :text => '11'
  64. end
  65. assert_select 'input[name=rev]'
  66. assert_select 'a', :text => 'Statistics'
  67. assert_select 'a', :text => 'Atom'
  68. assert_select 'a[href=?]', "/projects/subproject1/repository/#{@repository.id}", :text => 'root'
  69. end
  70. def test_show_non_default
  71. Repository::Subversion.create(:project => @project,
  72. :url => self.class.subversion_repository_url,
  73. :is_default => false, :identifier => 'svn')
  74. get :show, :params => {
  75. :id => PRJ_ID,
  76. :repository_id => 'svn'
  77. }
  78. assert_response :success
  79. assert_select 'tr.dir a[href="/projects/subproject1/repository/svn/show/subversion_test"]'
  80. # Repository menu should link to the main repo
  81. assert_select '#main-menu a[href="/projects/subproject1/repository"]'
  82. end
  83. def test_browse_directory
  84. assert_equal 0, @repository.changesets.count
  85. @repository.fetch_changesets
  86. @project.reload
  87. assert_equal NUM_REV, @repository.changesets.count
  88. get :show, :params => {
  89. :id => PRJ_ID,
  90. :repository_id => @repository.id,
  91. :path => repository_path_hash(['subversion_test'])[:param]
  92. }
  93. assert_response :success
  94. assert_select 'table.entries tbody' do
  95. assert_select 'tr', 5
  96. assert_select 'tr.dir td.filename a', :text => '[folder_with_brackets]'
  97. assert_select 'tr.dir td.filename a', :text => 'folder'
  98. assert_select 'tr.file td.filename a', :text => '.project'
  99. assert_select 'tr.file td.filename a', :text => 'helloworld.c'
  100. assert_select 'tr.file td.filename a', :text => 'textfile.txt'
  101. end
  102. assert_select 'a.text-x-c', :text => 'helloworld.c'
  103. end
  104. def test_browse_at_given_revision
  105. assert_equal 0, @repository.changesets.count
  106. @repository.fetch_changesets
  107. @project.reload
  108. assert_equal NUM_REV, @repository.changesets.count
  109. get :show, :params => {
  110. :id => PRJ_ID,
  111. :repository_id => @repository.id,
  112. :path => repository_path_hash(['subversion_test'])[:param],
  113. :rev => 4
  114. }
  115. assert_response :success
  116. assert_select 'table.entries tbody' do
  117. assert_select 'tr', 5
  118. assert_select 'tr.dir td.filename a', :text => 'folder'
  119. assert_select 'tr.file td.filename a', :text => '.project'
  120. assert_select 'tr.file td.filename a', :text => 'helloworld.c'
  121. assert_select 'tr.file td.filename a', :text => 'helloworld.rb'
  122. assert_select 'tr.file td.filename a', :text => 'textfile.txt'
  123. end
  124. end
  125. def test_file_changes
  126. assert_equal 0, @repository.changesets.count
  127. @repository.fetch_changesets
  128. @project.reload
  129. assert_equal NUM_REV, @repository.changesets.count
  130. get :changes, :params => {
  131. :id => PRJ_ID,
  132. :repository_id => @repository.id,
  133. :path => repository_path_hash(['subversion_test', 'folder', 'helloworld.rb'])[:param]
  134. }
  135. assert_response :success
  136. assert_select 'table.changesets tbody' do
  137. assert_select 'tr', 3
  138. assert_select 'tr td.id a', :text => '6'
  139. assert_select 'tr td.id a', :text => '3'
  140. assert_select 'tr td.id a', :text => '2'
  141. end
  142. # svn properties displayed with svn >= 1.5 only
  143. if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
  144. assert_select 'ul li' do
  145. assert_select 'b', :text => 'svn:eol-style'
  146. assert_select 'span', :text => 'native'
  147. end
  148. end
  149. end
  150. def test_directory_changes
  151. assert_equal 0, @repository.changesets.count
  152. @repository.fetch_changesets
  153. @project.reload
  154. assert_equal NUM_REV, @repository.changesets.count
  155. get :changes, :params => {
  156. :id => PRJ_ID,
  157. :repository_id => @repository.id,
  158. :path => repository_path_hash(['subversion_test', 'folder'])[:param]
  159. }
  160. assert_response :success
  161. assert_select 'table.changesets tbody' do
  162. assert_select 'tr', 6
  163. assert_select 'tr td.id a', :text => '10'
  164. assert_select 'tr td.id a', :text => '9'
  165. assert_select 'tr td.id a', :text => '7'
  166. assert_select 'tr td.id a', :text => '6'
  167. assert_select 'tr td.id a', :text => '5'
  168. assert_select 'tr td.id a', :text => '2'
  169. end
  170. end
  171. def test_entry
  172. assert_equal 0, @repository.changesets.count
  173. @repository.fetch_changesets
  174. @project.reload
  175. assert_equal NUM_REV, @repository.changesets.count
  176. get :entry, :params => {
  177. :id => PRJ_ID,
  178. :repository_id => @repository.id,
  179. :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
  180. }
  181. assert_response :success
  182. assert_select 'h2 a', :text => 'subversion_test'
  183. assert_select 'h2 a', :text => 'helloworld.c'
  184. end
  185. def test_entry_should_show_other_if_too_big
  186. assert_equal 0, @repository.changesets.count
  187. @repository.fetch_changesets
  188. @project.reload
  189. assert_equal NUM_REV, @repository.changesets.count
  190. # no files in the test repo is larger than 1KB...
  191. with_settings :file_max_size_displayed => 0 do
  192. get :entry, :params => {
  193. :id => PRJ_ID,
  194. :repository_id => @repository.id,
  195. :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
  196. }
  197. assert_response :success
  198. assert_equal 'text/html', @response.content_type
  199. assert_select 'p.nodata'
  200. end
  201. end
  202. def test_entry_should_display_images
  203. get :entry, :params => {
  204. :id => PRJ_ID,
  205. :repository_id => @repository.id,
  206. :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'rubylogo.gif'])[:param]
  207. }
  208. assert_response :success
  209. assert_select 'img[src=?]', "/projects/subproject1/repository/#{@repository.id}/raw/subversion_test/folder/subfolder/rubylogo.gif"
  210. end
  211. def test_entry_at_given_revision
  212. assert_equal 0, @repository.changesets.count
  213. @repository.fetch_changesets
  214. @project.reload
  215. assert_equal NUM_REV, @repository.changesets.count
  216. get :entry, :params => {
  217. :id => PRJ_ID,
  218. :repository_id => @repository.id,
  219. :path => repository_path_hash(['subversion_test', 'helloworld.rb'])[:param],
  220. :rev => 2
  221. }
  222. assert_response :success
  223. # this line was removed in r3 and file was moved in r6
  224. assert_select 'td.line-code', :text => /Here's the code/
  225. end
  226. def test_entry_not_found
  227. assert_equal 0, @repository.changesets.count
  228. @repository.fetch_changesets
  229. @project.reload
  230. assert_equal NUM_REV, @repository.changesets.count
  231. get :entry, :params => {
  232. :id => PRJ_ID,
  233. :repository_id => @repository.id,
  234. :path => repository_path_hash(['subversion_test', 'zzz.c'])[:param]
  235. }
  236. assert_select 'p#errorExplanation', :text => /The entry or revision was not found in the repository/
  237. end
  238. def test_entry_download
  239. assert_equal 0, @repository.changesets.count
  240. @repository.fetch_changesets
  241. @project.reload
  242. assert_equal NUM_REV, @repository.changesets.count
  243. get :raw, :params => {
  244. :id => PRJ_ID,
  245. :repository_id => @repository.id,
  246. :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
  247. }
  248. assert_response :success
  249. assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
  250. end
  251. def test_directory_entry
  252. assert_equal 0, @repository.changesets.count
  253. @repository.fetch_changesets
  254. @project.reload
  255. assert_equal NUM_REV, @repository.changesets.count
  256. get :entry, :params => {
  257. :id => PRJ_ID,
  258. :repository_id => @repository.id,
  259. :path => repository_path_hash(['subversion_test', 'folder'])[:param]
  260. }
  261. assert_response :success
  262. assert_select 'h2 a', :text => 'subversion_test'
  263. assert_select 'h2 a', :text => 'folder'
  264. end
  265. # TODO: this test needs fixtures.
  266. def test_revision
  267. get :revision, :params => {
  268. :id => 1,
  269. :repository_id => 10,
  270. :rev => 2
  271. }
  272. assert_response :success
  273. assert_select 'ul' do
  274. assert_select 'li' do
  275. # link to the entry at rev 2
  276. assert_select 'a[href=?]', '/projects/ecookbook/repository/10/revisions/2/entry/test/some/path/in/the/repo', :text => 'repo'
  277. # link to partial diff
  278. assert_select 'a[href=?]', '/projects/ecookbook/repository/10/revisions/2/diff/test/some/path/in/the/repo'
  279. end
  280. end
  281. end
  282. def test_invalid_revision
  283. assert_equal 0, @repository.changesets.count
  284. @repository.fetch_changesets
  285. @project.reload
  286. assert_equal NUM_REV, @repository.changesets.count
  287. get :revision, :params => {
  288. :id => PRJ_ID,
  289. :repository_id => @repository.id,
  290. :rev => 'something_weird'
  291. }
  292. assert_response 404
  293. assert_select_error /was not found/
  294. end
  295. def test_invalid_revision_diff
  296. get :diff, :params => {
  297. :id => PRJ_ID,
  298. :repository_id => @repository.id,
  299. :rev => '1',
  300. :rev_to => 'something_weird'
  301. }
  302. assert_response 404
  303. assert_select_error /was not found/
  304. end
  305. def test_empty_revision
  306. assert_equal 0, @repository.changesets.count
  307. @repository.fetch_changesets
  308. @project.reload
  309. assert_equal NUM_REV, @repository.changesets.count
  310. ['', ' ', nil].each do |r|
  311. get :revision, :params => {
  312. :id => PRJ_ID,
  313. :repository_id => @repository.id,
  314. :rev => r
  315. }
  316. assert_response 404
  317. assert_select_error /was not found/
  318. end
  319. end
  320. # TODO: this test needs fixtures.
  321. def test_revision_with_repository_pointing_to_a_subdirectory
  322. r = Project.find(1).repository
  323. # Changes repository url to a subdirectory
  324. r.update_attribute :url, (r.url + '/test/some')
  325. get :revision, :params => {
  326. :id => 1,
  327. :repository_id => 10,
  328. :rev => 2
  329. }
  330. assert_response :success
  331. assert_select 'ul' do
  332. assert_select 'li' do
  333. # link to the entry at rev 2
  334. assert_select 'a[href=?]', '/projects/ecookbook/repository/10/revisions/2/entry/path/in/the/repo', :text => 'repo'
  335. # link to partial diff
  336. assert_select 'a[href=?]', '/projects/ecookbook/repository/10/revisions/2/diff/path/in/the/repo'
  337. end
  338. end
  339. end
  340. def test_revision_diff
  341. assert_equal 0, @repository.changesets.count
  342. @repository.fetch_changesets
  343. @project.reload
  344. assert_equal NUM_REV, @repository.changesets.count
  345. ['inline', 'sbs'].each do |dt|
  346. get :diff, :params => {
  347. :id => PRJ_ID,
  348. :repository_id => @repository.id,
  349. :rev => 3,
  350. :type => dt
  351. }
  352. assert_response :success
  353. assert_select 'h2', :text => /Revision 3/
  354. assert_select 'th.filename', :text => 'subversion_test/textfile.txt'
  355. end
  356. end
  357. def test_revision_diff_raw_format
  358. assert_equal 0, @repository.changesets.count
  359. @repository.fetch_changesets
  360. @project.reload
  361. assert_equal NUM_REV, @repository.changesets.count
  362. get :diff, :params => {
  363. :id => PRJ_ID,
  364. :repository_id => @repository.id,
  365. :rev => 5,
  366. :format => 'diff'
  367. }
  368. assert_response :success
  369. assert_equal 'text/x-patch', @response.content_type
  370. assert_equal 'Index: subversion_test/folder/greeter.rb', @response.body.split(/\r?\n/).first
  371. end
  372. def test_directory_diff
  373. assert_equal 0, @repository.changesets.count
  374. @repository.fetch_changesets
  375. @project.reload
  376. assert_equal NUM_REV, @repository.changesets.count
  377. ['inline', 'sbs'].each do |dt|
  378. get :diff, :params => {
  379. :id => PRJ_ID,
  380. :repository_id => @repository.id,
  381. :rev => 6,
  382. :rev_to => 2,
  383. :path => repository_path_hash(['subversion_test', 'folder'])[:param],
  384. :type => dt
  385. }
  386. assert_response :success
  387. assert_select 'h2', :text => /2:6/
  388. # 2 files modified
  389. assert_select 'table.filecontent', 2
  390. assert_select 'table.filecontent thead th.filename', :text => 'greeter.rb'
  391. assert_select 'table.filecontent thead th.filename', :text => 'helloworld.rb'
  392. end
  393. end
  394. def test_annotate
  395. assert_equal 0, @repository.changesets.count
  396. @repository.fetch_changesets
  397. @project.reload
  398. assert_equal NUM_REV, @repository.changesets.count
  399. get :annotate, :params => {
  400. :id => PRJ_ID,
  401. :repository_id => @repository.id,
  402. :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
  403. }
  404. assert_response :success
  405. assert_select 'tr' do
  406. assert_select 'th.line-num', :text => '1'
  407. assert_select 'td.revision', :text => '4'
  408. assert_select 'td.author', :text => 'jp'
  409. assert_select 'td', :text => /stdio.h/
  410. end
  411. # Same revision
  412. assert_select 'tr' do
  413. assert_select 'th.line-num', :text => '2'
  414. assert_select 'td.revision', :text => ''
  415. assert_select 'td.author', :text => ''
  416. end
  417. end
  418. def test_annotate_at_given_revision
  419. assert_equal 0, @repository.changesets.count
  420. @repository.fetch_changesets
  421. @project.reload
  422. assert_equal NUM_REV, @repository.changesets.count
  423. get :annotate, :params => {
  424. :id => PRJ_ID,
  425. :repository_id => @repository.id,
  426. :rev => 8,
  427. :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
  428. }
  429. assert_response :success
  430. assert_select 'h2', :text => /@ 8/
  431. end
  432. def test_destroy_valid_repository
  433. @request.session[:user_id] = 1 # admin
  434. assert_equal 0, @repository.changesets.count
  435. @repository.fetch_changesets
  436. assert_equal NUM_REV, @repository.changesets.count
  437. assert_difference 'Repository.count', -1 do
  438. delete :destroy, :params => {
  439. :id => @repository.id
  440. }
  441. end
  442. assert_response 302
  443. @project.reload
  444. assert_nil @project.repository
  445. end
  446. def test_destroy_invalid_repository
  447. @request.session[:user_id] = 1 # admin
  448. @project.repository.destroy
  449. @repository = Repository::Subversion.create!(
  450. :project => @project,
  451. :url => "file:///invalid")
  452. @repository.fetch_changesets
  453. assert_equal 0, @repository.changesets.count
  454. assert_difference 'Repository.count', -1 do
  455. delete :destroy, :params => {
  456. :id => @repository.id
  457. }
  458. end
  459. assert_response 302
  460. @project.reload
  461. assert_nil @project.repository
  462. end
  463. else
  464. puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
  465. def test_fake; assert true end
  466. end
  467. end