##// END OF EJS Templates
scm: mercurial: add path encoding tests in functional test (#2664, #4050)....
Toshi MARUYAMA -
r4880:82c670ba0355
parent child
Show More
@@ -1,228 +1,316
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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 RepositoriesMercurialControllerTest < ActionController::TestCase
24 class RepositoriesMercurialControllerTest < 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/mercurial_repository'
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
29 CHAR_1_HEX = "\xc3\x9c"
30
31 ruby19_non_utf8_pass = (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
29
32
30 def setup
33 def setup
31 @controller = RepositoriesController.new
34 @controller = RepositoriesController.new
32 @request = ActionController::TestRequest.new
35 @request = ActionController::TestRequest.new
33 @response = ActionController::TestResponse.new
36 @response = ActionController::TestResponse.new
34 User.current = nil
37 User.current = nil
35 @repository = Repository::Mercurial.create(
38 @repository = Repository::Mercurial.create(
36 :project => Project.find(3),
39 :project => Project.find(3),
37 :url => REPOSITORY_PATH,
40 :url => REPOSITORY_PATH,
38 :path_encoding => 'ISO-8859-1'
41 :path_encoding => 'ISO-8859-1'
39 )
42 )
40 assert @repository
43 assert @repository
41 @diff_c_support = true
44 @diff_c_support = true
45 @char_1 = CHAR_1_HEX.dup
46 if @char_1.respond_to?(:force_encoding)
47 @char_1.force_encoding('UTF-8')
48 end
42 end
49 end
43
50
44 if File.directory?(REPOSITORY_PATH)
51 if ruby19_non_utf8_pass
52 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
53 "and Encoding.default_external is not UTF-8. " +
54 "Current value is '#{Encoding.default_external.to_s}'"
55 def test_fake; assert true end
56 elsif File.directory?(REPOSITORY_PATH)
45 def test_show
57 def test_show
46 get :show, :id => 3
58 get :show, :id => 3
47 assert_response :success
59 assert_response :success
48 assert_template 'show'
60 assert_template 'show'
49 assert_not_nil assigns(:entries)
61 assert_not_nil assigns(:entries)
50 assert_not_nil assigns(:changesets)
62 assert_not_nil assigns(:changesets)
51 end
63 end
52
64
53 def test_show_root
65 def test_show_root
54 get :show, :id => 3
66 get :show, :id => 3
55 assert_response :success
67 assert_response :success
56 assert_template 'show'
68 assert_template 'show'
57 assert_not_nil assigns(:entries)
69 assert_not_nil assigns(:entries)
58 assert_equal 4, assigns(:entries).size
70 assert_equal 4, assigns(:entries).size
59 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
71 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
60 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
72 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
61 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
73 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
62 end
74 end
63
75
64 def test_show_directory
76 def test_show_directory
65 get :show, :id => 3, :path => ['images']
77 get :show, :id => 3, :path => ['images']
66 assert_response :success
78 assert_response :success
67 assert_template 'show'
79 assert_template 'show'
68 assert_not_nil assigns(:entries)
80 assert_not_nil assigns(:entries)
69 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
81 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
70 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
82 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
71 assert_not_nil entry
83 assert_not_nil entry
72 assert_equal 'file', entry.kind
84 assert_equal 'file', entry.kind
73 assert_equal 'images/edit.png', entry.path
85 assert_equal 'images/edit.png', entry.path
74 end
86 end
75
87
76 def test_show_at_given_revision
88 def test_show_at_given_revision
77 [0, '0', '0885933ad4f6'].each do |r1|
89 [0, '0', '0885933ad4f6'].each do |r1|
78 get :show, :id => 3, :path => ['images'], :rev => r1
90 get :show, :id => 3, :path => ['images'], :rev => r1
79 assert_response :success
91 assert_response :success
80 assert_template 'show'
92 assert_template 'show'
81 assert_not_nil assigns(:entries)
93 assert_not_nil assigns(:entries)
82 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
94 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
83 end
95 end
84 end
96 end
85
97
86 def test_show_directory_sql_escape_percent
98 def test_show_directory_sql_escape_percent
87 [13, '13', '3a330eb32958'].each do |r1|
99 [13, '13', '3a330eb32958'].each do |r1|
88 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
100 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
89 assert_response :success
101 assert_response :success
90 assert_template 'show'
102 assert_template 'show'
91
103
92 assert_not_nil assigns(:entries)
104 assert_not_nil assigns(:entries)
93 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
105 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
94 changesets = assigns(:changesets)
106 changesets = assigns(:changesets)
95
107
96 ## This is not yet implemented.
108 ## This is not yet implemented.
97 # assert_not_nil changesets
109 # assert_not_nil changesets
98 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
110 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
99 end
111 end
100 end
112 end
101
113
114 def test_show_directory_latin_1
115 @repository.fetch_changesets
116 @repository.reload
117 [21, '21', 'adf805632193'].each do |r1|
118 get :show, :id => 3, :path => ['latin-1-dir'], :rev => r1
119 assert_response :success
120 assert_template 'show'
121
122 assert_not_nil assigns(:entries)
123 assert_equal ["make-latin-1-file.rb",
124 "test-#{@char_1}-1.txt",
125 "test-#{@char_1}-2.txt",
126 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
127 changesets = assigns(:changesets)
128 assert_not_nil changesets
129 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
130 end
131 end
132
102 def test_changes
133 def test_changes
103 get :changes, :id => 3, :path => ['images', 'edit.png']
134 get :changes, :id => 3, :path => ['images', 'edit.png']
104 assert_response :success
135 assert_response :success
105 assert_template 'changes'
136 assert_template 'changes'
106 assert_tag :tag => 'h2', :content => 'edit.png'
137 assert_tag :tag => 'h2', :content => 'edit.png'
107 end
138 end
108
139
109 def test_entry_show
140 def test_entry_show
110 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
141 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
111 assert_response :success
142 assert_response :success
112 assert_template 'entry'
143 assert_template 'entry'
113 # Line 10
144 # Line 10
114 assert_tag :tag => 'th',
145 assert_tag :tag => 'th',
115 :content => '10',
146 :content => '10',
116 :attributes => { :class => 'line-num' },
147 :attributes => { :class => 'line-num' },
117 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
148 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
118 end
149 end
150
151 def test_entry_show_latin_1
152 [21, '21', 'adf805632193'].each do |r1|
153 get :entry, :id => 3, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
154 assert_response :success
155 assert_template 'entry'
156 assert_tag :tag => 'th',
157 :content => '1',
158 :attributes => { :class => 'line-num' },
159 :sibling => { :tag => 'td', :content => /Mercurial is a distributed version control system/ }
160 end
161 end
119
162
120 def test_entry_download
163 def test_entry_download
121 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
164 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
122 assert_response :success
165 assert_response :success
123 # File content
166 # File content
124 assert @response.body.include?('WITHOUT ANY WARRANTY')
167 assert @response.body.include?('WITHOUT ANY WARRANTY')
125 end
168 end
126
169
127 def test_directory_entry
170 def test_directory_entry
128 get :entry, :id => 3, :path => ['sources']
171 get :entry, :id => 3, :path => ['sources']
129 assert_response :success
172 assert_response :success
130 assert_template 'show'
173 assert_template 'show'
131 assert_not_nil assigns(:entry)
174 assert_not_nil assigns(:entry)
132 assert_equal 'sources', assigns(:entry).name
175 assert_equal 'sources', assigns(:entry).name
133 end
176 end
134
177
135 def test_diff
178 def test_diff
136 @repository.fetch_changesets
179 @repository.fetch_changesets
137 @repository.reload
180 @repository.reload
138
181
139 [4, '4', 'def6d2f1254a'].each do |r1|
182 [4, '4', 'def6d2f1254a'].each do |r1|
140 # Full diff of changeset 4
183 # Full diff of changeset 4
141 get :diff, :id => 3, :rev => r1
184 get :diff, :id => 3, :rev => r1
142 assert_response :success
185 assert_response :success
143 assert_template 'diff'
186 assert_template 'diff'
144
187
145 if @diff_c_support
188 if @diff_c_support
146 # Line 22 removed
189 # Line 22 removed
147 assert_tag :tag => 'th',
190 assert_tag :tag => 'th',
148 :content => '22',
191 :content => '22',
149 :sibling => { :tag => 'td',
192 :sibling => { :tag => 'td',
150 :attributes => { :class => /diff_out/ },
193 :attributes => { :class => /diff_out/ },
151 :content => /def remove/ }
194 :content => /def remove/ }
152 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
195 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
153 end
196 end
154 end
197 end
155 end
198 end
156
199
157 def test_diff_two_revs
200 def test_diff_two_revs
158 @repository.fetch_changesets
201 @repository.fetch_changesets
159 @repository.reload
202 @repository.reload
160
203
161 [2, '400bb8672109', '400', 400].each do |r1|
204 [2, '400bb8672109', '400', 400].each do |r1|
162 [4, 'def6d2f1254a'].each do |r2|
205 [4, 'def6d2f1254a'].each do |r2|
163 get :diff, :id => 3, :rev => r1,
206 get :diff, :id => 3, :rev => r1,
164 :rev_to => r2
207 :rev_to => r2
165 assert_response :success
208 assert_response :success
166 assert_template 'diff'
209 assert_template 'diff'
167
210
168 diff = assigns(:diff)
211 diff = assigns(:diff)
169 assert_not_nil diff
212 assert_not_nil diff
170 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
213 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
171 end
214 end
172 end
215 end
173 end
216 end
174
217
218 def test_diff_latin_1
219 [21, 'adf805632193'].each do |r1|
220 get :diff, :id => 3, :rev => r1
221 assert_response :success
222 assert_template 'diff'
223 assert_tag :tag => 'th',
224 :content => '2',
225 :sibling => { :tag => 'td',
226 :attributes => { :class => /diff_in/ },
227 :content => /It is written in Python/ }
228 end
229 end
230
175 def test_annotate
231 def test_annotate
176 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
232 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
177 assert_response :success
233 assert_response :success
178 assert_template 'annotate'
234 assert_template 'annotate'
179 # Line 23, revision 4:def6d2f1254a
235 # Line 23, revision 4:def6d2f1254a
180 assert_tag :tag => 'th',
236 assert_tag :tag => 'th',
181 :content => '23',
237 :content => '23',
182 :attributes => { :class => 'line-num' },
238 :attributes => { :class => 'line-num' },
183 :sibling =>
239 :sibling =>
184 {
240 {
185 :tag => 'td',
241 :tag => 'td',
186 :attributes => { :class => 'revision' },
242 :attributes => { :class => 'revision' },
187 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
243 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
188 }
244 }
189 assert_tag :tag => 'th',
245 assert_tag :tag => 'th',
190 :content => '23',
246 :content => '23',
191 :attributes => { :class => 'line-num' },
247 :attributes => { :class => 'line-num' },
192 :sibling =>
248 :sibling =>
193 {
249 {
194 :tag => 'td' ,
250 :tag => 'td' ,
195 :content => 'jsmith' ,
251 :content => 'jsmith' ,
196 :attributes => { :class => 'author' },
252 :attributes => { :class => 'author' },
197 }
253 }
198 assert_tag :tag => 'th',
254 assert_tag :tag => 'th',
199 :content => '23',
255 :content => '23',
200 :attributes => { :class => 'line-num' },
256 :attributes => { :class => 'line-num' },
201 :sibling => { :tag => 'td', :content => /watcher =/ }
257 :sibling => { :tag => 'td', :content => /watcher =/ }
202 end
258 end
203
259
204 def test_annotate_at_given_revision
260 def test_annotate_at_given_revision
205 @repository.fetch_changesets
261 @repository.fetch_changesets
206 @repository.reload
262 @repository.reload
207 [2, '400bb8672109', '400', 400].each do |r1|
263 [2, '400bb8672109', '400', 400].each do |r1|
208 get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb']
264 get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb']
209 assert_response :success
265 assert_response :success
210 assert_template 'annotate'
266 assert_template 'annotate'
211 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
267 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
212 end
268 end
213 end
269 end
214
270
271 def test_annotate_latin_1
272 [21, '21', 'adf805632193'].each do |r1|
273 get :annotate, :id => 3, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
274 assert_response :success
275 assert_template 'annotate'
276 assert_tag :tag => 'th',
277 :content => '1',
278 :attributes => { :class => 'line-num' },
279 :sibling =>
280 {
281 :tag => 'td',
282 :attributes => { :class => 'revision' },
283 :child => { :tag => 'a', :content => '20:709858aafd1b' }
284 }
285 assert_tag :tag => 'th',
286 :content => '1',
287 :attributes => { :class => 'line-num' },
288 :sibling =>
289 {
290 :tag => 'td' ,
291 :content => 'jsmith' ,
292 :attributes => { :class => 'author' },
293
294 }
295 assert_tag :tag => 'th',
296 :content => '1',
297 :attributes => { :class => 'line-num' },
298 :sibling => { :tag => 'td', :content => /Mercurial is a distributed version control system/ }
299
300 end
301 end
302
215 def test_empty_revision
303 def test_empty_revision
216 @repository.fetch_changesets
304 @repository.fetch_changesets
217 @repository.reload
305 @repository.reload
218 ['', ' ', nil].each do |r|
306 ['', ' ', nil].each do |r|
219 get :revision, :id => 3, :rev => r
307 get :revision, :id => 3, :rev => r
220 assert_response 404
308 assert_response 404
221 assert_error_tag :content => /was not found/
309 assert_error_tag :content => /was not found/
222 end
310 end
223 end
311 end
224 else
312 else
225 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
313 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
226 def test_fake; assert true end
314 def test_fake; assert true end
227 end
315 end
228 end
316 end
General Comments 0
You need to be logged in to leave comments. Login now