Chris@441: # Redmine - project management software Chris@441: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@441: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@441: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@119: require File.expand_path('../../test_helper', __FILE__) Chris@0: require 'repositories_controller' Chris@0: Chris@0: # Re-raise errors caught by the controller. Chris@0: class RepositoriesController; def rescue_action(e) raise e end; end Chris@0: Chris@0: class RepositoriesSubversionControllerTest < ActionController::TestCase Chris@0: fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, Chris@0: :repositories, :issues, :issue_statuses, :changesets, :changes, Chris@0: :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers Chris@0: Chris@245: PRJ_ID = 3 Chris@245: Chris@0: def setup Chris@0: @controller = RepositoriesController.new Chris@0: @request = ActionController::TestRequest.new Chris@0: @response = ActionController::TestResponse.new Chris@0: Setting.default_language = 'en' Chris@0: User.current = nil Chris@245: Chris@245: @project = Project.find(PRJ_ID) Chris@245: @repository = Repository::Subversion.create(:project => @project, Chris@441: :url => self.class.subversion_repository_url) Chris@245: assert @repository Chris@0: end Chris@0: Chris@0: if repository_configured?('subversion') Chris@0: def test_show Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :show, :id => PRJ_ID Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entries) Chris@0: assert_not_nil assigns(:changesets) Chris@0: end Chris@441: Chris@0: def test_browse_root Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :show, :id => PRJ_ID Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entries) Chris@0: entry = assigns(:entries).detect {|e| e.name == 'subversion_test'} Chris@0: assert_equal 'dir', entry.kind Chris@0: end Chris@441: Chris@0: def test_browse_directory Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :show, :id => PRJ_ID, :path => ['subversion_test'] Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entries) Chris@441: assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], Chris@441: assigns(:entries).collect(&:name) Chris@0: entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} Chris@0: assert_equal 'file', entry.kind Chris@0: assert_equal 'subversion_test/helloworld.c', entry.path Chris@0: assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ } Chris@0: end Chris@0: Chris@0: def test_browse_at_given_revision Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :show, :id => PRJ_ID, :path => ['subversion_test'], :rev => 4 Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entries) Chris@441: assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], Chris@441: assigns(:entries).collect(&:name) Chris@0: end Chris@441: Chris@0: def test_file_changes Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder', 'helloworld.rb' ] Chris@0: assert_response :success Chris@0: assert_template 'changes' Chris@441: Chris@0: changesets = assigns(:changesets) Chris@0: assert_not_nil changesets Chris@0: assert_equal %w(6 3 2), changesets.collect(&:revision) Chris@441: Chris@0: # svn properties displayed with svn >= 1.5 only Chris@0: if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0]) Chris@0: assert_not_nil assigns(:properties) Chris@0: assert_equal 'native', assigns(:properties)['svn:eol-style'] Chris@0: assert_tag :ul, Chris@0: :child => { :tag => 'li', Chris@0: :child => { :tag => 'b', :content => 'svn:eol-style' }, Chris@0: :child => { :tag => 'span', :content => 'native' } } Chris@0: end Chris@0: end Chris@0: Chris@0: def test_directory_changes Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder' ] Chris@0: assert_response :success Chris@0: assert_template 'changes' Chris@441: Chris@0: changesets = assigns(:changesets) Chris@0: assert_not_nil changesets Chris@0: assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision) Chris@0: end Chris@441: Chris@0: def test_entry Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'] Chris@0: assert_response :success Chris@0: assert_template 'entry' Chris@0: end Chris@441: Chris@0: def test_entry_should_send_if_too_big Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@0: # no files in the test repo is larger than 1KB... Chris@0: with_settings :file_max_size_displayed => 0 do Chris@245: get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'] Chris@0: assert_response :success Chris@0: assert_template '' Chris@0: assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] Chris@0: end Chris@0: end Chris@441: Chris@0: def test_entry_at_given_revision Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.rb'], :rev => 2 Chris@0: assert_response :success Chris@0: assert_template 'entry' Chris@0: # this line was removed in r3 and file was moved in r6 Chris@0: assert_tag :tag => 'td', :attributes => { :class => /line-code/}, Chris@0: :content => /Here's the code/ Chris@0: end Chris@441: Chris@0: def test_entry_not_found Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :entry, :id => PRJ_ID, :path => ['subversion_test', 'zzz.c'] chris@37: assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, Chris@0: :content => /The entry or revision was not found in the repository/ Chris@0: end Chris@441: Chris@0: def test_entry_download Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'], :format => 'raw' Chris@0: assert_response :success Chris@0: assert_template '' Chris@0: assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] Chris@0: end Chris@441: Chris@0: def test_directory_entry Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :entry, :id => PRJ_ID, :path => ['subversion_test', 'folder'] Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entry) Chris@0: assert_equal 'folder', assigns(:entry).name Chris@0: end Chris@441: Chris@245: # TODO: this test needs fixtures. Chris@0: def test_revision Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@0: get :revision, :id => 1, :rev => 2 Chris@0: assert_response :success Chris@0: assert_template 'revision' Chris@0: assert_tag :tag => 'ul', Chris@0: :child => { :tag => 'li', Chris@0: # link to the entry at rev 2 Chris@441: :child => { :tag => 'a', Chris@0: :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'}, Chris@0: :content => 'repo', Chris@0: # link to partial diff Chris@441: :sibling => { :tag => 'a', Chris@441: :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' } Chris@0: } Chris@0: } Chris@0: } Chris@0: end Chris@441: Chris@119: def test_invalid_revision Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :revision, :id => PRJ_ID, :rev => 'something_weird' Chris@245: assert_response 404 Chris@245: assert_error_tag :content => /was not found/ Chris@245: end Chris@245: Chris@245: def test_invalid_revision_diff Chris@245: get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird' Chris@128: assert_response 404 Chris@119: assert_error_tag :content => /was not found/ Chris@119: end Chris@119: Chris@119: def test_empty_revision Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@119: ['', ' ', nil].each do |r| Chris@245: get :revision, :id => PRJ_ID, :rev => r Chris@128: assert_response 404 Chris@119: assert_error_tag :content => /was not found/ Chris@119: end Chris@119: end Chris@119: Chris@245: # TODO: this test needs fixtures. Chris@0: def test_revision_with_repository_pointing_to_a_subdirectory Chris@0: r = Project.find(1).repository Chris@0: # Changes repository url to a subdirectory Chris@0: r.update_attribute :url, (r.url + '/test/some') Chris@441: Chris@0: get :revision, :id => 1, :rev => 2 Chris@0: assert_response :success Chris@0: assert_template 'revision' Chris@0: assert_tag :tag => 'ul', Chris@0: :child => { :tag => 'li', Chris@0: # link to the entry at rev 2 Chris@441: :child => { :tag => 'a', Chris@0: :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'}, Chris@0: :content => 'repo', Chris@0: # link to partial diff Chris@441: :sibling => { :tag => 'a', Chris@441: :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' } Chris@0: } Chris@0: } Chris@0: } Chris@0: end Chris@441: Chris@0: def test_revision_diff Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :diff, :id => PRJ_ID, :rev => 3 Chris@0: assert_response :success Chris@0: assert_template 'diff' Chris@119: Chris@119: assert_tag :tag => 'h2', :content => /3/ Chris@0: end Chris@0: Chris@0: def test_directory_diff Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder'] Chris@0: assert_response :success Chris@0: assert_template 'diff' Chris@441: Chris@0: diff = assigns(:diff) Chris@0: assert_not_nil diff Chris@0: # 2 files modified Chris@0: assert_equal 2, Redmine::UnifiedDiff.new(diff).size Chris@119: Chris@119: assert_tag :tag => 'h2', :content => /2:6/ Chris@0: end Chris@441: Chris@0: def test_annotate Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :annotate, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'] Chris@0: assert_response :success Chris@0: assert_template 'annotate' Chris@0: end Chris@210: Chris@210: def test_annotate_at_given_revision Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :annotate, :id => PRJ_ID, :rev => 8, :path => ['subversion_test', 'helloworld.c'] Chris@210: assert_response :success Chris@210: assert_template 'annotate' Chris@210: assert_tag :tag => 'h2', :content => /@ 8/ Chris@210: end Chris@0: else Chris@0: puts "Subversion test repository NOT FOUND. Skipping functional tests !!!" Chris@0: def test_fake; assert true end Chris@0: end Chris@0: end