Mercurial > hg > soundsoftware-site
comparison test/functional/time_entry_reports_controller_test.rb @ 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 -*- | 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 | |
2 require File.expand_path('../../test_helper', __FILE__) | 19 require File.expand_path('../../test_helper', __FILE__) |
3 | 20 |
4 class TimeEntryReportsControllerTest < ActionController::TestCase | 21 class TimeEntryReportsControllerTest < ActionController::TestCase |
5 tests TimelogController | 22 tests TimelogController |
6 | 23 |
71 assert_not_nil assigns(:report) | 88 assert_not_nil assigns(:report) |
72 assert_equal "8.65", "%.2f" % assigns(:report).total_hours | 89 assert_equal "8.65", "%.2f" % assigns(:report).total_hours |
73 end | 90 end |
74 | 91 |
75 def test_report_two_criteria | 92 def test_report_two_criteria |
76 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["member", "activity"] | 93 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"] |
77 assert_response :success | 94 assert_response :success |
78 assert_template 'report' | 95 assert_template 'report' |
79 assert_not_nil assigns(:report) | 96 assert_not_nil assigns(:report) |
80 assert_equal "162.90", "%.2f" % assigns(:report).total_hours | 97 assert_equal "162.90", "%.2f" % assigns(:report).total_hours |
81 end | 98 end |
89 get :report, :project_id => 1, :columns => 'day', :criteria => ["cf_#{field.id}"] | 106 get :report, :project_id => 1, :columns => 'day', :criteria => ["cf_#{field.id}"] |
90 assert_response :success | 107 assert_response :success |
91 end | 108 end |
92 | 109 |
93 def test_report_one_day | 110 def test_report_one_day |
94 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criteria => ["member", "activity"] | 111 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criteria => ["user", "activity"] |
95 assert_response :success | 112 assert_response :success |
96 assert_template 'report' | 113 assert_template 'report' |
97 assert_not_nil assigns(:report) | 114 assert_not_nil assigns(:report) |
98 assert_equal "4.25", "%.2f" % assigns(:report).total_hours | 115 assert_equal "4.25", "%.2f" % assigns(:report).total_hours |
99 end | 116 end |
100 | 117 |
101 def test_report_at_issue_level | 118 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"] | 119 get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"] |
103 assert_response :success | 120 assert_response :success |
104 assert_template 'report' | 121 assert_template 'report' |
105 assert_not_nil assigns(:report) | 122 assert_not_nil assigns(:report) |
106 assert_equal "154.25", "%.2f" % assigns(:report).total_hours | 123 assert_equal "154.25", "%.2f" % assigns(:report).total_hours |
107 assert_tag :form, | 124 assert_tag :form, |
108 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'} | 125 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'} |
109 end | 126 end |
110 | 127 |
111 def test_report_custom_field_criteria | 128 def test_report_by_week_should_use_commercial_year |
112 get :report, :project_id => 1, :criteria => ['project', 'cf_1', 'cf_7'] | 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'] | |
113 assert_response :success | 168 assert_response :success |
114 assert_template 'report' | 169 assert_template 'report' |
115 assert_not_nil assigns(:report) | 170 assert_not_nil assigns(:report) |
116 assert_equal 3, assigns(:report).criteria.size | 171 assert_equal 3, assigns(:report).criteria.size |
117 assert_equal "162.90", "%.2f" % assigns(:report).total_hours | 172 assert_equal "162.90", "%.2f" % assigns(:report).total_hours |
118 # Custom field column | 173 |
119 assert_tag :tag => 'th', :content => 'Database' | 174 # Custom fields columns |
175 assert_select 'th', :text => 'Database' | |
176 assert_select 'th', :text => 'Development status' | |
177 assert_select 'th', :text => 'Billable' | |
178 | |
120 # Custom field row | 179 # Custom field row |
121 assert_tag :tag => 'td', :content => 'MySQL', | 180 assert_select 'tr' do |
122 :sibling => { :tag => 'td', :attributes => { :class => 'hours' }, | 181 assert_select 'td', :text => 'MySQL' |
123 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' }, | 182 assert_select 'td.hours', :text => '1.00' |
124 :content => '1' }} | 183 end |
125 # Second custom field column | |
126 assert_tag :tag => 'th', :content => 'Billable' | |
127 end | 184 end |
128 | 185 |
129 def test_report_one_criteria_no_result | 186 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'] | 187 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criteria => ['project'] |
131 assert_response :success | 188 assert_response :success |
142 assert_tag :tag => 'td', :content => 'New' | 199 assert_tag :tag => 'td', :content => 'New' |
143 end | 200 end |
144 | 201 |
145 def test_report_all_projects_csv_export | 202 def test_report_all_projects_csv_export |
146 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", | 203 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", |
147 :criteria => ["project", "member", "activity"], :format => "csv" | 204 :criteria => ["project", "user", "activity"], :format => "csv" |
148 assert_response :success | 205 assert_response :success |
149 assert_equal 'text/csv; header=present', @response.content_type | 206 assert_equal 'text/csv; header=present', @response.content_type |
150 lines = @response.body.chomp.split("\n") | 207 lines = @response.body.chomp.split("\n") |
151 # Headers | 208 # Headers |
152 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', | 209 assert_equal 'Project,User,Activity,2007-3,2007-4,Total time', lines.first |
153 lines.first | |
154 # Total row | 210 # Total row |
155 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last | 211 assert_equal 'Total time,"","",154.25,8.65,162.90', lines.last |
156 end | 212 end |
157 | 213 |
158 def test_report_csv_export | 214 def test_report_csv_export |
159 get :report, :project_id => 1, :columns => 'month', | 215 get :report, :project_id => 1, :columns => 'month', |
160 :from => "2007-01-01", :to => "2007-06-30", | 216 :from => "2007-01-01", :to => "2007-06-30", |
161 :criteria => ["project", "member", "activity"], :format => "csv" | 217 :criteria => ["project", "user", "activity"], :format => "csv" |
162 assert_response :success | 218 assert_response :success |
163 assert_equal 'text/csv; header=present', @response.content_type | 219 assert_equal 'text/csv; header=present', @response.content_type |
164 lines = @response.body.chomp.split("\n") | 220 lines = @response.body.chomp.split("\n") |
165 # Headers | 221 # Headers |
166 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total', | 222 assert_equal 'Project,User,Activity,2007-3,2007-4,Total time', lines.first |
167 lines.first | |
168 # Total row | 223 # Total row |
169 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last | 224 assert_equal 'Total time,"","",154.25,8.65,162.90', lines.last |
170 end | 225 end |
171 | 226 |
172 def test_csv_big_5 | 227 def test_csv_big_5 |
173 Setting.default_language = "zh-TW" | 228 Setting.default_language = "zh-TW" |
174 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" | 229 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" |
194 assert_equal 7.3, te2.hours | 249 assert_equal 7.3, te2.hours |
195 assert_equal 3, te2.user_id | 250 assert_equal 3, te2.user_id |
196 | 251 |
197 get :report, :project_id => 1, :columns => 'day', | 252 get :report, :project_id => 1, :columns => 'day', |
198 :from => "2011-11-11", :to => "2011-11-11", | 253 :from => "2011-11-11", :to => "2011-11-11", |
199 :criteria => ["member"], :format => "csv" | 254 :criteria => ["user"], :format => "csv" |
200 assert_response :success | 255 assert_response :success |
201 assert_equal 'text/csv; header=present', @response.content_type | 256 assert_equal 'text/csv; header=present', @response.content_type |
202 lines = @response.body.chomp.split("\n") | 257 lines = @response.body.chomp.split("\n") |
203 # Headers | 258 # Headers |
204 s1 = "\xa6\xa8\xad\xfb,2011-11-11,\xc1`\xadp" | 259 s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xc1`\xadp" |
205 s2 = "\xc1`\xadp" | 260 s2 = "\xc1`\xadp" |
206 if s1.respond_to?(:force_encoding) | 261 if s1.respond_to?(:force_encoding) |
207 s1.force_encoding('Big5') | 262 s1.force_encoding('Big5') |
208 s2.force_encoding('Big5') | 263 s2.force_encoding('Big5') |
209 end | 264 end |
245 assert_equal 7.3, te2.hours | 300 assert_equal 7.3, te2.hours |
246 assert_equal 3, te2.user_id | 301 assert_equal 3, te2.user_id |
247 | 302 |
248 get :report, :project_id => 1, :columns => 'day', | 303 get :report, :project_id => 1, :columns => 'day', |
249 :from => "2011-11-11", :to => "2011-11-11", | 304 :from => "2011-11-11", :to => "2011-11-11", |
250 :criteria => ["member"], :format => "csv" | 305 :criteria => ["user"], :format => "csv" |
251 assert_response :success | 306 assert_response :success |
252 assert_equal 'text/csv; header=present', @response.content_type | 307 assert_equal 'text/csv; header=present', @response.content_type |
253 lines = @response.body.chomp.split("\n") | 308 lines = @response.body.chomp.split("\n") |
254 # Headers | 309 # Headers |
255 s1 = "\xa6\xa8\xad\xfb,2011-11-11,\xc1`\xadp" | 310 s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xc1`\xadp" |
256 if s1.respond_to?(:force_encoding) | 311 if s1.respond_to?(:force_encoding) |
257 s1.force_encoding('Big5') | 312 s1.force_encoding('Big5') |
258 end | 313 end |
259 assert_equal s1, lines.first | 314 assert_equal s1, lines.first |
260 # Total row | 315 # Total row |
286 assert_equal 7.3, te2.hours | 341 assert_equal 7.3, te2.hours |
287 assert_equal 3, te2.user_id | 342 assert_equal 3, te2.user_id |
288 | 343 |
289 get :report, :project_id => 1, :columns => 'day', | 344 get :report, :project_id => 1, :columns => 'day', |
290 :from => "2011-11-11", :to => "2011-11-11", | 345 :from => "2011-11-11", :to => "2011-11-11", |
291 :criteria => ["member"], :format => "csv" | 346 :criteria => ["user"], :format => "csv" |
292 assert_response :success | 347 assert_response :success |
293 assert_equal 'text/csv; header=present', @response.content_type | 348 assert_equal 'text/csv; header=present', @response.content_type |
294 lines = @response.body.chomp.split("\n") | 349 lines = @response.body.chomp.split("\n") |
295 # Headers | 350 # Headers |
296 s1 = "Membre;2011-11-11;Total" | 351 s1 = "Utilisateur;2011-11-11;Temps total" |
297 s2 = "Total" | 352 s2 = "Temps total" |
298 if s1.respond_to?(:force_encoding) | 353 if s1.respond_to?(:force_encoding) |
299 s1.force_encoding('ISO-8859-1') | 354 s1.force_encoding('ISO-8859-1') |
300 s2.force_encoding('ISO-8859-1') | 355 s2.force_encoding('ISO-8859-1') |
301 end | 356 end |
302 assert_equal s1, lines.first | 357 assert_equal s1, lines.first |