選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

repositories_mercurial_controller_test.rb 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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 RepositoriesMercurialControllerTest < 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/mercurial_repository').to_s
  23. CHAR_1_HEX = "\xc3\x9c"
  24. PRJ_ID = 3
  25. NUM_REV = 34
  26. ruby19_non_utf8_pass = Encoding.default_external.to_s != 'UTF-8'
  27. def setup
  28. super
  29. User.current = nil
  30. @project = Project.find(PRJ_ID)
  31. @repository = Repository::Mercurial.create(
  32. :project => @project,
  33. :url => REPOSITORY_PATH,
  34. :path_encoding => 'ISO-8859-1'
  35. )
  36. assert @repository
  37. @diff_c_support = true
  38. @char_1 = CHAR_1_HEX.dup.force_encoding('UTF-8')
  39. @tag_char_1 = "tag-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
  40. @branch_char_0 = "branch-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
  41. @branch_char_1 = "branch-#{CHAR_1_HEX}-01".force_encoding('UTF-8')
  42. end
  43. if ruby19_non_utf8_pass
  44. puts "TODO: Mercurial functional test fails " +
  45. "when Encoding.default_external is not UTF-8. " +
  46. "Current value is '#{Encoding.default_external.to_s}'"
  47. def test_fake; assert true end
  48. elsif File.directory?(REPOSITORY_PATH)
  49. def test_get_new
  50. @request.session[:user_id] = 1
  51. @project.repository.destroy
  52. get :new, :params => {
  53. :project_id => 'subproject1',
  54. :repository_scm => 'Mercurial'
  55. }
  56. assert_response :success
  57. assert_select 'select[name=?]', 'repository_scm' do
  58. assert_select 'option[value=?][selected=selected]', 'Mercurial'
  59. end
  60. end
  61. def test_show_root
  62. assert_equal 0, @repository.changesets.count
  63. @repository.fetch_changesets
  64. @project.reload
  65. assert_equal NUM_REV, @repository.changesets.count
  66. get :show, :params => {
  67. :id => PRJ_ID
  68. }
  69. assert_response :success
  70. assert_select 'table.entries tbody' do
  71. assert_select 'tr', 4
  72. assert_select 'tr.dir td.filename a', :text => 'images'
  73. assert_select 'tr.dir td.filename a', :text => 'sources'
  74. assert_select 'tr.file td.filename a', :text => '.hgtags'
  75. assert_select 'tr.file td.filename a', :text => 'README'
  76. end
  77. assert_select 'table.changesets tbody' do
  78. assert_select 'tr'
  79. end
  80. end
  81. def test_show_directory
  82. assert_equal 0, @repository.changesets.count
  83. @repository.fetch_changesets
  84. @project.reload
  85. assert_equal NUM_REV, @repository.changesets.count
  86. get :show, :params => {
  87. :id => PRJ_ID,
  88. :repository_id => @repository.id,
  89. :path => repository_path_hash(['images'])[:param]
  90. }
  91. assert_response :success
  92. assert_select 'table.entries tbody' do
  93. assert_select 'tr', 2
  94. assert_select 'tr.file td.filename a', :text => 'delete.png'
  95. assert_select 'tr.file td.filename a', :text => 'edit.png'
  96. end
  97. assert_select 'table.changesets tbody' do
  98. assert_select 'tr'
  99. end
  100. end
  101. def test_show_at_given_revision
  102. assert_equal 0, @repository.changesets.count
  103. @repository.fetch_changesets
  104. @project.reload
  105. assert_equal NUM_REV, @repository.changesets.count
  106. [0, '0', '0885933ad4f6'].each do |r1|
  107. get :show, :params => {
  108. :id => PRJ_ID,
  109. :repository_id => @repository.id,
  110. :path => repository_path_hash(['images'])[:param],
  111. :rev => r1
  112. }
  113. assert_response :success
  114. assert_select 'table.entries tbody' do
  115. assert_select 'tr', 1
  116. assert_select 'tr.file td.filename a', :text => 'delete.png'
  117. end
  118. assert_select 'table.changesets tbody' do
  119. assert_select 'tr'
  120. end
  121. end
  122. end
  123. def test_show_directory_sql_escape_percent
  124. assert_equal 0, @repository.changesets.count
  125. @repository.fetch_changesets
  126. @project.reload
  127. assert_equal NUM_REV, @repository.changesets.count
  128. [13, '13', '3a330eb32958'].each do |r1|
  129. get :show, :params => {
  130. :id => PRJ_ID,
  131. :repository_id => @repository.id,
  132. :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param],
  133. :rev => r1
  134. }
  135. assert_response :success
  136. assert_select 'table.entries tbody' do
  137. assert_select 'tr', 2
  138. assert_select 'tr.file td.filename a', :text => 'percent%file1.txt'
  139. assert_select 'tr.file td.filename a', :text => 'percentfile1.txt'
  140. end
  141. assert_select 'table.changesets tbody' do
  142. assert_select 'tr td.id a', :text => /^13:/
  143. assert_select 'tr td.id a', :text => /^11:/
  144. assert_select 'tr td.id a', :text => /^10:/
  145. assert_select 'tr td.id a', :text => /^9:/
  146. end
  147. end
  148. end
  149. def test_show_directory_latin_1_path
  150. assert_equal 0, @repository.changesets.count
  151. @repository.fetch_changesets
  152. @project.reload
  153. assert_equal NUM_REV, @repository.changesets.count
  154. [21, '21', 'adf805632193'].each do |r1|
  155. get :show, :params => {
  156. :id => PRJ_ID,
  157. :repository_id => @repository.id,
  158. :path => repository_path_hash(['latin-1-dir'])[:param],
  159. :rev => r1
  160. }
  161. assert_response :success
  162. assert_select 'table.entries tbody' do
  163. assert_select 'tr', 4
  164. assert_select 'tr.file td.filename a', :text => "make-latin-1-file.rb"
  165. assert_select 'tr.file td.filename a', :text => "test-#{@char_1}-1.txt"
  166. assert_select 'tr.file td.filename a', :text => "test-#{@char_1}-2.txt"
  167. assert_select 'tr.file td.filename a', :text => "test-#{@char_1}.txt"
  168. end
  169. assert_select 'table.changesets tbody' do
  170. assert_select 'tr td.id a', :text => /^21:/
  171. assert_select 'tr td.id a', :text => /^20:/
  172. assert_select 'tr td.id a', :text => /^19:/
  173. assert_select 'tr td.id a', :text => /^18:/
  174. assert_select 'tr td.id a', :text => /^17:/
  175. end
  176. end
  177. end
  178. def show_should_show_branch_selection_form
  179. @repository.fetch_changesets
  180. @project.reload
  181. get :show, :params => {
  182. :id => PRJ_ID
  183. }
  184. assert_select 'form#revision_selector[action=?]', '/projects/subproject1/repository/show' do
  185. assert_select 'select[name=branch]' do
  186. assert_select 'option[value=?]', 'test-branch-01'
  187. end
  188. end
  189. end
  190. def test_show_branch
  191. assert_equal 0, @repository.changesets.count
  192. @repository.fetch_changesets
  193. @project.reload
  194. assert_equal NUM_REV, @repository.changesets.count
  195. [
  196. 'default',
  197. @branch_char_1,
  198. 'branch (1)[2]&,%.-3_4',
  199. @branch_char_0,
  200. 'test_branch.latin-1',
  201. 'test-branch-00',
  202. ].each do |bra|
  203. get :show, :params => {
  204. :id => PRJ_ID,
  205. :repository_id => @repository.id,
  206. :rev => bra
  207. }
  208. assert_response :success
  209. assert_select 'table.entries tbody tr'
  210. assert_select 'table.changesets tbody tr'
  211. end
  212. end
  213. def test_show_tag
  214. assert_equal 0, @repository.changesets.count
  215. @repository.fetch_changesets
  216. @project.reload
  217. assert_equal NUM_REV, @repository.changesets.count
  218. [
  219. @tag_char_1,
  220. 'tag_test.00',
  221. 'tag-init-revision'
  222. ].each do |tag|
  223. get :show, :params => {
  224. :id => PRJ_ID,
  225. :repository_id => @repository.id,
  226. :rev => tag
  227. }
  228. assert_response :success
  229. assert_select 'table.entries tbody tr'
  230. assert_select 'table.changesets tbody tr'
  231. end
  232. end
  233. def test_changes
  234. get :changes, :params => {
  235. :id => PRJ_ID,
  236. :repository_id => @repository.id,
  237. :path => repository_path_hash(['images', 'edit.png'])[:param]
  238. }
  239. assert_response :success
  240. assert_select 'h2', :text => /edit.png/
  241. end
  242. def test_entry_show
  243. get :entry, :params => {
  244. :id => PRJ_ID,
  245. :repository_id => @repository.id,
  246. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  247. }
  248. assert_response :success
  249. # Line 10
  250. assert_select 'tr#L10 td.line-code', :text => /WITHOUT ANY WARRANTY/
  251. end
  252. def test_entry_show_latin_1_path
  253. [21, '21', 'adf805632193'].each do |r1|
  254. get :entry, :params => {
  255. :id => PRJ_ID,
  256. :repository_id => @repository.id,
  257. :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
  258. :rev => r1
  259. }
  260. assert_response :success
  261. assert_select 'tr#L1 td.line-code', :text => /Mercurial is a distributed version control system/
  262. end
  263. end
  264. def test_entry_show_latin_1_contents
  265. with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
  266. [27, '27', '7bbf4c738e71'].each do |r1|
  267. get :entry, :params => {
  268. :id => PRJ_ID,
  269. :repository_id => @repository.id,
  270. :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
  271. :rev => r1
  272. }
  273. assert_response :success
  274. assert_select 'tr#L1 td.line-code', :text => /test-#{@char_1}.txt/
  275. end
  276. end
  277. end
  278. def test_entry_download
  279. get :entry, :params => {
  280. :id => PRJ_ID,
  281. :repository_id => @repository.id,
  282. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  283. :format => 'raw'
  284. }
  285. assert_response :success
  286. # File content
  287. assert @response.body.include?('WITHOUT ANY WARRANTY')
  288. end
  289. def test_entry_binary_force_download
  290. # TODO: add a binary file which is not an image to the test repo
  291. end
  292. def test_directory_entry
  293. get :entry, :params => {
  294. :id => PRJ_ID,
  295. :repository_id => @repository.id,
  296. :path => repository_path_hash(['sources'])[:param]
  297. }
  298. assert_response :success
  299. assert_select 'h2 a', :text => 'sources'
  300. assert_select 'table.entries tbody'
  301. end
  302. def test_diff
  303. assert_equal 0, @repository.changesets.count
  304. @repository.fetch_changesets
  305. @project.reload
  306. assert_equal NUM_REV, @repository.changesets.count
  307. [4, '4', 'def6d2f1254a'].each do |r1|
  308. # Full diff of changeset 4
  309. ['inline', 'sbs'].each do |dt|
  310. get :diff, :params => {
  311. :id => PRJ_ID,
  312. :repository_id => @repository.id,
  313. :rev => r1,
  314. :type => dt
  315. }
  316. assert_response :success
  317. if @diff_c_support
  318. # Line 22 removed
  319. assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/
  320. assert_select 'h2', :text => /4:def6d2f1254a/
  321. end
  322. end
  323. end
  324. end
  325. def test_diff_two_revs
  326. assert_equal 0, @repository.changesets.count
  327. @repository.fetch_changesets
  328. @project.reload
  329. assert_equal NUM_REV, @repository.changesets.count
  330. [2, '400bb8672109', '400', 400].each do |r1|
  331. [4, 'def6d2f1254a'].each do |r2|
  332. ['inline', 'sbs'].each do |dt|
  333. get :diff, :params => {
  334. :id => PRJ_ID,
  335. :repository_id => @repository.id,
  336. :rev => r1,
  337. :rev_to => r2,
  338. :type => dt
  339. }
  340. assert_response :success
  341. assert_select 'h2', :text => /4:def6d2f1254a 2:400bb8672109/
  342. end
  343. end
  344. end
  345. end
  346. def test_diff_latin_1_path
  347. with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
  348. [21, 'adf805632193'].each do |r1|
  349. ['inline', 'sbs'].each do |dt|
  350. get :diff, :params => {
  351. :id => PRJ_ID,
  352. :repository_id => @repository.id,
  353. :rev => r1,
  354. :type => dt
  355. }
  356. assert_response :success
  357. assert_select 'table' do
  358. assert_select 'thead th.filename', :text => /latin-1-dir\/test-#{@char_1}-2.txt/
  359. assert_select 'tbody td.diff_in', :text => /It is written in Python/
  360. end
  361. end
  362. end
  363. end
  364. end
  365. def test_diff_should_show_modified_filenames
  366. get :diff, :params => {
  367. :id => PRJ_ID,
  368. :repository_id => @repository.id,
  369. :rev => '400bb8672109',
  370. :type => 'inline'
  371. }
  372. assert_response :success
  373. assert_select 'th.filename', :text => 'sources/watchers_controller.rb'
  374. end
  375. def test_diff_should_show_deleted_filenames
  376. get :diff, :params => {
  377. :id => PRJ_ID,
  378. :repository_id => @repository.id,
  379. :rev => 'b3a615152df8',
  380. :type => 'inline'
  381. }
  382. assert_response :success
  383. assert_select 'th.filename', :text => 'sources/welcome_controller.rb'
  384. end
  385. def test_annotate
  386. get :annotate, :params => {
  387. :id => PRJ_ID,
  388. :repository_id => @repository.id,
  389. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  390. }
  391. assert_response :success
  392. # Line 22, revision 4:def6d2f1254a
  393. assert_select 'tr' do
  394. assert_select 'th.line-num', :text => '22'
  395. assert_select 'td.revision', :text => '4:def6d2f1254a'
  396. assert_select 'td.author', :text => 'jsmith'
  397. assert_select 'td', :text => /remove_watcher/
  398. end
  399. end
  400. def test_annotate_not_in_tip
  401. assert_equal 0, @repository.changesets.count
  402. @repository.fetch_changesets
  403. @project.reload
  404. assert_equal NUM_REV, @repository.changesets.count
  405. get :annotate, :params => {
  406. :id => PRJ_ID,
  407. :repository_id => @repository.id,
  408. :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param]
  409. }
  410. assert_response 404
  411. assert_select_error /was not found/
  412. end
  413. def test_annotate_at_given_revision
  414. assert_equal 0, @repository.changesets.count
  415. @repository.fetch_changesets
  416. @project.reload
  417. assert_equal NUM_REV, @repository.changesets.count
  418. [2, '400bb8672109', '400', 400].each do |r1|
  419. get :annotate, :params => {
  420. :id => PRJ_ID,
  421. :repository_id => @repository.id,
  422. :rev => r1,
  423. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  424. }
  425. assert_response :success
  426. assert_select 'h2', :text => /@ 2:400bb8672109/
  427. end
  428. end
  429. def test_annotate_latin_1_path
  430. [21, '21', 'adf805632193'].each do |r1|
  431. get :annotate, :params => {
  432. :id => PRJ_ID,
  433. :repository_id => @repository.id,
  434. :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
  435. :rev => r1
  436. }
  437. assert_response :success
  438. assert_select "th.line-num", :text => '1' do
  439. assert_select "+ td.revision" do
  440. assert_select "a", :text => '20:709858aafd1b'
  441. assert_select "+ td.author", :text => "jsmith" do
  442. assert_select "+ td",
  443. :text => "Mercurial is a distributed version control system."
  444. end
  445. end
  446. end
  447. end
  448. end
  449. def test_annotate_latin_1_contents
  450. with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
  451. [27, '7bbf4c738e71'].each do |r1|
  452. get :annotate, :params => {
  453. :id => PRJ_ID,
  454. :repository_id => @repository.id,
  455. :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
  456. :rev => r1
  457. }
  458. assert_select 'tr#L1 td.line-code', :text => /test-#{@char_1}.txt/
  459. end
  460. end
  461. end
  462. def test_revision
  463. assert_equal 0, @repository.changesets.count
  464. @repository.fetch_changesets
  465. @project.reload
  466. assert_equal NUM_REV, @repository.changesets.count
  467. ['1', '9d5b5b', '9d5b5b004199'].each do |r|
  468. with_settings :default_language => "en" do
  469. get :revision, :params => {
  470. :id => PRJ_ID,
  471. :repository_id => @repository.id,
  472. :rev => r
  473. }
  474. assert_response :success
  475. assert_select 'title',
  476. :text => 'Revision 1:9d5b5b004199 - Added 2 files and modified one. - eCookbook Subproject 1 - Redmine'
  477. end
  478. end
  479. end
  480. def test_empty_revision
  481. assert_equal 0, @repository.changesets.count
  482. @repository.fetch_changesets
  483. @project.reload
  484. assert_equal NUM_REV, @repository.changesets.count
  485. ['', ' ', nil].each do |r|
  486. get :revision, :params => {
  487. :id => PRJ_ID,
  488. :repository_id => @repository.id,
  489. :rev => r
  490. }
  491. assert_response 404
  492. assert_select_error /was not found/
  493. end
  494. end
  495. def test_destroy_valid_repository
  496. @request.session[:user_id] = 1 # admin
  497. assert_equal 0, @repository.changesets.count
  498. @repository.fetch_changesets
  499. assert_equal NUM_REV, @repository.changesets.count
  500. assert_difference 'Repository.count', -1 do
  501. delete :destroy, :params => {
  502. :id => @repository.id
  503. }
  504. end
  505. assert_response 302
  506. @project.reload
  507. assert_nil @project.repository
  508. end
  509. def test_destroy_invalid_repository
  510. @request.session[:user_id] = 1 # admin
  511. @project.repository.destroy
  512. @repository = Repository::Mercurial.create!(
  513. :project => Project.find(PRJ_ID),
  514. :url => "/invalid",
  515. :path_encoding => 'ISO-8859-1'
  516. )
  517. @repository.fetch_changesets
  518. assert_equal 0, @repository.changesets.count
  519. assert_difference 'Repository.count', -1 do
  520. delete :destroy, :params => {
  521. :id => @repository.id
  522. }
  523. end
  524. assert_response 302
  525. @project.reload
  526. assert_nil @project.repository
  527. end
  528. else
  529. puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
  530. def test_fake; assert true end
  531. end
  532. end