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