##// END OF EJS Templates
add unit tests of subversion url validation...
Toshi MARUYAMA -
r11487:7a189207283f
parent child
Show More
@@ -1,231 +1,259
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 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
20 20 class RepositorySubversionTest < ActiveSupport::TestCase
21 21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22 22
23 include Redmine::I18n
24
23 25 NUM_REV = 11
24 26
25 27 def setup
26 28 @project = Project.find(3)
27 29 @repository = Repository::Subversion.create(:project => @project,
28 30 :url => self.class.subversion_repository_url)
29 31 assert @repository
30 32 end
31 33
34 def test_invalid_url
35 set_language_if_valid 'en'
36 ['invalid', 'http://', 'svn://', 'svn+ssh://', 'file://'].each do |url|
37 repo = Repository::Subversion.new(
38 :project => @project,
39 :identifier => 'test',
40 :url => url
41 )
42 assert !repo.save
43 assert_include "is invalid", repo.errors[:url]
44 end
45 end
46
47 def test_valid_url
48 ['http://valid', 'svn://valid', 'svn+ssh://valid', 'file://valid'].each do |url|
49 repo = Repository::Subversion.new(
50 :project => @project,
51 :identifier => 'test',
52 :url => url
53 )
54 assert repo.save
55 assert_equal [], repo.errors[:url]
56 assert repo.destroy
57 end
58 end
59
32 60 if repository_configured?('subversion')
33 61 def test_fetch_changesets_from_scratch
34 62 assert_equal 0, @repository.changesets.count
35 63 @repository.fetch_changesets
36 64 @project.reload
37 65
38 66 assert_equal NUM_REV, @repository.changesets.count
39 67 assert_equal 20, @repository.filechanges.count
40 68 assert_equal 'Initial import.', @repository.changesets.find_by_revision('1').comments
41 69 end
42 70
43 71 def test_fetch_changesets_incremental
44 72 assert_equal 0, @repository.changesets.count
45 73 @repository.fetch_changesets
46 74 @project.reload
47 75 assert_equal NUM_REV, @repository.changesets.count
48 76
49 77 # Remove changesets with revision > 5
50 78 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 5}
51 79 @project.reload
52 80 assert_equal 5, @repository.changesets.count
53 81
54 82 @repository.fetch_changesets
55 83 @project.reload
56 84 assert_equal NUM_REV, @repository.changesets.count
57 85 end
58 86
59 87 def test_entries
60 88 entries = @repository.entries
61 89 assert_kind_of Redmine::Scm::Adapters::Entries, entries
62 90 end
63 91
64 92 def test_entries_for_invalid_path_should_return_nil
65 93 entries = @repository.entries('invalid_path')
66 94 assert_nil entries
67 95 end
68 96
69 97 def test_latest_changesets
70 98 assert_equal 0, @repository.changesets.count
71 99 @repository.fetch_changesets
72 100 @project.reload
73 101 assert_equal NUM_REV, @repository.changesets.count
74 102
75 103 # with limit
76 104 changesets = @repository.latest_changesets('', nil, 2)
77 105 assert_equal 2, changesets.size
78 106 assert_equal @repository.latest_changesets('', nil).slice(0,2), changesets
79 107
80 108 # with path
81 109 changesets = @repository.latest_changesets('subversion_test/folder', nil)
82 110 assert_equal ["10", "9", "7", "6", "5", "2"], changesets.collect(&:revision)
83 111
84 112 # with path and revision
85 113 changesets = @repository.latest_changesets('subversion_test/folder', 8)
86 114 assert_equal ["7", "6", "5", "2"], changesets.collect(&:revision)
87 115 end
88 116
89 117 def test_directory_listing_with_square_brackets_in_path
90 118 assert_equal 0, @repository.changesets.count
91 119 @repository.fetch_changesets
92 120 @project.reload
93 121 assert_equal NUM_REV, @repository.changesets.count
94 122
95 123 entries = @repository.entries('subversion_test/[folder_with_brackets]')
96 124 assert_not_nil entries, 'Expect to find entries in folder_with_brackets'
97 125 assert_equal 1, entries.size, 'Expect one entry in folder_with_brackets'
98 126 assert_equal 'README.txt', entries.first.name
99 127 end
100 128
101 129 def test_directory_listing_with_square_brackets_in_base
102 130 @project = Project.find(3)
103 131 @repository = Repository::Subversion.create(
104 132 :project => @project,
105 133 :url => "file:///#{self.class.repository_path('subversion')}/subversion_test/[folder_with_brackets]")
106 134
107 135 assert_equal 0, @repository.changesets.count
108 136 @repository.fetch_changesets
109 137 @project.reload
110 138
111 139 assert_equal 1, @repository.changesets.count, 'Expected to see 1 revision'
112 140 assert_equal 2, @repository.filechanges.count, 'Expected to see 2 changes, dir add and file add'
113 141
114 142 entries = @repository.entries('')
115 143 assert_not_nil entries, 'Expect to find entries'
116 144 assert_equal 1, entries.size, 'Expect a single entry'
117 145 assert_equal 'README.txt', entries.first.name
118 146 end
119 147
120 148 def test_identifier
121 149 assert_equal 0, @repository.changesets.count
122 150 @repository.fetch_changesets
123 151 @project.reload
124 152 assert_equal NUM_REV, @repository.changesets.count
125 153 c = @repository.changesets.find_by_revision('1')
126 154 assert_equal c.revision, c.identifier
127 155 end
128 156
129 157 def test_find_changeset_by_empty_name
130 158 assert_equal 0, @repository.changesets.count
131 159 @repository.fetch_changesets
132 160 @project.reload
133 161 assert_equal NUM_REV, @repository.changesets.count
134 162 ['', ' ', nil].each do |r|
135 163 assert_nil @repository.find_changeset_by_name(r)
136 164 end
137 165 end
138 166
139 167 def test_identifier_nine_digit
140 168 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
141 169 :revision => '123456789', :comments => 'test')
142 170 assert_equal c.identifier, c.revision
143 171 end
144 172
145 173 def test_format_identifier
146 174 assert_equal 0, @repository.changesets.count
147 175 @repository.fetch_changesets
148 176 @project.reload
149 177 assert_equal NUM_REV, @repository.changesets.count
150 178 c = @repository.changesets.find_by_revision('1')
151 179 assert_equal c.format_identifier, c.revision
152 180 end
153 181
154 182 def test_format_identifier_nine_digit
155 183 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
156 184 :revision => '123456789', :comments => 'test')
157 185 assert_equal c.format_identifier, c.revision
158 186 end
159 187
160 188 def test_activities
161 189 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
162 190 :revision => '1', :comments => 'test')
163 191 assert c.event_title.include?('1:')
164 192 assert_equal '1', c.event_url[:rev]
165 193 end
166 194
167 195 def test_activities_nine_digit
168 196 c = Changeset.new(:repository => @repository, :committed_on => Time.now,
169 197 :revision => '123456789', :comments => 'test')
170 198 assert c.event_title.include?('123456789:')
171 199 assert_equal '123456789', c.event_url[:rev]
172 200 end
173 201
174 202 def test_log_encoding_ignore_setting
175 203 with_settings :commit_logs_encoding => 'windows-1252' do
176 204 s1 = "\xC2\x80"
177 205 s2 = "\xc3\x82\xc2\x80"
178 206 if s1.respond_to?(:force_encoding)
179 207 s1.force_encoding('ISO-8859-1')
180 208 s2.force_encoding('UTF-8')
181 209 assert_equal s1.encode('UTF-8'), s2
182 210 end
183 211 c = Changeset.new(:repository => @repository,
184 212 :comments => s2,
185 213 :revision => '123',
186 214 :committed_on => Time.now)
187 215 assert c.save
188 216 assert_equal s2, c.comments
189 217 end
190 218 end
191 219
192 220 def test_previous
193 221 assert_equal 0, @repository.changesets.count
194 222 @repository.fetch_changesets
195 223 @project.reload
196 224 assert_equal NUM_REV, @repository.changesets.count
197 225 changeset = @repository.find_changeset_by_name('3')
198 226 assert_equal @repository.find_changeset_by_name('2'), changeset.previous
199 227 end
200 228
201 229 def test_previous_nil
202 230 assert_equal 0, @repository.changesets.count
203 231 @repository.fetch_changesets
204 232 @project.reload
205 233 assert_equal NUM_REV, @repository.changesets.count
206 234 changeset = @repository.find_changeset_by_name('1')
207 235 assert_nil changeset.previous
208 236 end
209 237
210 238 def test_next
211 239 assert_equal 0, @repository.changesets.count
212 240 @repository.fetch_changesets
213 241 @project.reload
214 242 assert_equal NUM_REV, @repository.changesets.count
215 243 changeset = @repository.find_changeset_by_name('2')
216 244 assert_equal @repository.find_changeset_by_name('3'), changeset.next
217 245 end
218 246
219 247 def test_next_nil
220 248 assert_equal 0, @repository.changesets.count
221 249 @repository.fetch_changesets
222 250 @project.reload
223 251 assert_equal NUM_REV, @repository.changesets.count
224 252 changeset = @repository.find_changeset_by_name('11')
225 253 assert_nil changeset.next
226 254 end
227 255 else
228 256 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
229 257 def test_fake; assert true end
230 258 end
231 259 end
General Comments 0
You need to be logged in to leave comments. Login now