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