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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 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:contains(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", :text => '2' do
  183. assert_select "+ td.revision" do
  184. assert_select "a", :text => '3'
  185. assert_select "+ td.author", :text => "jsmith@" do
  186. assert_select "+ td",
  187. :text => "Main purpose:"
  188. end
  189. end
  190. end
  191. end
  192. def test_annotate_author_escaping
  193. repository =
  194. Repository::Bazaar.create(
  195. :project => @project,
  196. :url => File.join(REPOSITORY_PATH, "author_escaping"),
  197. :identifier => 'author_escaping',
  198. :log_encoding => 'UTF-8'
  199. )
  200. assert repository
  201. get(
  202. :annotate,
  203. :params => {
  204. :id => PRJ_ID,
  205. :repository_id => 'author_escaping',
  206. :path => repository_path_hash(['author-escaping-test.txt'])[:param]
  207. }
  208. )
  209. assert_response :success
  210. assert_select "th.line-num", :text => '1' do
  211. assert_select "+ td.revision" do
  212. assert_select "a", :text => '2'
  213. assert_select "+ td.author", :text => "test &" do
  214. assert_select "+ td",
  215. :text => "author escaping test"
  216. end
  217. end
  218. end
  219. end
  220. def test_annotate_author_non_ascii
  221. log_encoding = nil
  222. if Encoding.locale_charmap == "UTF-8" ||
  223. Encoding.locale_charmap == "ISO-8859-1"
  224. log_encoding = Encoding.locale_charmap
  225. end
  226. unless log_encoding.nil?
  227. repository =
  228. Repository::Bazaar.create(
  229. :project => @project,
  230. :url => File.join(REPOSITORY_PATH, "author_non_ascii"),
  231. :identifier => 'author_non_ascii',
  232. :log_encoding => log_encoding
  233. )
  234. assert repository
  235. get(
  236. :annotate,
  237. :params => {
  238. :id => PRJ_ID,
  239. :repository_id => 'author_non_ascii',
  240. :path => repository_path_hash(['author-non-ascii-test.txt'])[:param]
  241. }
  242. )
  243. assert_response :success
  244. assert_select "th.line-num", :text => '1' do
  245. assert_select "+ td.revision" do
  246. assert_select "a", :text => '2'
  247. assert_select "+ td.author", :text => "test Ü" do
  248. assert_select "+ td",
  249. :text => "author non ASCII test"
  250. end
  251. end
  252. end
  253. end
  254. end
  255. def test_destroy_valid_repository
  256. @request.session[:user_id] = 1 # admin
  257. assert_equal 0, @repository.changesets.count
  258. @repository.fetch_changesets
  259. assert @repository.changesets.count > 0
  260. assert_difference 'Repository.count', -1 do
  261. delete(
  262. :destroy,
  263. :params => {
  264. :id => @repository.id
  265. }
  266. )
  267. end
  268. assert_response 302
  269. @project.reload
  270. assert_nil @project.repository
  271. end
  272. def test_destroy_invalid_repository
  273. @request.session[:user_id] = 1 # admin
  274. @project.repository.destroy
  275. @repository =
  276. Repository::Bazaar.create!(
  277. :project => @project,
  278. :url => "/invalid",
  279. :log_encoding => 'UTF-8'
  280. )
  281. @repository.fetch_changesets
  282. @repository.reload
  283. assert_equal 0, @repository.changesets.count
  284. assert_difference 'Repository.count', -1 do
  285. delete(
  286. :destroy,
  287. :params => {
  288. :id => @repository.id
  289. }
  290. )
  291. end
  292. assert_response 302
  293. @project.reload
  294. assert_nil @project.repository
  295. end
  296. else
  297. puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
  298. def test_fake; assert true end
  299. end
  300. end