annotate .svn/pristine/fe/fe260260eb5a4d5517ce882020d2298022f2b0e4.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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