Chris@1494: # Redmine - project management software Chris@1494: # Copyright (C) 2006-2014 Jean-Philippe Lang Chris@1494: # Chris@1494: # This program is free software; you can redistribute it and/or Chris@1494: # modify it under the terms of the GNU General Public License Chris@1494: # as published by the Free Software Foundation; either version 2 Chris@1494: # of the License, or (at your option) any later version. Chris@1494: # Chris@1494: # This program is distributed in the hope that it will be useful, Chris@1494: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1494: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1494: # GNU General Public License for more details. Chris@1494: # Chris@1494: # You should have received a copy of the GNU General Public License Chris@1494: # along with this program; if not, write to the Free Software Chris@1494: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1494: Chris@1494: require File.expand_path('../../test_helper', __FILE__) Chris@1494: Chris@1494: class RepositoriesSubversionControllerTest < ActionController::TestCase Chris@1494: tests RepositoriesController Chris@1494: Chris@1494: fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, Chris@1494: :repositories, :issues, :issue_statuses, :changesets, :changes, Chris@1494: :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers Chris@1494: Chris@1494: PRJ_ID = 3 Chris@1494: NUM_REV = 11 Chris@1494: Chris@1494: def setup Chris@1494: Setting.default_language = 'en' Chris@1494: User.current = nil Chris@1494: Chris@1494: @project = Project.find(PRJ_ID) Chris@1494: @repository = Repository::Subversion.create(:project => @project, Chris@1494: :url => self.class.subversion_repository_url) Chris@1494: assert @repository Chris@1494: end Chris@1494: Chris@1494: if repository_configured?('subversion') Chris@1494: def test_new Chris@1494: @request.session[:user_id] = 1 Chris@1494: @project.repository.destroy Chris@1494: get :new, :project_id => 'subproject1', :repository_scm => 'Subversion' Chris@1494: assert_response :success Chris@1494: assert_template 'new' Chris@1494: assert_kind_of Repository::Subversion, assigns(:repository) Chris@1494: assert assigns(:repository).new_record? Chris@1494: end Chris@1494: Chris@1494: def test_show Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :show, :id => PRJ_ID Chris@1494: assert_response :success Chris@1494: assert_template 'show' Chris@1494: assert_not_nil assigns(:entries) Chris@1494: assert_not_nil assigns(:changesets) Chris@1494: Chris@1494: entry = assigns(:entries).detect {|e| e.name == 'subversion_test'} Chris@1494: assert_not_nil entry Chris@1494: assert_equal 'dir', entry.kind Chris@1494: assert_select 'tr.dir a[href=/projects/subproject1/repository/show/subversion_test]' Chris@1494: Chris@1494: assert_tag 'input', :attributes => {:name => 'rev'} Chris@1494: assert_tag 'a', :content => 'Statistics' Chris@1494: assert_tag 'a', :content => 'Atom' Chris@1494: assert_tag :tag => 'a', Chris@1494: :attributes => {:href => '/projects/subproject1/repository'}, Chris@1494: :content => 'root' Chris@1494: end Chris@1494: Chris@1494: def test_show_non_default Chris@1494: Repository::Subversion.create(:project => @project, Chris@1494: :url => self.class.subversion_repository_url, Chris@1494: :is_default => false, :identifier => 'svn') Chris@1494: Chris@1494: get :show, :id => PRJ_ID, :repository_id => 'svn' Chris@1494: assert_response :success Chris@1494: assert_template 'show' Chris@1494: assert_select 'tr.dir a[href=/projects/subproject1/repository/svn/show/subversion_test]' Chris@1494: # Repository menu should link to the main repo Chris@1494: assert_select '#main-menu a[href=/projects/subproject1/repository]' Chris@1494: end Chris@1494: Chris@1494: def test_browse_directory Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param] Chris@1494: assert_response :success Chris@1494: assert_template 'show' Chris@1494: assert_not_nil assigns(:entries) Chris@1494: assert_equal [ Chris@1494: '[folder_with_brackets]', 'folder', '.project', Chris@1494: 'helloworld.c', 'textfile.txt' Chris@1494: ], Chris@1494: assigns(:entries).collect(&:name) Chris@1494: entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} Chris@1494: assert_equal 'file', entry.kind Chris@1494: assert_equal 'subversion_test/helloworld.c', entry.path Chris@1494: assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ } Chris@1494: end Chris@1494: Chris@1494: def test_browse_at_given_revision Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param], Chris@1494: :rev => 4 Chris@1494: assert_response :success Chris@1494: assert_template 'show' Chris@1494: assert_not_nil assigns(:entries) Chris@1494: assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], Chris@1494: assigns(:entries).collect(&:name) Chris@1494: end Chris@1494: Chris@1494: def test_file_changes Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :changes, :id => PRJ_ID, Chris@1494: :path => repository_path_hash(['subversion_test', 'folder', 'helloworld.rb'])[:param] Chris@1494: assert_response :success Chris@1494: assert_template 'changes' Chris@1494: Chris@1494: changesets = assigns(:changesets) Chris@1494: assert_not_nil changesets Chris@1494: assert_equal %w(6 3 2), changesets.collect(&:revision) Chris@1494: Chris@1494: # svn properties displayed with svn >= 1.5 only Chris@1494: if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0]) Chris@1494: assert_not_nil assigns(:properties) Chris@1494: assert_equal 'native', assigns(:properties)['svn:eol-style'] Chris@1494: assert_tag :ul, Chris@1494: :child => { :tag => 'li', Chris@1494: :child => { :tag => 'b', :content => 'svn:eol-style' }, Chris@1494: :child => { :tag => 'span', :content => 'native' } } Chris@1494: end Chris@1494: end Chris@1494: Chris@1494: def test_directory_changes Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :changes, :id => PRJ_ID, Chris@1494: :path => repository_path_hash(['subversion_test', 'folder'])[:param] Chris@1494: assert_response :success Chris@1494: assert_template 'changes' Chris@1494: Chris@1494: changesets = assigns(:changesets) Chris@1494: assert_not_nil changesets Chris@1494: assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision) Chris@1494: end Chris@1494: Chris@1494: def test_entry Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :entry, :id => PRJ_ID, Chris@1494: :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param] Chris@1494: assert_response :success Chris@1494: assert_template 'entry' Chris@1494: end Chris@1494: Chris@1494: def test_entry_should_send_if_too_big Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: # no files in the test repo is larger than 1KB... Chris@1494: with_settings :file_max_size_displayed => 0 do Chris@1494: get :entry, :id => PRJ_ID, Chris@1494: :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param] Chris@1494: assert_response :success Chris@1494: assert_equal 'attachment; filename="helloworld.c"', Chris@1494: @response.headers['Content-Disposition'] Chris@1494: end Chris@1494: end Chris@1494: Chris@1494: def test_entry_should_send_images_inline Chris@1494: get :entry, :id => PRJ_ID, Chris@1494: :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'rubylogo.gif'])[:param] Chris@1494: assert_response :success Chris@1494: assert_equal 'inline; filename="rubylogo.gif"', response.headers['Content-Disposition'] Chris@1494: end Chris@1494: Chris@1494: def test_entry_at_given_revision Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :entry, :id => PRJ_ID, Chris@1494: :path => repository_path_hash(['subversion_test', 'helloworld.rb'])[:param], Chris@1494: :rev => 2 Chris@1494: assert_response :success Chris@1494: assert_template 'entry' Chris@1494: # this line was removed in r3 and file was moved in r6 Chris@1494: assert_tag :tag => 'td', :attributes => { :class => /line-code/}, Chris@1494: :content => /Here's the code/ Chris@1494: end Chris@1494: Chris@1494: def test_entry_not_found Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :entry, :id => PRJ_ID, Chris@1494: :path => repository_path_hash(['subversion_test', 'zzz.c'])[:param] Chris@1494: assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, Chris@1494: :content => /The entry or revision was not found in the repository/ Chris@1494: end Chris@1494: Chris@1494: def test_entry_download Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :raw, :id => PRJ_ID, Chris@1494: :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param] Chris@1494: assert_response :success Chris@1494: assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] Chris@1494: end Chris@1494: Chris@1494: def test_directory_entry Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :entry, :id => PRJ_ID, Chris@1494: :path => repository_path_hash(['subversion_test', 'folder'])[:param] Chris@1494: assert_response :success Chris@1494: assert_template 'show' Chris@1494: assert_not_nil assigns(:entry) Chris@1494: assert_equal 'folder', assigns(:entry).name Chris@1494: end Chris@1494: Chris@1494: # TODO: this test needs fixtures. Chris@1494: def test_revision Chris@1494: get :revision, :id => 1, :rev => 2 Chris@1494: assert_response :success Chris@1494: assert_template 'revision' Chris@1494: Chris@1494: assert_select 'ul' do Chris@1494: assert_select 'li' do Chris@1494: # link to the entry at rev 2 Chris@1494: assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo', :text => 'repo' Chris@1494: # link to partial diff Chris@1494: assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' Chris@1494: end Chris@1494: end Chris@1494: end Chris@1494: Chris@1494: def test_invalid_revision Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :revision, :id => PRJ_ID, :rev => 'something_weird' Chris@1494: assert_response 404 Chris@1494: assert_error_tag :content => /was not found/ Chris@1494: end Chris@1494: Chris@1494: def test_invalid_revision_diff Chris@1494: get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird' Chris@1494: assert_response 404 Chris@1494: assert_error_tag :content => /was not found/ Chris@1494: end Chris@1494: Chris@1494: def test_empty_revision Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: ['', ' ', nil].each do |r| Chris@1494: get :revision, :id => PRJ_ID, :rev => r Chris@1494: assert_response 404 Chris@1494: assert_error_tag :content => /was not found/ Chris@1494: end Chris@1494: end Chris@1494: Chris@1494: # TODO: this test needs fixtures. Chris@1494: def test_revision_with_repository_pointing_to_a_subdirectory Chris@1494: r = Project.find(1).repository Chris@1494: # Changes repository url to a subdirectory Chris@1494: r.update_attribute :url, (r.url + '/test/some') Chris@1494: Chris@1494: get :revision, :id => 1, :rev => 2 Chris@1494: assert_response :success Chris@1494: assert_template 'revision' Chris@1494: Chris@1494: assert_select 'ul' do Chris@1494: assert_select 'li' do Chris@1494: # link to the entry at rev 2 Chris@1494: assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo', :text => 'repo' Chris@1494: # link to partial diff Chris@1494: assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' Chris@1494: end Chris@1494: end Chris@1494: end Chris@1494: Chris@1494: def test_revision_diff Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: ['inline', 'sbs'].each do |dt| Chris@1494: get :diff, :id => PRJ_ID, :rev => 3, :type => dt Chris@1494: assert_response :success Chris@1494: assert_template 'diff' Chris@1494: assert_select 'h2', :text => /Revision 3/ Chris@1494: assert_select 'th.filename', :text => 'subversion_test/textfile.txt' Chris@1494: end Chris@1494: end Chris@1494: Chris@1494: def test_revision_diff_raw_format Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: Chris@1494: get :diff, :id => PRJ_ID, :rev => 5, :format => 'diff' Chris@1494: assert_response :success Chris@1494: assert_equal 'text/x-patch', @response.content_type Chris@1494: assert_equal 'Index: subversion_test/folder/greeter.rb', @response.body.split(/\r?\n/).first Chris@1494: end Chris@1494: Chris@1494: def test_directory_diff Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: ['inline', 'sbs'].each do |dt| Chris@1494: get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2, Chris@1494: :path => repository_path_hash(['subversion_test', 'folder'])[:param], Chris@1494: :type => dt Chris@1494: assert_response :success Chris@1494: assert_template 'diff' Chris@1494: Chris@1494: diff = assigns(:diff) Chris@1494: assert_not_nil diff Chris@1494: # 2 files modified Chris@1494: assert_equal 2, Redmine::UnifiedDiff.new(diff).size Chris@1494: assert_tag :tag => 'h2', :content => /2:6/ Chris@1494: end Chris@1494: end Chris@1494: Chris@1494: def test_annotate Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :annotate, :id => PRJ_ID, Chris@1494: :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param] Chris@1494: assert_response :success Chris@1494: assert_template 'annotate' Chris@1494: Chris@1494: assert_select 'tr' do Chris@1494: assert_select 'th.line-num', :text => '1' Chris@1494: assert_select 'td.revision', :text => '4' Chris@1494: assert_select 'td.author', :text => 'jp' Chris@1494: assert_select 'td', :text => /stdio.h/ Chris@1494: end Chris@1494: # Same revision Chris@1494: assert_select 'tr' do Chris@1494: assert_select 'th.line-num', :text => '2' Chris@1494: assert_select 'td.revision', :text => '' Chris@1494: assert_select 'td.author', :text => '' Chris@1494: end Chris@1494: end Chris@1494: Chris@1494: def test_annotate_at_given_revision Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: @project.reload Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: get :annotate, :id => PRJ_ID, :rev => 8, Chris@1494: :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param] Chris@1494: assert_response :success Chris@1494: assert_template 'annotate' Chris@1494: assert_tag :tag => 'h2', :content => /@ 8/ Chris@1494: end Chris@1494: Chris@1494: def test_destroy_valid_repository Chris@1494: @request.session[:user_id] = 1 # admin Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: @repository.fetch_changesets Chris@1494: assert_equal NUM_REV, @repository.changesets.count Chris@1494: Chris@1494: assert_difference 'Repository.count', -1 do Chris@1494: delete :destroy, :id => @repository.id Chris@1494: end Chris@1494: assert_response 302 Chris@1494: @project.reload Chris@1494: assert_nil @project.repository Chris@1494: end Chris@1494: Chris@1494: def test_destroy_invalid_repository Chris@1494: @request.session[:user_id] = 1 # admin Chris@1494: @project.repository.destroy Chris@1494: @repository = Repository::Subversion.create!( Chris@1494: :project => @project, Chris@1494: :url => "file:///invalid") Chris@1494: @repository.fetch_changesets Chris@1494: assert_equal 0, @repository.changesets.count Chris@1494: Chris@1494: assert_difference 'Repository.count', -1 do Chris@1494: delete :destroy, :id => @repository.id Chris@1494: end Chris@1494: assert_response 302 Chris@1494: @project.reload Chris@1494: assert_nil @project.repository Chris@1494: end Chris@1494: else Chris@1494: puts "Subversion test repository NOT FOUND. Skipping functional tests !!!" Chris@1494: def test_fake; assert true end Chris@1494: end Chris@1494: end