Mercurial > hg > soundsoftware-site
comparison .svn/pristine/59/595569d84d22df6ad4296b4d377f37df66d05fc6.svn-base @ 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 | |
children |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 # -*- coding: utf-8 -*- | |
2 require File.expand_path('../../test_helper', __FILE__) | |
3 | |
4 class TimeEntryReportsControllerTest < ActionController::TestCase | |
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 | |
14 | |
15 def test_report_at_project_level | |
16 get :report, :project_id => 'ecookbook' | |
17 assert_response :success | |
18 assert_template 'report' | |
19 assert_tag :form, | |
20 :attributes => {:action => "/projects/ecookbook/time_entries/report", :id => 'query_form'} | |
21 end | |
22 | |
23 def test_report_all_projects | |
24 get :report | |
25 assert_response :success | |
26 assert_template 'report' | |
27 assert_tag :form, | |
28 :attributes => {:action => "/time_entries/report", :id => 'query_form'} | |
29 end | |
30 | |
31 def test_report_all_projects_denied | |
32 r = Role.anonymous | |
33 r.permissions.delete(:view_time_entries) | |
34 r.permissions_will_change! | |
35 r.save | |
36 get :report | |
37 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport' | |
38 end | |
39 | |
40 def test_report_all_projects_one_criteria | |
41 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] | |
42 assert_response :success | |
43 assert_template 'report' | |
44 assert_not_nil assigns(:total_hours) | |
45 assert_equal "8.65", "%.2f" % assigns(:total_hours) | |
46 end | |
47 | |
48 def test_report_all_time | |
49 get :report, :project_id => 1, :criterias => ['project', 'issue'] | |
50 assert_response :success | |
51 assert_template 'report' | |
52 assert_not_nil assigns(:total_hours) | |
53 assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
54 end | |
55 | |
56 def test_report_all_time_by_day | |
57 get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day' | |
58 assert_response :success | |
59 assert_template 'report' | |
60 assert_not_nil assigns(:total_hours) | |
61 assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
62 assert_tag :tag => 'th', :content => '2007-03-12' | |
63 end | |
64 | |
65 def test_report_one_criteria | |
66 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] | |
67 assert_response :success | |
68 assert_template 'report' | |
69 assert_not_nil assigns(:total_hours) | |
70 assert_equal "8.65", "%.2f" % assigns(:total_hours) | |
71 end | |
72 | |
73 def test_report_two_criterias | |
74 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] | |
75 assert_response :success | |
76 assert_template 'report' | |
77 assert_not_nil assigns(:total_hours) | |
78 assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
79 end | |
80 | |
81 def test_report_one_day | |
82 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criterias => ["member", "activity"] | |
83 assert_response :success | |
84 assert_template 'report' | |
85 assert_not_nil assigns(:total_hours) | |
86 assert_equal "4.25", "%.2f" % assigns(:total_hours) | |
87 end | |
88 | |
89 def test_report_at_issue_level | |
90 get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] | |
91 assert_response :success | |
92 assert_template 'report' | |
93 assert_not_nil assigns(:total_hours) | |
94 assert_equal "154.25", "%.2f" % assigns(:total_hours) | |
95 assert_tag :form, | |
96 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'} | |
97 end | |
98 | |
99 def test_report_custom_field_criteria | |
100 get :report, :project_id => 1, :criterias => ['project', 'cf_1', 'cf_7'] | |
101 assert_response :success | |
102 assert_template 'report' | |
103 assert_not_nil assigns(:total_hours) | |
104 assert_not_nil assigns(:criterias) | |
105 assert_equal 3, assigns(:criterias).size | |
106 assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
107 # Custom field column | |
108 assert_tag :tag => 'th', :content => 'Database' | |
109 # Custom field row | |
110 assert_tag :tag => 'td', :content => 'MySQL', | |
111 :sibling => { :tag => 'td', :attributes => { :class => 'hours' }, | |
112 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' }, | |
113 :content => '1' }} | |
114 # Second custom field column | |
115 assert_tag :tag => 'th', :content => 'Billable' | |
116 end | |
117 | |
118 def test_report_one_criteria_no_result | |
119 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project'] | |
120 assert_response :success | |
121 assert_template 'report' | |
122 assert_not_nil assigns(:total_hours) | |
123 assert_equal "0.00", "%.2f" % assigns(:total_hours) | |
124 end | |
125 | |
126 def test_report_all_projects_csv_export | |
127 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", | |
128 :criterias => ["project", "member", "activity"], :format => "csv" | |
129 assert_response :success | |
130 assert_equal 'text/csv', @response.content_type | |
131 lines = @response.body.chomp.split("\n") | |
132 # Headers | |
133 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', | |
134 lines.first | |
135 # Total row | |
136 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last | |
137 end | |
138 | |
139 def test_report_csv_export | |
140 get :report, :project_id => 1, :columns => 'month', | |
141 :from => "2007-01-01", :to => "2007-06-30", | |
142 :criterias => ["project", "member", "activity"], :format => "csv" | |
143 assert_response :success | |
144 assert_equal 'text/csv', @response.content_type | |
145 lines = @response.body.chomp.split("\n") | |
146 # Headers | |
147 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', | |
148 lines.first | |
149 # Total row | |
150 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last | |
151 end | |
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 | |
298 end |