##// END OF EJS Templates
scm: filesystem: add test for UTF-16 file displaying (#6256)....
Toshi MARUYAMA -
r5086:fb0d24d37e71
parent child
Show More
@@ -1,83 +1,94
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'repositories_controller'
19 require 'repositories_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
23
24 class RepositoriesFilesystemControllerTest < ActionController::TestCase
24 class RepositoriesFilesystemControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26
26
27 # No '..' in the repository path
27 # No '..' in the repository path
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/filesystem_repository'
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/filesystem_repository'
29 PRJ_ID = 3
29 PRJ_ID = 3
30
30
31 def setup
31 def setup
32 @controller = RepositoriesController.new
32 @controller = RepositoriesController.new
33 @request = ActionController::TestRequest.new
33 @request = ActionController::TestRequest.new
34 @response = ActionController::TestResponse.new
34 @response = ActionController::TestResponse.new
35 User.current = nil
35 User.current = nil
36 Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
36 Setting.enabled_scm << 'Filesystem' unless Setting.enabled_scm.include?('Filesystem')
37 @repository = Repository::Filesystem.create(
37 @repository = Repository::Filesystem.create(
38 :project => Project.find(PRJ_ID),
38 :project => Project.find(PRJ_ID),
39 :url => REPOSITORY_PATH,
39 :url => REPOSITORY_PATH,
40 :path_encoding => ''
40 :path_encoding => ''
41 )
41 )
42 assert @repository
42 assert @repository
43 end
43 end
44
44
45 if File.directory?(REPOSITORY_PATH)
45 if File.directory?(REPOSITORY_PATH)
46 def test_browse_root
46 def test_browse_root
47 @repository.fetch_changesets
47 @repository.fetch_changesets
48 @repository.reload
48 @repository.reload
49 get :show, :id => PRJ_ID
49 get :show, :id => PRJ_ID
50 assert_response :success
50 assert_response :success
51 assert_template 'show'
51 assert_template 'show'
52 assert_not_nil assigns(:entries)
52 assert_not_nil assigns(:entries)
53 assert assigns(:entries).size > 0
53 assert assigns(:entries).size > 0
54 assert_not_nil assigns(:changesets)
54 assert_not_nil assigns(:changesets)
55 assert assigns(:changesets).size == 0
55 assert assigns(:changesets).size == 0
56 end
56 end
57
57
58 def test_show_no_extension
58 def test_show_no_extension
59 get :entry, :id => PRJ_ID, :path => ['test']
59 get :entry, :id => PRJ_ID, :path => ['test']
60 assert_response :success
60 assert_response :success
61 assert_template 'entry'
61 assert_template 'entry'
62 assert_tag :tag => 'th',
62 assert_tag :tag => 'th',
63 :content => '1',
63 :content => '1',
64 :attributes => { :class => 'line-num' },
64 :attributes => { :class => 'line-num' },
65 :sibling => { :tag => 'td', :content => /TEST CAT/ }
65 :sibling => { :tag => 'td', :content => /TEST CAT/ }
66 end
66 end
67
67
68 def test_show_non_ascii_contents
68 def test_show_non_ascii_contents
69 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
69 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
70 get :entry, :id => PRJ_ID, :path => ['japanese', 'euc-jp.txt']
70 get :entry, :id => PRJ_ID, :path => ['japanese', 'euc-jp.txt']
71 assert_response :success
71 assert_response :success
72 assert_template 'entry'
72 assert_template 'entry'
73 assert_tag :tag => 'th',
73 assert_tag :tag => 'th',
74 :content => '2',
74 :content => '2',
75 :attributes => { :class => 'line-num' },
75 :attributes => { :class => 'line-num' },
76 :sibling => { :tag => 'td', :content => /japanese/ }
76 :sibling => { :tag => 'td', :content => /japanese/ }
77 end
77 end
78 end
78 end
79
80 def test_show_utf16
81 with_settings :repositories_encodings => 'UTF-16' do
82 get :entry, :id => PRJ_ID, :path => ['japanese', 'utf-16.txt']
83 assert_response :success
84 assert_tag :tag => 'th',
85 :content => '2',
86 :attributes => { :class => 'line-num' },
87 :sibling => { :tag => 'td', :content => /japanese/ }
88 end
89 end
79 else
90 else
80 puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!"
91 puts "Filesystem test repository NOT FOUND. Skipping functional tests !!!"
81 def test_fake; assert true end
92 def test_fake; assert true end
82 end
93 end
83 end
94 end
General Comments 0
You need to be logged in to leave comments. Login now