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 RepositoriesCvsControllerTest < ActionController::TestCase Chris@119: fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules Chris@0: Chris@0: # No '..' in the repository path Chris@0: REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/cvs_repository' Chris@0: REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? Chris@0: # CVS module Chris@0: MODULE_NAME = 'test' Chris@210: PRJ_ID = 3 Chris@210: 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: Chris@210: @project = Project.find(PRJ_ID) Chris@441: @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID), Chris@441: :root_url => REPOSITORY_PATH, Chris@441: :url => MODULE_NAME, Chris@245: :log_encoding => 'UTF-8') Chris@210: assert @repository Chris@0: end Chris@441: Chris@0: if File.directory?(REPOSITORY_PATH) Chris@0: def test_browse_root Chris@210: @repository.fetch_changesets Chris@210: @repository.reload Chris@210: 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_equal 3, assigns(:entries).size Chris@441: Chris@0: entry = assigns(:entries).detect {|e| e.name == 'images'} Chris@0: assert_equal 'dir', entry.kind Chris@0: Chris@0: entry = assigns(:entries).detect {|e| e.name == 'README'} Chris@0: assert_equal 'file', entry.kind Chris@441: Chris@441: assert_not_nil assigns(:changesets) Chris@441: assigns(:changesets).size > 0 Chris@0: end Chris@441: Chris@0: def test_browse_directory Chris@210: @repository.fetch_changesets Chris@210: @repository.reload Chris@210: get :show, :id => PRJ_ID, :path => ['images'] Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entries) Chris@0: assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name) Chris@0: entry = assigns(:entries).detect {|e| e.name == 'edit.png'} Chris@0: assert_not_nil entry Chris@0: assert_equal 'file', entry.kind Chris@0: assert_equal 'images/edit.png', entry.path Chris@0: end Chris@441: Chris@0: def test_browse_at_given_revision Chris@210: @repository.fetch_changesets Chris@210: @repository.reload Chris@210: get :show, :id => PRJ_ID, :path => ['images'], :rev => 1 Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entries) Chris@0: assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) Chris@0: end Chris@441: Chris@0: def test_entry Chris@210: @repository.fetch_changesets Chris@210: @repository.reload Chris@210: get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] Chris@0: assert_response :success Chris@0: assert_template 'entry' Chris@441: assert_no_tag :tag => 'td', Chris@441: :attributes => { :class => /line-code/}, Chris@441: :content => /before_filter/ Chris@0: end Chris@441: Chris@0: def test_entry_at_given_revision Chris@0: # changesets must be loaded Chris@210: @repository.fetch_changesets Chris@210: @repository.reload Chris@210: get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 2 Chris@0: assert_response :success Chris@0: assert_template 'entry' Chris@0: # this line was removed in r3 Chris@441: assert_tag :tag => 'td', Chris@441: :attributes => { :class => /line-code/}, Chris@441: :content => /before_filter/ Chris@0: end Chris@441: Chris@0: def test_entry_not_found Chris@210: @repository.fetch_changesets Chris@210: @repository.reload Chris@210: get :entry, :id => PRJ_ID, :path => ['sources', 'zzz.c'] Chris@441: assert_tag :tag => 'p', Chris@441: :attributes => { :id => /errorExplanation/ }, Chris@441: :content => /The entry or revision was not found in the repository/ Chris@0: end Chris@441: Chris@0: def test_entry_download Chris@210: @repository.fetch_changesets Chris@210: @repository.reload Chris@210: get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' Chris@0: assert_response :success Chris@0: end Chris@0: Chris@0: def test_directory_entry Chris@210: @repository.fetch_changesets Chris@210: @repository.reload Chris@210: get :entry, :id => PRJ_ID, :path => ['sources'] Chris@0: assert_response :success Chris@0: assert_template 'show' Chris@0: assert_not_nil assigns(:entry) Chris@0: assert_equal 'sources', assigns(:entry).name Chris@0: end Chris@441: Chris@0: def test_diff Chris@210: @repository.fetch_changesets Chris@210: @repository.reload Chris@210: get :diff, :id => PRJ_ID, :rev => 3, :type => 'inline' Chris@0: assert_response :success Chris@0: assert_template 'diff' Chris@0: assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' }, Chris@441: :content => /before_filter :require_login/ Chris@0: assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, Chris@441: :content => /with one change/ Chris@0: end Chris@441: Chris@245: def test_diff_new_files Chris@245: @repository.fetch_changesets Chris@245: @repository.reload Chris@245: get :diff, :id => PRJ_ID, :rev => 1, :type => 'inline' Chris@245: assert_response :success Chris@245: assert_template 'diff' Chris@245: assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' }, Chris@245: :content => /watched.remove_watcher/ Chris@245: assert_tag :tag => 'th', :attributes => { :class => 'filename' }, Chris@245: :content => /test\/README/ Chris@245: assert_tag :tag => 'th', :attributes => { :class => 'filename' }, Chris@245: :content => /test\/images\/delete.png / Chris@245: assert_tag :tag => 'th', :attributes => { :class => 'filename' }, Chris@245: :content => /test\/images\/edit.png/ Chris@245: assert_tag :tag => 'th', :attributes => { :class => 'filename' }, Chris@441: :content => /test\/sources\/watchers_controller.rb/ Chris@245: end Chris@0: Chris@0: def test_annotate Chris@210: @repository.fetch_changesets Chris@210: @repository.reload Chris@210: get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] Chris@0: assert_response :success Chris@0: assert_template 'annotate' Chris@0: # 1.1 line Chris@441: assert_tag :tag => 'th', Chris@441: :attributes => { :class => 'line-num' }, Chris@441: :content => '18', Chris@441: :sibling => { Chris@441: :tag => 'td', Chris@441: :attributes => { :class => 'revision' }, Chris@441: :content => /1.1/, Chris@441: :sibling => { Chris@441: :tag => 'td', Chris@441: :attributes => { :class => 'author' }, Chris@441: :content => /LANG/ Chris@441: } Chris@441: } Chris@0: # 1.2 line Chris@441: assert_tag :tag => 'th', Chris@441: :attributes => { :class => 'line-num' }, Chris@441: :content => '32', Chris@441: :sibling => { Chris@441: :tag => 'td', Chris@441: :attributes => { :class => 'revision' }, Chris@441: :content => /1.2/, Chris@441: :sibling => { Chris@441: :tag => 'td', Chris@441: :attributes => { :class => 'author' }, Chris@441: :content => /LANG/ Chris@441: } Chris@441: } Chris@0: end Chris@0: else Chris@0: puts "CVS test repository NOT FOUND. Skipping functional tests !!!" Chris@0: def test_fake; assert true end Chris@0: end Chris@0: end