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_bazaar_controller_test.rb 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2023 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 RepositoriesBazaarControllerTest < Redmine::RepositoryControllerTest
  20. tests RepositoriesController
  21. fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
  22. :repositories, :enabled_modules
  23. REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
  24. REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
  25. PRJ_ID = 3
  26. def setup
  27. super
  28. User.current = nil
  29. @project = Project.find(PRJ_ID)
  30. @repository =
  31. Repository::Bazaar.create(
  32. :project => @project,
  33. :url => REPOSITORY_PATH_TRUNK,
  34. :log_encoding => 'UTF-8'
  35. )
  36. assert @repository
  37. end
  38. if File.directory?(REPOSITORY_PATH)
  39. def test_get_new
  40. @request.session[:user_id] = 1
  41. @project.repository.destroy
  42. get(
  43. :new,
  44. :params => {
  45. :project_id => 'subproject1',
  46. :repository_scm => 'Bazaar'
  47. }
  48. )
  49. assert_response :success
  50. assert_select 'select[name=?]', 'repository_scm' do
  51. assert_select 'option[value=?][selected=selected]', 'Bazaar'
  52. end
  53. end
  54. def test_browse_root
  55. get(
  56. :show,
  57. :params => {
  58. :id => PRJ_ID
  59. }
  60. )
  61. assert_response :success
  62. assert_select 'table.entries tbody' do
  63. assert_select 'tr', 2
  64. assert_select 'tr.dir td.filename a', :text => 'directory'
  65. assert_select 'tr.file td.filename a', :text => 'doc-mkdir.txt'
  66. end
  67. end
  68. def test_browse_directory
  69. get(
  70. :show,
  71. :params => {
  72. :id => PRJ_ID,
  73. :repository_id => @repository.id,
  74. :path => repository_path_hash(['directory'])[:param]
  75. }
  76. )
  77. assert_response :success
  78. assert_select 'table.entries tbody' do
  79. assert_select 'tr', 3
  80. assert_select 'tr.file td.filename a', :text => 'doc-ls.txt'
  81. assert_select 'tr.file td.filename a', :text => 'document.txt'
  82. assert_select 'tr.file td.filename a', :text => 'edit.png'
  83. end
  84. end
  85. def test_browse_at_given_revision
  86. get(
  87. :show,
  88. :params => {
  89. :id => PRJ_ID,
  90. :repository_id => @repository.id,
  91. :path => repository_path_hash([])[:param],
  92. :rev => 3
  93. }
  94. )
  95. assert_response :success
  96. assert_select 'table.entries tbody' do
  97. assert_select 'tr', 4
  98. assert_select 'tr.dir td.filename a', :text => 'directory'
  99. assert_select 'tr.file td.filename a', :text => 'doc-deleted.txt'
  100. assert_select 'tr.file td.filename a', :text => 'doc-ls.txt'
  101. assert_select 'tr.file td.filename a', :text => 'doc-mkdir.txt'
  102. end
  103. end
  104. def test_changes
  105. get(
  106. :changes,
  107. :params => {
  108. :id => PRJ_ID,
  109. :repository_id => @repository.id,
  110. :path => repository_path_hash(['doc-mkdir.txt'])[:param]
  111. }
  112. )
  113. assert_response :success
  114. assert_select 'h2', :text => /doc-mkdir.txt/
  115. end
  116. def test_entry_show
  117. get(
  118. :entry,
  119. :params => {
  120. :id => PRJ_ID,
  121. :repository_id => @repository.id,
  122. :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param]
  123. }
  124. )
  125. assert_response :success
  126. # Line 19
  127. assert_select 'tr#L29 td.line-code', :text => /Show help message/
  128. end
  129. def test_entry_download
  130. get(
  131. :entry,
  132. :params => {
  133. :id => PRJ_ID,
  134. :repository_id => @repository.id,
  135. :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param],
  136. :format => 'raw'
  137. }
  138. )
  139. assert_response :success
  140. # File content
  141. assert @response.body.include?('Show help message')
  142. end
  143. def test_directory_entry
  144. get(
  145. :entry,
  146. :params => {
  147. :id => PRJ_ID,
  148. :repository_id => @repository.id,
  149. :path => repository_path_hash(['directory'])[:param]
  150. }
  151. )
  152. assert_response :success
  153. assert_select 'table.entries tbody'
  154. end
  155. def test_diff
  156. # Full diff of changeset 3
  157. ['inline', 'sbs'].each do |dt|
  158. get(
  159. :diff,
  160. :params => {
  161. :id => PRJ_ID,
  162. :repository_id => @repository.id,
  163. :rev => 3,
  164. :type => dt
  165. }
  166. )
  167. assert_response :success
  168. # Line 11 removed
  169. assert_select 'th.line-num[data-txt=11] ~ td.diff_out', :text => /Display more information/
  170. end
  171. end
  172. def test_annotate
  173. get(
  174. :annotate,
  175. :params => {
  176. :id => PRJ_ID,
  177. :repository_id => @repository.id,
  178. :path => repository_path_hash(['doc-mkdir.txt'])[:param]
  179. }
  180. )
  181. assert_response :success
  182. assert_select "th.line-num" do
  183. assert_select 'a[data-txt=?]', '2'
  184. assert_select "+ td.revision" do
  185. assert_select "a", :text => '3'
  186. assert_select "+ td.author", :text => "jsmith@" do
  187. assert_select "+ td",
  188. :text => "Main purpose:"
  189. end
  190. end
  191. end
  192. end
  193. def test_annotate_author_escaping
  194. repository =
  195. Repository::Bazaar.create(
  196. :project => @project,
  197. :url => File.join(REPOSITORY_PATH, "author_escaping"),
  198. :identifier => 'author_escaping',
  199. :log_encoding => 'UTF-8'
  200. )
  201. assert repository
  202. get(
  203. :annotate,
  204. :params => {
  205. :id => PRJ_ID,
  206. :repository_id => 'author_escaping',
  207. :path => repository_path_hash(['author-escaping-test.txt'])[:param]
  208. }
  209. )
  210. assert_response :success
  211. assert_select "th.line-num" do
  212. assert_select "a[data-txt=?]", '1'
  213. assert_select "+ td.revision" do
  214. assert_select "a", :text => '2'
  215. assert_select "+ td.author", :text => "test &" do
  216. assert_select "+ td",
  217. :text => "author escaping test"
  218. end
  219. end
  220. end
  221. end
  222. def test_annotate_author_non_ascii
  223. log_encoding = nil
  224. if Encoding.locale_charmap == "UTF-8" ||
  225. Encoding.locale_charmap == "ISO-8859-1"
  226. log_encoding = Encoding.locale_charmap
  227. end
  228. unless log_encoding.nil?
  229. repository =
  230. Repository::Bazaar.create(
  231. :project => @project,
  232. :url => File.join(REPOSITORY_PATH, "author_non_ascii"),
  233. :identifier => 'author_non_ascii',
  234. :log_encoding => log_encoding
  235. )
  236. assert repository
  237. get(
  238. :annotate,
  239. :params => {
  240. :id => PRJ_ID,
  241. :repository_id => 'author_non_ascii',
  242. :path => repository_path_hash(['author-non-ascii-test.txt'])[:param]
  243. }
  244. )
  245. assert_response :success
  246. assert_select "th.line-num" do
  247. assert_select 'a[data-txt=?]', '1'
  248. assert_select "+ td.revision" do
  249. assert_select "a", :text => '2'
  250. assert_select "+ td.author", :text => "test Ü" do
  251. assert_select "+ td",
  252. :text => "author non ASCII test"
  253. end
  254. end
  255. end
  256. end
  257. end
  258. def test_destroy_valid_repository
  259. @request.session[:user_id] = 1 # admin
  260. assert_equal 0, @repository.changesets.count
  261. @repository.fetch_changesets
  262. assert @repository.changesets.count > 0
  263. assert_difference 'Repository.count', -1 do
  264. delete(
  265. :destroy,
  266. :params => {
  267. :id => @repository.id
  268. }
  269. )
  270. end
  271. assert_response 302
  272. @project.reload
  273. assert_nil @project.repository
  274. end
  275. def test_destroy_invalid_repository
  276. @request.session[:user_id] = 1 # admin
  277. @project.repository.destroy
  278. @repository =
  279. Repository::Bazaar.create!(
  280. :project => @project,
  281. :url => "/invalid",
  282. :log_encoding => 'UTF-8'
  283. )
  284. @repository.fetch_changesets
  285. @repository.reload
  286. assert_equal 0, @repository.changesets.count
  287. assert_difference 'Repository.count', -1 do
  288. delete(
  289. :destroy,
  290. :params => {
  291. :id => @repository.id
  292. }
  293. )
  294. end
  295. assert_response 302
  296. @project.reload
  297. assert_nil @project.repository
  298. end
  299. else
  300. puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
  301. def test_fake; assert true end
  302. end
  303. end