##// END OF EJS Templates
add functional test to export time entry report csv encoded in Big5 on Traditional Chinese locale (#8549)...
Toshi MARUYAMA -
r7691:95ef93104822
parent child
Show More
@@ -1,146 +1,191
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,
5 fixtures :projects, :enabled_modules, :roles, :members, :member_roles,
6 :issues, :time_entries, :users, :trackers, :enumerations,
6 :issues, :time_entries, :users, :trackers, :enumerations,
7 :issue_statuses, :custom_fields, :custom_values
7 :issue_statuses, :custom_fields, :custom_values
8
8
9 def setup
10 Setting.default_language = "en"
11 end
12
9 def test_report_at_project_level
13 def test_report_at_project_level
10 get :report, :project_id => 'ecookbook'
14 get :report, :project_id => 'ecookbook'
11 assert_response :success
15 assert_response :success
12 assert_template 'report'
16 assert_template 'report'
13 assert_tag :form,
17 assert_tag :form,
14 :attributes => {:action => "/projects/ecookbook/time_entries/report", :id => 'query_form'}
18 :attributes => {:action => "/projects/ecookbook/time_entries/report", :id => 'query_form'}
15 end
19 end
16
20
17 def test_report_all_projects
21 def test_report_all_projects
18 get :report
22 get :report
19 assert_response :success
23 assert_response :success
20 assert_template 'report'
24 assert_template 'report'
21 assert_tag :form,
25 assert_tag :form,
22 :attributes => {:action => "/time_entries/report", :id => 'query_form'}
26 :attributes => {:action => "/time_entries/report", :id => 'query_form'}
23 end
27 end
24
28
25 def test_report_all_projects_denied
29 def test_report_all_projects_denied
26 r = Role.anonymous
30 r = Role.anonymous
27 r.permissions.delete(:view_time_entries)
31 r.permissions.delete(:view_time_entries)
28 r.permissions_will_change!
32 r.permissions_will_change!
29 r.save
33 r.save
30 get :report
34 get :report
31 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport'
35 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport'
32 end
36 end
33
37
34 def test_report_all_projects_one_criteria
38 def test_report_all_projects_one_criteria
35 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
39 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
36 assert_response :success
40 assert_response :success
37 assert_template 'report'
41 assert_template 'report'
38 assert_not_nil assigns(:total_hours)
42 assert_not_nil assigns(:total_hours)
39 assert_equal "8.65", "%.2f" % assigns(:total_hours)
43 assert_equal "8.65", "%.2f" % assigns(:total_hours)
40 end
44 end
41
45
42 def test_report_all_time
46 def test_report_all_time
43 get :report, :project_id => 1, :criterias => ['project', 'issue']
47 get :report, :project_id => 1, :criterias => ['project', 'issue']
44 assert_response :success
48 assert_response :success
45 assert_template 'report'
49 assert_template 'report'
46 assert_not_nil assigns(:total_hours)
50 assert_not_nil assigns(:total_hours)
47 assert_equal "162.90", "%.2f" % assigns(:total_hours)
51 assert_equal "162.90", "%.2f" % assigns(:total_hours)
48 end
52 end
49
53
50 def test_report_all_time_by_day
54 def test_report_all_time_by_day
51 get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day'
55 get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day'
52 assert_response :success
56 assert_response :success
53 assert_template 'report'
57 assert_template 'report'
54 assert_not_nil assigns(:total_hours)
58 assert_not_nil assigns(:total_hours)
55 assert_equal "162.90", "%.2f" % assigns(:total_hours)
59 assert_equal "162.90", "%.2f" % assigns(:total_hours)
56 assert_tag :tag => 'th', :content => '2007-03-12'
60 assert_tag :tag => 'th', :content => '2007-03-12'
57 end
61 end
58
62
59 def test_report_one_criteria
63 def test_report_one_criteria
60 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
64 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
61 assert_response :success
65 assert_response :success
62 assert_template 'report'
66 assert_template 'report'
63 assert_not_nil assigns(:total_hours)
67 assert_not_nil assigns(:total_hours)
64 assert_equal "8.65", "%.2f" % assigns(:total_hours)
68 assert_equal "8.65", "%.2f" % assigns(:total_hours)
65 end
69 end
66
70
67 def test_report_two_criterias
71 def test_report_two_criterias
68 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
72 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
69 assert_response :success
73 assert_response :success
70 assert_template 'report'
74 assert_template 'report'
71 assert_not_nil assigns(:total_hours)
75 assert_not_nil assigns(:total_hours)
72 assert_equal "162.90", "%.2f" % assigns(:total_hours)
76 assert_equal "162.90", "%.2f" % assigns(:total_hours)
73 end
77 end
74
78
75 def test_report_one_day
79 def test_report_one_day
76 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criterias => ["member", "activity"]
80 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criterias => ["member", "activity"]
77 assert_response :success
81 assert_response :success
78 assert_template 'report'
82 assert_template 'report'
79 assert_not_nil assigns(:total_hours)
83 assert_not_nil assigns(:total_hours)
80 assert_equal "4.25", "%.2f" % assigns(:total_hours)
84 assert_equal "4.25", "%.2f" % assigns(:total_hours)
81 end
85 end
82
86
83 def test_report_at_issue_level
87 def test_report_at_issue_level
84 get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
88 get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
85 assert_response :success
89 assert_response :success
86 assert_template 'report'
90 assert_template 'report'
87 assert_not_nil assigns(:total_hours)
91 assert_not_nil assigns(:total_hours)
88 assert_equal "154.25", "%.2f" % assigns(:total_hours)
92 assert_equal "154.25", "%.2f" % assigns(:total_hours)
89 assert_tag :form,
93 assert_tag :form,
90 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'}
94 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'}
91 end
95 end
92
96
93 def test_report_custom_field_criteria
97 def test_report_custom_field_criteria
94 get :report, :project_id => 1, :criterias => ['project', 'cf_1', 'cf_7']
98 get :report, :project_id => 1, :criterias => ['project', 'cf_1', 'cf_7']
95 assert_response :success
99 assert_response :success
96 assert_template 'report'
100 assert_template 'report'
97 assert_not_nil assigns(:total_hours)
101 assert_not_nil assigns(:total_hours)
98 assert_not_nil assigns(:criterias)
102 assert_not_nil assigns(:criterias)
99 assert_equal 3, assigns(:criterias).size
103 assert_equal 3, assigns(:criterias).size
100 assert_equal "162.90", "%.2f" % assigns(:total_hours)
104 assert_equal "162.90", "%.2f" % assigns(:total_hours)
101 # Custom field column
105 # Custom field column
102 assert_tag :tag => 'th', :content => 'Database'
106 assert_tag :tag => 'th', :content => 'Database'
103 # Custom field row
107 # Custom field row
104 assert_tag :tag => 'td', :content => 'MySQL',
108 assert_tag :tag => 'td', :content => 'MySQL',
105 :sibling => { :tag => 'td', :attributes => { :class => 'hours' },
109 :sibling => { :tag => 'td', :attributes => { :class => 'hours' },
106 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
110 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
107 :content => '1' }}
111 :content => '1' }}
108 # Second custom field column
112 # Second custom field column
109 assert_tag :tag => 'th', :content => 'Billable'
113 assert_tag :tag => 'th', :content => 'Billable'
110 end
114 end
111
115
112 def test_report_one_criteria_no_result
116 def test_report_one_criteria_no_result
113 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project']
117 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project']
114 assert_response :success
118 assert_response :success
115 assert_template 'report'
119 assert_template 'report'
116 assert_not_nil assigns(:total_hours)
120 assert_not_nil assigns(:total_hours)
117 assert_equal "0.00", "%.2f" % assigns(:total_hours)
121 assert_equal "0.00", "%.2f" % assigns(:total_hours)
118 end
122 end
119
123
120 def test_report_all_projects_csv_export
124 def test_report_all_projects_csv_export
121 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30",
125 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30",
122 :criterias => ["project", "member", "activity"], :format => "csv"
126 :criterias => ["project", "member", "activity"], :format => "csv"
123 assert_response :success
127 assert_response :success
124 assert_equal 'text/csv', @response.content_type
128 assert_equal 'text/csv', @response.content_type
125 lines = @response.body.chomp.split("\n")
129 lines = @response.body.chomp.split("\n")
126 # Headers
130 # Headers
127 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total',
131 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total',
128 lines.first
132 lines.first
129 # Total row
133 # Total row
130 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
134 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
131 end
135 end
132
136
133 def test_report_csv_export
137 def test_report_csv_export
134 get :report, :project_id => 1, :columns => 'month',
138 get :report, :project_id => 1, :columns => 'month',
135 :from => "2007-01-01", :to => "2007-06-30",
139 :from => "2007-01-01", :to => "2007-06-30",
136 :criterias => ["project", "member", "activity"], :format => "csv"
140 :criterias => ["project", "member", "activity"], :format => "csv"
137 assert_response :success
141 assert_response :success
138 assert_equal 'text/csv', @response.content_type
142 assert_equal 'text/csv', @response.content_type
139 lines = @response.body.chomp.split("\n")
143 lines = @response.body.chomp.split("\n")
140 # Headers
144 # Headers
141 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total',
145 assert_equal 'Project,Member,Activity,2007-1,2007-2,2007-3,2007-4,2007-5,2007-6,Total',
142 lines.first
146 lines.first
143 # Total row
147 # Total row
144 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
148 assert_equal 'Total,"","","","",154.25,8.65,"","",162.90', lines.last
145 end
149 end
150
151 def test_csv_big_5
152 Setting.default_language = "zh-TW"
153 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
154 str_big5 = "\xa4@\xa4\xeb"
155 if str_utf8.respond_to?(:force_encoding)
156 str_utf8.force_encoding('UTF-8')
157 str_big5.force_encoding('Big5')
158 end
159 user = User.find_by_id(3)
160 user.firstname = str_utf8
161 user.lastname = "test-lastname"
162 assert user.save
163 comments = "test_csv_big_5"
164 te1 = TimeEntry.create(:spent_on => '2011-11-11',
165 :hours => 7.3,
166 :project => Project.find(1),
167 :user => user,
168 :activity => TimeEntryActivity.find_by_name('Design'),
169 :comments => comments)
170
171 te2 = TimeEntry.find_by_comments(comments)
172 assert_not_nil te2
173 assert_equal 7.3, te2.hours
174 assert_equal 3, te2.user_id
175
176 get :report, :project_id => 1, :columns => 'day',
177 :from => "2011-11-11", :to => "2011-11-11",
178 :criterias => ["member"], :format => "csv"
179 assert_response :success
180 assert_equal 'text/csv', @response.content_type
181 lines = @response.body.chomp.split("\n")
182 # Headers
183 s1 = "\xa6\xa8\xad\xfb,2011-11-11,\xc1`\xadp"
184 if s1.respond_to?(:force_encoding)
185 s1.force_encoding('Big5')
186 end
187 assert_equal s1, lines.first
188 # Total row
189 assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1]
190 end
146 end
191 end
General Comments 0
You need to be logged in to leave comments. Login now