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

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