comparison test/functional/time_entry_reports_controller_test.rb @ 909:cbb26bc654de redmine-1.3

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