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

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