##// 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 1 # redMine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'repositories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class RepositoriesMercurialControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26 26
27 27 # No '..' in the repository path
28 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 33 def setup
31 34 @controller = RepositoriesController.new
32 35 @request = ActionController::TestRequest.new
33 36 @response = ActionController::TestResponse.new
34 37 User.current = nil
35 38 @repository = Repository::Mercurial.create(
36 39 :project => Project.find(3),
37 40 :url => REPOSITORY_PATH,
38 41 :path_encoding => 'ISO-8859-1'
39 42 )
40 43 assert @repository
41 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 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 57 def test_show
46 58 get :show, :id => 3
47 59 assert_response :success
48 60 assert_template 'show'
49 61 assert_not_nil assigns(:entries)
50 62 assert_not_nil assigns(:changesets)
51 63 end
52 64
53 65 def test_show_root
54 66 get :show, :id => 3
55 67 assert_response :success
56 68 assert_template 'show'
57 69 assert_not_nil assigns(:entries)
58 70 assert_equal 4, assigns(:entries).size
59 71 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
60 72 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
61 73 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
62 74 end
63 75
64 76 def test_show_directory
65 77 get :show, :id => 3, :path => ['images']
66 78 assert_response :success
67 79 assert_template 'show'
68 80 assert_not_nil assigns(:entries)
69 81 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
70 82 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
71 83 assert_not_nil entry
72 84 assert_equal 'file', entry.kind
73 85 assert_equal 'images/edit.png', entry.path
74 86 end
75 87
76 88 def test_show_at_given_revision
77 89 [0, '0', '0885933ad4f6'].each do |r1|
78 90 get :show, :id => 3, :path => ['images'], :rev => r1
79 91 assert_response :success
80 92 assert_template 'show'
81 93 assert_not_nil assigns(:entries)
82 94 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
83 95 end
84 96 end
85 97
86 98 def test_show_directory_sql_escape_percent
87 99 [13, '13', '3a330eb32958'].each do |r1|
88 100 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
89 101 assert_response :success
90 102 assert_template 'show'
91 103
92 104 assert_not_nil assigns(:entries)
93 105 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
94 106 changesets = assigns(:changesets)
95 107
96 108 ## This is not yet implemented.
97 109 # assert_not_nil changesets
98 110 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
99 111 end
100 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 133 def test_changes
103 134 get :changes, :id => 3, :path => ['images', 'edit.png']
104 135 assert_response :success
105 136 assert_template 'changes'
106 137 assert_tag :tag => 'h2', :content => 'edit.png'
107 138 end
108 139
109 140 def test_entry_show
110 141 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
111 142 assert_response :success
112 143 assert_template 'entry'
113 144 # Line 10
114 145 assert_tag :tag => 'th',
115 146 :content => '10',
116 147 :attributes => { :class => 'line-num' },
117 148 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
118 149 end
119 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
162
120 163 def test_entry_download
121 164 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
122 165 assert_response :success
123 166 # File content
124 167 assert @response.body.include?('WITHOUT ANY WARRANTY')
125 168 end
126 169
127 170 def test_directory_entry
128 171 get :entry, :id => 3, :path => ['sources']
129 172 assert_response :success
130 173 assert_template 'show'
131 174 assert_not_nil assigns(:entry)
132 175 assert_equal 'sources', assigns(:entry).name
133 176 end
134 177
135 178 def test_diff
136 179 @repository.fetch_changesets
137 180 @repository.reload
138 181
139 182 [4, '4', 'def6d2f1254a'].each do |r1|
140 183 # Full diff of changeset 4
141 184 get :diff, :id => 3, :rev => r1
142 185 assert_response :success
143 186 assert_template 'diff'
144 187
145 188 if @diff_c_support
146 189 # Line 22 removed
147 190 assert_tag :tag => 'th',
148 191 :content => '22',
149 192 :sibling => { :tag => 'td',
150 193 :attributes => { :class => /diff_out/ },
151 194 :content => /def remove/ }
152 195 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
153 196 end
154 197 end
155 198 end
156 199
157 200 def test_diff_two_revs
158 201 @repository.fetch_changesets
159 202 @repository.reload
160 203
161 204 [2, '400bb8672109', '400', 400].each do |r1|
162 205 [4, 'def6d2f1254a'].each do |r2|
163 206 get :diff, :id => 3, :rev => r1,
164 207 :rev_to => r2
165 208 assert_response :success
166 209 assert_template 'diff'
167 210
168 211 diff = assigns(:diff)
169 212 assert_not_nil diff
170 213 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
171 214 end
172 215 end
173 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 231 def test_annotate
176 232 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
177 233 assert_response :success
178 234 assert_template 'annotate'
179 235 # Line 23, revision 4:def6d2f1254a
180 236 assert_tag :tag => 'th',
181 237 :content => '23',
182 238 :attributes => { :class => 'line-num' },
183 239 :sibling =>
184 240 {
185 241 :tag => 'td',
186 242 :attributes => { :class => 'revision' },
187 243 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
188 244 }
189 245 assert_tag :tag => 'th',
190 246 :content => '23',
191 247 :attributes => { :class => 'line-num' },
192 248 :sibling =>
193 249 {
194 250 :tag => 'td' ,
195 251 :content => 'jsmith' ,
196 252 :attributes => { :class => 'author' },
197 253 }
198 254 assert_tag :tag => 'th',
199 255 :content => '23',
200 256 :attributes => { :class => 'line-num' },
201 257 :sibling => { :tag => 'td', :content => /watcher =/ }
202 258 end
203 259
204 260 def test_annotate_at_given_revision
205 261 @repository.fetch_changesets
206 262 @repository.reload
207 263 [2, '400bb8672109', '400', 400].each do |r1|
208 264 get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb']
209 265 assert_response :success
210 266 assert_template 'annotate'
211 267 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
212 268 end
213 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 303 def test_empty_revision
216 304 @repository.fetch_changesets
217 305 @repository.reload
218 306 ['', ' ', nil].each do |r|
219 307 get :revision, :id => 3, :rev => r
220 308 assert_response 404
221 309 assert_error_tag :content => /was not found/
222 310 end
223 311 end
224 312 else
225 313 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
226 314 def test_fake; assert true end
227 315 end
228 316 end
General Comments 0
You need to be logged in to leave comments. Login now