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