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.0KB

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