Chris@0: # redMine - project management software Chris@0: # Copyright (C) 2006-2008 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@0: # 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@0: # 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@0: require File.dirname(__FILE__) + '/../test_helper' 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@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@0: end Chris@0: Chris@0: if repository_configured?('subversion') Chris@0: def test_show Chris@0: get :show, :id => 1 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@0: Chris@0: def test_browse_root Chris@0: get :show, :id => 1 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@0: Chris@0: def test_browse_directory Chris@0: get :show, :id => 1, :path => ['subversion_test'] Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entries) Chris@0: assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], 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@0: get :show, :id => 1, :path => ['subversion_test'], :rev => 4 Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entries) Chris@0: assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name) Chris@0: end Chris@0: Chris@0: def test_file_changes Chris@0: get :changes, :id => 1, :path => ['subversion_test', 'folder', 'helloworld.rb' ] Chris@0: assert_response :success Chris@0: assert_template 'changes' Chris@0: Chris@0: changesets = assigns(:changesets) Chris@0: assert_not_nil changesets Chris@0: assert_equal %w(6 3 2), changesets.collect(&:revision) Chris@0: 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@0: get :changes, :id => 1, :path => ['subversion_test', 'folder' ] Chris@0: assert_response :success Chris@0: assert_template 'changes' Chris@0: 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@0: Chris@0: def test_entry Chris@0: get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'] Chris@0: assert_response :success Chris@0: assert_template 'entry' Chris@0: end Chris@0: Chris@0: def test_entry_should_send_if_too_big Chris@0: # no files in the test repo is larger than 1KB... Chris@0: with_settings :file_max_size_displayed => 0 do Chris@0: get :entry, :id => 1, :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@0: Chris@0: def test_entry_at_given_revision Chris@0: get :entry, :id => 1, :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@0: Chris@0: def test_entry_not_found Chris@0: get :entry, :id => 1, :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@0: Chris@0: def test_entry_download Chris@0: get :entry, :id => 1, :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@0: Chris@0: def test_directory_entry Chris@0: get :entry, :id => 1, :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@0: Chris@0: def test_revision 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@0: :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@0: :sibling => { :tag => 'a', Chris@0: :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' } Chris@0: } Chris@0: } Chris@0: } Chris@0: end Chris@0: 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@0: 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@0: :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@0: :sibling => { :tag => 'a', Chris@0: :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' } Chris@0: } Chris@0: } Chris@0: } Chris@0: end Chris@0: Chris@0: def test_revision_diff Chris@0: get :diff, :id => 1, :rev => 3 Chris@0: assert_response :success Chris@0: assert_template 'diff' Chris@0: end Chris@0: Chris@0: def test_directory_diff Chris@0: get :diff, :id => 1, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder'] Chris@0: assert_response :success Chris@0: assert_template 'diff' Chris@0: 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@0: end Chris@0: Chris@0: def test_annotate Chris@0: get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c'] Chris@0: assert_response :success Chris@0: assert_template 'annotate' Chris@0: 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