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

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