Chris@441: # Redmine - project management software Chris@441: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@441: # Chris@441: # This program is free software; you can redistribute it and/or Chris@441: # modify it under the terms of the GNU General Public License Chris@441: # as published by the Free Software Foundation; either version 2 Chris@441: # of the License, or (at your option) any later version. Chris@441: # Chris@441: # This program is distributed in the hope that it will be useful, Chris@441: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@441: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@441: # GNU General Public License for more details. Chris@441: # Chris@441: # You should have received a copy of the GNU General Public License Chris@441: # along with this program; if not, write to the Free Software Chris@441: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@441: Chris@441: require File.expand_path('../../test_helper', __FILE__) Chris@441: require 'repositories_controller' Chris@441: Chris@441: # Re-raise errors caught by the controller. Chris@441: class RepositoriesController; def rescue_action(e) raise e end; end Chris@441: Chris@441: class RepositoriesFilesystemControllerTest < ActionController::TestCase Chris@441: fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules Chris@441: Chris@441: # No '..' in the repository path Chris@441: REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/filesystem_repository' Chris@441: PRJ_ID = 3 Chris@441: Chris@441: def setup Chris@441: @ruby19_non_utf8_pass = Chris@441: (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') Chris@441: @controller = RepositoriesController.new Chris@441: @request = ActionController::TestRequest.new Chris@441: @response = ActionController::TestResponse.new Chris@441: User.current = nil Chris@441: Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem') Chris@441: @repository = Repository::Filesystem.create( Chris@441: :project => Project.find(PRJ_ID), Chris@441: :url => REPOSITORY_PATH, Chris@441: :path_encoding => '' Chris@441: ) Chris@441: assert @repository Chris@441: end Chris@441: Chris@441: if File.directory?(REPOSITORY_PATH) Chris@441: def test_browse_root Chris@441: @repository.fetch_changesets Chris@441: @repository.reload Chris@441: get :show, :id => PRJ_ID Chris@441: assert_response :success Chris@441: assert_template 'show' Chris@441: assert_not_nil assigns(:entries) Chris@441: assert assigns(:entries).size > 0 Chris@441: assert_not_nil assigns(:changesets) Chris@441: assert assigns(:changesets).size == 0 Chris@441: end Chris@441: Chris@441: def test_show_no_extension Chris@441: get :entry, :id => PRJ_ID, :path => ['test'] Chris@441: assert_response :success Chris@441: assert_template 'entry' Chris@441: assert_tag :tag => 'th', Chris@441: :content => '1', Chris@441: :attributes => { :class => 'line-num' }, Chris@441: :sibling => { :tag => 'td', :content => /TEST CAT/ } Chris@441: end Chris@441: Chris@441: def test_entry_download_no_extension Chris@441: get :entry, :id => PRJ_ID, :path => ['test'], :format => 'raw' Chris@441: assert_response :success Chris@441: assert_equal 'application/octet-stream', @response.content_type Chris@441: end Chris@441: Chris@441: def test_show_non_ascii_contents Chris@441: with_settings :repositories_encodings => 'UTF-8,EUC-JP' do Chris@441: get :entry, :id => PRJ_ID, :path => ['japanese', 'euc-jp.txt'] Chris@441: assert_response :success Chris@441: assert_template 'entry' Chris@441: assert_tag :tag => 'th', Chris@441: :content => '2', Chris@441: :attributes => { :class => 'line-num' }, Chris@441: :sibling => { :tag => 'td', :content => /japanese/ } Chris@441: if @ruby19_non_utf8_pass Chris@441: puts "TODO: show repository file contents test fails in Ruby 1.9 " + Chris@441: "and Encoding.default_external is not UTF-8. " + Chris@441: "Current value is '#{Encoding.default_external.to_s}'" Chris@441: else Chris@441: str_japanese = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e" Chris@441: str_japanese.force_encoding('UTF-8') if str_japanese.respond_to?(:force_encoding) Chris@441: assert_tag :tag => 'th', Chris@441: :content => '3', Chris@441: :attributes => { :class => 'line-num' }, Chris@441: :sibling => { :tag => 'td', :content => /#{str_japanese}/ } Chris@441: end Chris@441: end Chris@441: end Chris@441: Chris@441: def test_show_utf16 Chris@441: with_settings :repositories_encodings => 'UTF-16' do Chris@441: get :entry, :id => PRJ_ID, :path => ['japanese', 'utf-16.txt'] Chris@441: assert_response :success Chris@441: assert_tag :tag => 'th', Chris@441: :content => '2', Chris@441: :attributes => { :class => 'line-num' }, Chris@441: :sibling => { :tag => 'td', :content => /japanese/ } Chris@441: end Chris@441: end Chris@441: Chris@441: def test_show_text_file_should_send_if_too_big Chris@441: with_settings :file_max_size_displayed => 1 do Chris@441: get :entry, :id => PRJ_ID, :path => ['japanese', 'big-file.txt'] Chris@441: assert_response :success Chris@441: assert_equal 'text/plain', @response.content_type Chris@441: end Chris@441: end Chris@441: else Chris@441: puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!" Chris@441: def test_fake; assert true end Chris@441: end Chris@441: end