comparison .svn/pristine/e2/e29ed39ed3e18484a016be4e6d2d802b2c90de66.svn-base @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents
children
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # -*- coding: utf-8 -*-
2 require File.expand_path('../../test_helper', __FILE__)
3
4 class TimeEntryReportsControllerTest < ActionController::TestCase
5 tests TimelogController
6
7 fixtures :projects, :enabled_modules, :roles, :members, :member_roles,
8 :issues, :time_entries, :users, :trackers, :enumerations,
9 :issue_statuses, :custom_fields, :custom_values
10
11 include Redmine::I18n
12
13 def setup
14 Setting.default_language = "en"
15 end
16
17 def test_report_at_project_level
18 get :report, :project_id => 'ecookbook'
19 assert_response :success
20 assert_template 'report'
21 assert_tag :form,
22 :attributes => {:action => "/projects/ecookbook/time_entries/report", :id => 'query_form'}
23 end
24
25 def test_report_all_projects
26 get :report
27 assert_response :success
28 assert_template 'report'
29 assert_tag :form,
30 :attributes => {:action => "/time_entries/report", :id => 'query_form'}
31 end
32
33 def test_report_all_projects_denied
34 r = Role.anonymous
35 r.permissions.delete(:view_time_entries)
36 r.permissions_will_change!
37 r.save
38 get :report
39 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport'
40 end
41
42 def test_report_all_projects_one_criteria
43 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project']
44 assert_response :success
45 assert_template 'report'
46 assert_not_nil assigns(:report)
47 assert_equal "8.65", "%.2f" % assigns(:report).total_hours
48 end
49
50 def test_report_all_time
51 get :report, :project_id => 1, :criteria => ['project', 'issue']
52 assert_response :success
53 assert_template 'report'
54 assert_not_nil assigns(:report)
55 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
56 end
57
58 def test_report_all_time_by_day
59 get :report, :project_id => 1, :criteria => ['project', 'issue'], :columns => 'day'
60 assert_response :success
61 assert_template 'report'
62 assert_not_nil assigns(:report)
63 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
64 assert_tag :tag => 'th', :content => '2007-03-12'
65 end
66
67 def test_report_one_criteria
68 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project']
69 assert_response :success
70 assert_template 'report'
71 assert_not_nil assigns(:report)
72 assert_equal "8.65", "%.2f" % assigns(:report).total_hours
73 end
74
75 def test_report_two_criteria
76 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["member", "activity"]
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 end
82
83 def test_report_custom_field_criteria_with_multiple_values
84 field = TimeEntryCustomField.create!(:name => 'multi', :field_format => 'list', :possible_values => ['value1', 'value2'])
85 entry = TimeEntry.create!(:project => Project.find(1), :hours => 1, :activity_id => 10, :user => User.find(2), :spent_on => Date.today)
86 CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value1')
87 CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value2')
88
89 get :report, :project_id => 1, :columns => 'day', :criteria => ["cf_#{field.id}"]
90 assert_response :success
91 end
92
93 def test_report_one_day
94 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criteria => ["member", "activity"]
95 assert_response :success
96 assert_template 'report'
97 assert_not_nil assigns(:report)
98 assert_equal "4.25", "%.2f" % assigns(:report).total_hours
99 end
100
101 def test_report_at_issue_level
102 get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["member", "activity"]
103 assert_response :success
104 assert_template 'report'
105 assert_not_nil assigns(:report)
106 assert_equal "154.25", "%.2f" % assigns(:report).total_hours
107 assert_tag :form,
108 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'}
109 end
110
111 def test_report_custom_field_criteria
112 get :report, :project_id => 1, :criteria => ['project', 'cf_1', 'cf_7']
113 assert_response :success
114 assert_template 'report'
115 assert_not_nil assigns(:report)
116 assert_equal 3, assigns(:report).criteria.size
117 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
118 # Custom field column
119 assert_tag :tag => 'th', :content => 'Database'
120 # Custom field row
121 assert_tag :tag => 'td', :content => 'MySQL',
122 :sibling => { :tag => 'td', :attributes => { :class => 'hours' },
123 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
124 :content => '1' }}
125 # Second custom field column
126 assert_tag :tag => 'th', :content => 'Billable'
127 end
128
129 def test_report_one_criteria_no_result
130 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criteria => ['project']
131 assert_response :success
132 assert_template 'report'
133 assert_not_nil assigns(:report)
134 assert_equal "0.00", "%.2f" % assigns(:report).total_hours
135 end
136
137 def test_report_status_criterion
138 get :report, :project_id => 1, :criteria => ['status']
139 assert_response :success
140 assert_template 'report'
141 assert_tag :tag => 'th', :content => 'Status'
142 assert_tag :tag => 'td', :content => 'New'
143 end
144
145 def test_report_all_projects_csv_export
146 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30",
147 :criteria => ["project", "member", "activity"], :format => "csv"
148 assert_response :success
149 assert_equal 'text/csv; header=present', @response.content_type
150 lines = @response.body.chomp.split("\n")
151 # Headers
152 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total',
153 lines.first
154 # Total row
155 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
156 end
157
158 def test_report_csv_export
159 get :report, :project_id => 1, :columns => 'month',
160 :from => "2007-01-01", :to => "2007-06-30",
161 :criteria => ["project", "member", "activity"], :format => "csv"
162 assert_response :success
163 assert_equal 'text/csv; header=present', @response.content_type
164 lines = @response.body.chomp.split("\n")
165 # Headers
166 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total',
167 lines.first
168 # Total row
169 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
170 end
171
172 def test_csv_big_5
173 Setting.default_language = "zh-TW"
174 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
175 str_big5 = "\xa4@\xa4\xeb"
176 if str_utf8.respond_to?(:force_encoding)
177 str_utf8.force_encoding('UTF-8')
178 str_big5.force_encoding('Big5')
179 end
180 user = User.find_by_id(3)
181 user.firstname = str_utf8
182 user.lastname = "test-lastname"
183 assert user.save
184 comments = "test_csv_big_5"
185 te1 = TimeEntry.create(:spent_on => '2011-11-11',
186 :hours => 7.3,
187 :project => Project.find(1),
188 :user => user,
189 :activity => TimeEntryActivity.find_by_name('Design'),
190 :comments => comments)
191
192 te2 = TimeEntry.find_by_comments(comments)
193 assert_not_nil te2
194 assert_equal 7.3, te2.hours
195 assert_equal 3, te2.user_id
196
197 get :report, :project_id => 1, :columns => 'day',
198 :from => "2011-11-11", :to => "2011-11-11",
199 :criteria => ["member"], :format => "csv"
200 assert_response :success
201 assert_equal 'text/csv; header=present', @response.content_type
202 lines = @response.body.chomp.split("\n")
203 # Headers
204 s1 = "\xa6\xa8\xad\xfb,2011-11-11,\xc1`\xadp"
205 s2 = "\xc1`\xadp"
206 if s1.respond_to?(:force_encoding)
207 s1.force_encoding('Big5')
208 s2.force_encoding('Big5')
209 end
210 assert_equal s1, lines.first
211 # Total row
212 assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1]
213 assert_equal "#{s2},7.30,7.30", lines[2]
214
215 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
216 if str_tw.respond_to?(:force_encoding)
217 str_tw.force_encoding('UTF-8')
218 end
219 assert_equal str_tw, l(:general_lang_name)
220 assert_equal 'Big5', l(:general_csv_encoding)
221 assert_equal ',', l(:general_csv_separator)
222 assert_equal '.', l(:general_csv_decimal_separator)
223 end
224
225 def test_csv_cannot_convert_should_be_replaced_big_5
226 Setting.default_language = "zh-TW"
227 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
228 if str_utf8.respond_to?(:force_encoding)
229 str_utf8.force_encoding('UTF-8')
230 end
231 user = User.find_by_id(3)
232 user.firstname = str_utf8
233 user.lastname = "test-lastname"
234 assert user.save
235 comments = "test_replaced"
236 te1 = TimeEntry.create(:spent_on => '2011-11-11',
237 :hours => 7.3,
238 :project => Project.find(1),
239 :user => user,
240 :activity => TimeEntryActivity.find_by_name('Design'),
241 :comments => comments)
242
243 te2 = TimeEntry.find_by_comments(comments)
244 assert_not_nil te2
245 assert_equal 7.3, te2.hours
246 assert_equal 3, te2.user_id
247
248 get :report, :project_id => 1, :columns => 'day',
249 :from => "2011-11-11", :to => "2011-11-11",
250 :criteria => ["member"], :format => "csv"
251 assert_response :success
252 assert_equal 'text/csv; header=present', @response.content_type
253 lines = @response.body.chomp.split("\n")
254 # Headers
255 s1 = "\xa6\xa8\xad\xfb,2011-11-11,\xc1`\xadp"
256 if s1.respond_to?(:force_encoding)
257 s1.force_encoding('Big5')
258 end
259 assert_equal s1, lines.first
260 # Total row
261 s2 = ""
262 if s2.respond_to?(:force_encoding)
263 s2 = "\xa5H?"
264 s2.force_encoding('Big5')
265 elsif RUBY_PLATFORM == 'java'
266 s2 = "??"
267 else
268 s2 = "\xa5H???"
269 end
270 assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1]
271 end
272
273 def test_csv_fr
274 with_settings :default_language => "fr" do
275 str1 = "test_csv_fr"
276 user = User.find_by_id(3)
277 te1 = TimeEntry.create(:spent_on => '2011-11-11',
278 :hours => 7.3,
279 :project => Project.find(1),
280 :user => user,
281 :activity => TimeEntryActivity.find_by_name('Design'),
282 :comments => str1)
283
284 te2 = TimeEntry.find_by_comments(str1)
285 assert_not_nil te2
286 assert_equal 7.3, te2.hours
287 assert_equal 3, te2.user_id
288
289 get :report, :project_id => 1, :columns => 'day',
290 :from => "2011-11-11", :to => "2011-11-11",
291 :criteria => ["member"], :format => "csv"
292 assert_response :success
293 assert_equal 'text/csv; header=present', @response.content_type
294 lines = @response.body.chomp.split("\n")
295 # Headers
296 s1 = "Membre;2011-11-11;Total"
297 s2 = "Total"
298 if s1.respond_to?(:force_encoding)
299 s1.force_encoding('ISO-8859-1')
300 s2.force_encoding('ISO-8859-1')
301 end
302 assert_equal s1, lines.first
303 # Total row
304 assert_equal "#{user.firstname} #{user.lastname};7,30;7,30", lines[1]
305 assert_equal "#{s2};7,30;7,30", lines[2]
306
307 str_fr = "Fran\xc3\xa7ais"
308 if str_fr.respond_to?(:force_encoding)
309 str_fr.force_encoding('UTF-8')
310 end
311 assert_equal str_fr, l(:general_lang_name)
312 assert_equal 'ISO-8859-1', l(:general_csv_encoding)
313 assert_equal ';', l(:general_csv_separator)
314 assert_equal ',', l(:general_csv_decimal_separator)
315 end
316 end
317 end