##// END OF EJS Templates
add missing fixture to TimeEntryReportsControllerTest...
Toshi MARUYAMA -
r13548:693badf5ff0b
parent child
Show More
@@ -1,353 +1,354
1 1 # -*- coding: utf-8 -*-
2 2 # Redmine - project management software
3 3 # Copyright (C) 2006-2015 Jean-Philippe Lang
4 4 #
5 5 # This program is free software; you can redistribute it and/or
6 6 # modify it under the terms of the GNU General Public License
7 7 # as published by the Free Software Foundation; either version 2
8 8 # of the License, or (at your option) any later version.
9 9 #
10 10 # This program is distributed in the hope that it will be useful,
11 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 # GNU General Public License for more details.
14 14 #
15 15 # You should have received a copy of the GNU General Public License
16 16 # along with this program; if not, write to the Free Software
17 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 18
19 19 require File.expand_path('../../test_helper', __FILE__)
20 20
21 21 class TimeEntryReportsControllerTest < ActionController::TestCase
22 22 tests TimelogController
23 23
24 24 fixtures :projects, :enabled_modules, :roles, :members, :member_roles,
25 :email_addresses,
25 26 :issues, :time_entries, :users, :trackers, :enumerations,
26 27 :issue_statuses, :custom_fields, :custom_values,
27 28 :projects_trackers, :custom_fields_trackers,
28 29 :custom_fields_projects
29 30
30 31 include Redmine::I18n
31 32
32 33 def setup
33 34 Setting.default_language = "en"
34 35 end
35 36
36 37 def test_report_at_project_level
37 38 get :report, :project_id => 'ecookbook'
38 39 assert_response :success
39 40 assert_template 'report'
40 41 assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries/report'
41 42 end
42 43
43 44 def test_report_all_projects
44 45 get :report
45 46 assert_response :success
46 47 assert_template 'report'
47 48 assert_select 'form#query_form[action=?]', '/time_entries/report'
48 49 end
49 50
50 51 def test_report_all_projects_denied
51 52 r = Role.anonymous
52 53 r.permissions.delete(:view_time_entries)
53 54 r.permissions_will_change!
54 55 r.save
55 56 get :report
56 57 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport'
57 58 end
58 59
59 60 def test_report_all_projects_one_criteria
60 61 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project']
61 62 assert_response :success
62 63 assert_template 'report'
63 64 assert_not_nil assigns(:report)
64 65 assert_equal "8.65", "%.2f" % assigns(:report).total_hours
65 66 end
66 67
67 68 def test_report_all_time
68 69 get :report, :project_id => 1, :criteria => ['project', 'issue']
69 70 assert_response :success
70 71 assert_template 'report'
71 72 assert_not_nil assigns(:report)
72 73 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
73 74 end
74 75
75 76 def test_report_all_time_by_day
76 77 get :report, :project_id => 1, :criteria => ['project', 'issue'], :columns => 'day'
77 78 assert_response :success
78 79 assert_template 'report'
79 80 assert_not_nil assigns(:report)
80 81 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
81 82 assert_select 'th', :text => '2007-03-12'
82 83 end
83 84
84 85 def test_report_one_criteria
85 86 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project']
86 87 assert_response :success
87 88 assert_template 'report'
88 89 assert_not_nil assigns(:report)
89 90 assert_equal "8.65", "%.2f" % assigns(:report).total_hours
90 91 end
91 92
92 93 def test_report_two_criteria
93 94 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"]
94 95 assert_response :success
95 96 assert_template 'report'
96 97 assert_not_nil assigns(:report)
97 98 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
98 99 end
99 100
100 101 def test_report_custom_field_criteria_with_multiple_values_on_single_value_custom_field_should_not_fail
101 102 field = TimeEntryCustomField.create!(:name => 'multi', :field_format => 'list', :possible_values => ['value1', 'value2'])
102 103 entry = TimeEntry.create!(:project => Project.find(1), :hours => 1, :activity_id => 10, :user => User.find(2), :spent_on => Date.today)
103 104 CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value1')
104 105 CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value2')
105 106
106 107 get :report, :project_id => 1, :columns => 'day', :criteria => ["cf_#{field.id}"]
107 108 assert_response :success
108 109 end
109 110
110 111 def test_report_multiple_values_custom_fields_should_not_be_proposed
111 112 TimeEntryCustomField.create!(:name => 'Single', :field_format => 'list', :possible_values => ['value1', 'value2'])
112 113 TimeEntryCustomField.create!(:name => 'Multi', :field_format => 'list', :multiple => true, :possible_values => ['value1', 'value2'])
113 114
114 115 get :report, :project_id => 1
115 116 assert_response :success
116 117 assert_select 'select[name=?]', 'criteria[]' do
117 118 assert_select 'option', :text => 'Single'
118 119 assert_select 'option', :text => 'Multi', :count => 0
119 120 end
120 121 end
121 122
122 123 def test_report_one_day
123 124 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criteria => ["user", "activity"]
124 125 assert_response :success
125 126 assert_template 'report'
126 127 assert_not_nil assigns(:report)
127 128 assert_equal "4.25", "%.2f" % assigns(:report).total_hours
128 129 end
129 130
130 131 def test_report_at_issue_level
131 132 get :report, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"]
132 133 assert_response :success
133 134 assert_template 'report'
134 135 assert_not_nil assigns(:report)
135 136 assert_equal "154.25", "%.2f" % assigns(:report).total_hours
136 137 assert_select 'form#query_form[action=?]', '/issues/1/time_entries/report'
137 138 end
138 139
139 140 def test_report_by_week_should_use_commercial_year
140 141 TimeEntry.delete_all
141 142 TimeEntry.generate!(:hours => '2', :spent_on => '2009-12-25') # 2009-52
142 143 TimeEntry.generate!(:hours => '4', :spent_on => '2009-12-31') # 2009-53
143 144 TimeEntry.generate!(:hours => '8', :spent_on => '2010-01-01') # 2009-53
144 145 TimeEntry.generate!(:hours => '16', :spent_on => '2010-01-05') # 2010-1
145 146
146 147 get :report, :columns => 'week', :from => "2009-12-25", :to => "2010-01-05", :criteria => ["project"]
147 148 assert_response :success
148 149
149 150 assert_select '#time-report thead tr' do
150 151 assert_select 'th:nth-child(1)', :text => 'Project'
151 152 assert_select 'th:nth-child(2)', :text => '2009-52'
152 153 assert_select 'th:nth-child(3)', :text => '2009-53'
153 154 assert_select 'th:nth-child(4)', :text => '2010-1'
154 155 assert_select 'th:nth-child(5)', :text => 'Total time'
155 156 end
156 157 assert_select '#time-report tbody tr' do
157 158 assert_select 'td:nth-child(1)', :text => 'eCookbook'
158 159 assert_select 'td:nth-child(2)', :text => '2.00'
159 160 assert_select 'td:nth-child(3)', :text => '12.00'
160 161 assert_select 'td:nth-child(4)', :text => '16.00'
161 162 assert_select 'td:nth-child(5)', :text => '30.00' # Total
162 163 end
163 164 end
164 165
165 166 def test_report_should_propose_association_custom_fields
166 167 get :report
167 168 assert_response :success
168 169 assert_template 'report'
169 170
170 171 assert_select 'select[name=?]', 'criteria[]' do
171 172 assert_select 'option[value=cf_1]', {:text => 'Database'}, 'Issue custom field not found'
172 173 assert_select 'option[value=cf_3]', {:text => 'Development status'}, 'Project custom field not found'
173 174 assert_select 'option[value=cf_7]', {:text => 'Billable'}, 'TimeEntryActivity custom field not found'
174 175 end
175 176 end
176 177
177 178 def test_report_with_association_custom_fields
178 179 get :report, :criteria => ['cf_1', 'cf_3', 'cf_7']
179 180 assert_response :success
180 181 assert_template 'report'
181 182 assert_not_nil assigns(:report)
182 183 assert_equal 3, assigns(:report).criteria.size
183 184 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
184 185
185 186 # Custom fields columns
186 187 assert_select 'th', :text => 'Database'
187 188 assert_select 'th', :text => 'Development status'
188 189 assert_select 'th', :text => 'Billable'
189 190
190 191 # Custom field row
191 192 assert_select 'tr' do
192 193 assert_select 'td', :text => 'MySQL'
193 194 assert_select 'td.hours', :text => '1.00'
194 195 end
195 196 end
196 197
197 198 def test_report_one_criteria_no_result
198 199 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criteria => ['project']
199 200 assert_response :success
200 201 assert_template 'report'
201 202 assert_not_nil assigns(:report)
202 203 assert_equal "0.00", "%.2f" % assigns(:report).total_hours
203 204 end
204 205
205 206 def test_report_status_criterion
206 207 get :report, :project_id => 1, :criteria => ['status']
207 208 assert_response :success
208 209 assert_template 'report'
209 210 assert_select 'th', :text => 'Status'
210 211 assert_select 'td', :text => 'New'
211 212 end
212 213
213 214 def test_report_all_projects_csv_export
214 215 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30",
215 216 :criteria => ["project", "user", "activity"], :format => "csv"
216 217 assert_response :success
217 218 assert_equal 'text/csv; header=present', @response.content_type
218 219 lines = @response.body.chomp.split("\n")
219 220 # Headers
220 221 assert_equal 'Project,User,Activity,2007-3,2007-4,Total time', lines.first
221 222 # Total row
222 223 assert_equal 'Total time,"","",154.25,8.65,162.90', lines.last
223 224 end
224 225
225 226 def test_report_csv_export
226 227 get :report, :project_id => 1, :columns => 'month',
227 228 :from => "2007-01-01", :to => "2007-06-30",
228 229 :criteria => ["project", "user", "activity"], :format => "csv"
229 230 assert_response :success
230 231 assert_equal 'text/csv; header=present', @response.content_type
231 232 lines = @response.body.chomp.split("\n")
232 233 # Headers
233 234 assert_equal 'Project,User,Activity,2007-3,2007-4,Total time', lines.first
234 235 # Total row
235 236 assert_equal 'Total time,"","",154.25,8.65,162.90', lines.last
236 237 end
237 238
238 239 def test_csv_big_5
239 240 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8')
240 241 str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5')
241 242 user = User.find_by_id(3)
242 243 user.firstname = str_utf8
243 244 user.lastname = "test-lastname"
244 245 assert user.save
245 246 comments = "test_csv_big_5"
246 247 te1 = TimeEntry.create(:spent_on => '2011-11-11',
247 248 :hours => 7.3,
248 249 :project => Project.find(1),
249 250 :user => user,
250 251 :activity => TimeEntryActivity.find_by_name('Design'),
251 252 :comments => comments)
252 253
253 254 te2 = TimeEntry.find_by_comments(comments)
254 255 assert_not_nil te2
255 256 assert_equal 7.3, te2.hours
256 257 assert_equal 3, te2.user_id
257 258
258 259 with_settings :default_language => "zh-TW" do
259 260 get :report, :project_id => 1, :columns => 'day',
260 261 :from => "2011-11-11", :to => "2011-11-11",
261 262 :criteria => ["user"], :format => "csv"
262 263 end
263 264 assert_response :success
264 265 assert_equal 'text/csv; header=present', @response.content_type
265 266 lines = @response.body.chomp.split("\n")
266 267 # Headers
267 268 s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5')
268 269 s2 = "\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5')
269 270 assert_equal s1, lines.first
270 271 # Total row
271 272 assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1]
272 273 assert_equal "#{s2},7.30,7.30", lines[2]
273 274
274 275 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)".force_encoding('UTF-8')
275 276 assert_equal str_tw, l(:general_lang_name)
276 277 assert_equal 'Big5', l(:general_csv_encoding)
277 278 assert_equal ',', l(:general_csv_separator)
278 279 assert_equal '.', l(:general_csv_decimal_separator)
279 280 end
280 281
281 282 def test_csv_cannot_convert_should_be_replaced_big_5
282 283 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
283 284 user = User.find_by_id(3)
284 285 user.firstname = str_utf8
285 286 user.lastname = "test-lastname"
286 287 assert user.save
287 288 comments = "test_replaced"
288 289 te1 = TimeEntry.create(:spent_on => '2011-11-11',
289 290 :hours => 7.3,
290 291 :project => Project.find(1),
291 292 :user => user,
292 293 :activity => TimeEntryActivity.find_by_name('Design'),
293 294 :comments => comments)
294 295
295 296 te2 = TimeEntry.find_by_comments(comments)
296 297 assert_not_nil te2
297 298 assert_equal 7.3, te2.hours
298 299 assert_equal 3, te2.user_id
299 300
300 301 with_settings :default_language => "zh-TW" do
301 302 get :report, :project_id => 1, :columns => 'day',
302 303 :from => "2011-11-11", :to => "2011-11-11",
303 304 :criteria => ["user"], :format => "csv"
304 305 end
305 306 assert_response :success
306 307 assert_equal 'text/csv; header=present', @response.content_type
307 308 lines = @response.body.chomp.split("\n")
308 309 # Headers
309 310 s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5')
310 311 assert_equal s1, lines.first
311 312 # Total row
312 313 s2 = "\xa5H?".force_encoding('Big5')
313 314 assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1]
314 315 end
315 316
316 317 def test_csv_fr
317 318 with_settings :default_language => "fr" do
318 319 str1 = "test_csv_fr"
319 320 user = User.find_by_id(3)
320 321 te1 = TimeEntry.create(:spent_on => '2011-11-11',
321 322 :hours => 7.3,
322 323 :project => Project.find(1),
323 324 :user => user,
324 325 :activity => TimeEntryActivity.find_by_name('Design'),
325 326 :comments => str1)
326 327
327 328 te2 = TimeEntry.find_by_comments(str1)
328 329 assert_not_nil te2
329 330 assert_equal 7.3, te2.hours
330 331 assert_equal 3, te2.user_id
331 332
332 333 get :report, :project_id => 1, :columns => 'day',
333 334 :from => "2011-11-11", :to => "2011-11-11",
334 335 :criteria => ["user"], :format => "csv"
335 336 assert_response :success
336 337 assert_equal 'text/csv; header=present', @response.content_type
337 338 lines = @response.body.chomp.split("\n")
338 339 # Headers
339 340 s1 = "Utilisateur;2011-11-11;Temps total".force_encoding('ISO-8859-1')
340 341 s2 = "Temps total".force_encoding('ISO-8859-1')
341 342 assert_equal s1, lines.first
342 343 # Total row
343 344 assert_equal "#{user.firstname} #{user.lastname};7,30;7,30", lines[1]
344 345 assert_equal "#{s2};7,30;7,30", lines[2]
345 346
346 347 str_fr = "French (Fran\xc3\xa7ais)".force_encoding('UTF-8')
347 348 assert_equal str_fr, l(:general_lang_name)
348 349 assert_equal 'ISO-8859-1', l(:general_csv_encoding)
349 350 assert_equal ';', l(:general_csv_separator)
350 351 assert_equal ',', l(:general_csv_decimal_separator)
351 352 end
352 353 end
353 354 end
General Comments 0
You need to be logged in to leave comments. Login now