Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# This file is part of Koha |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# 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 Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
# use Test::NoWarnings; |
21 |
use Test::More tests => 18; |
22 |
|
23 |
use Koha::ERM::EUsage::SushiCounter; |
24 |
use Koha::Database; |
25 |
use JSON qw( decode_json ); |
26 |
use File::Basename qw( dirname ); |
27 |
use File::Slurp; |
28 |
|
29 |
use t::lib::TestBuilder; |
30 |
|
31 |
my $schema = Koha::Database->new->schema; |
32 |
my $builder = t::lib::TestBuilder->new; |
33 |
|
34 |
my $test_data_base_dir = "/../../../../data/erm/eusage/COUNTER_5.1"; |
35 |
my $sushi_response_file_TR_J1 = dirname(__FILE__) . $test_data_base_dir . "/TR_J1.json"; |
36 |
my $sushi_counter_51_response_TR_J1 = decode_json( read_file($sushi_response_file_TR_J1) ); |
37 |
my $sushi_counter_TR_J1 = |
38 |
Koha::ERM::EUsage::SushiCounter->new( { version => '5.1', response => $sushi_counter_51_response_TR_J1 } ); |
39 |
|
40 |
subtest 'TR_J1 _COUNTER_report_header' => sub { |
41 |
|
42 |
plan tests => 43; |
43 |
|
44 |
my @report_header = $sushi_counter_TR_J1->_COUNTER_report_header; |
45 |
|
46 |
# Header row #1 - Report_Name |
47 |
is( $report_header[0][0], 'Report_Name', '1st row is report name' ); |
48 |
is( $report_header[0][1], 'Journal Requests (Excluding OA_Gold)', '1st row is report name' ); |
49 |
is( $report_header[0][2], undef, '1st row is report name' ); |
50 |
|
51 |
# Header row #2 - Report_ID |
52 |
is( $report_header[1][0], 'Report_ID', '2nd row is report name' ); |
53 |
is( $report_header[1][1], 'TR_J1', '2nd row is report name' ); |
54 |
is( $report_header[1][2], undef, '2nd row is report name' ); |
55 |
|
56 |
# Header row #3 - Release |
57 |
is( $report_header[2][0], 'Release', '3rd row is counter release' ); |
58 |
is( $report_header[2][1], '5.1', '3rd row is counter release' ); |
59 |
is( $report_header[2][2], undef, '3rd row is counter release' ); |
60 |
|
61 |
# Header row #4 - Institution_Name |
62 |
is( $report_header[3][0], 'Institution_Name', '4th row is institution name' ); |
63 |
is( $report_header[3][1], 'Test Institution', '4th row is institution name' ); |
64 |
is( $report_header[3][2], undef, '4th row is institution name' ); |
65 |
|
66 |
# Header row #5 - Institution_ID |
67 |
is( $report_header[4][0], 'Institution_ID', '5th row is institution id' ); |
68 |
like( $report_header[4][1], qr/Proprietary:TInsti:EALTEST001|ISNI:0000000123456789/, '5th row is institution id' ); |
69 |
is( $report_header[4][2], undef, '5th row is institution id' ); |
70 |
|
71 |
# Header row #6 - Metric_Types |
72 |
is( $report_header[5][0], 'Metric_Types', '6th row is metric types' ); |
73 |
is( $report_header[5][1], 'Total_Item_Requests; Unique_Item_Requests', '6th row is metric types' ); |
74 |
is( $report_header[5][2], undef, '6th row is metric types' ); |
75 |
|
76 |
# Header row #7 - Report_Filters |
77 |
is( $report_header[6][0], 'Report_Filters', '7th row is report filters' ); |
78 |
like( $report_header[6][1], qr/End_Date:2022-09-30/, '7th row is report filters' ); |
79 |
like( $report_header[6][1], qr/Access_Method:Regular/, '7th row is report filters' ); |
80 |
like( |
81 |
$report_header[6][1], qr/Metric_Type:Total_Item_Requests\|Unique_Item_Requests/, |
82 |
'7th row is report filters' |
83 |
); |
84 |
like( $report_header[6][1], qr/Data_Type:Journal/, '7th row is report filters' ); |
85 |
like( $report_header[6][1], qr/Begin_Date:2021-09-01/, '7th row is report filters' ); |
86 |
like( $report_header[6][1], qr/Access_Type:Controlled/, '7th row is report filters' ); |
87 |
is( $report_header[6][2], undef, '7th row is report filters' ); |
88 |
|
89 |
# Header row #8 - Report_Attributes |
90 |
is( $report_header[7][0], 'Report_Attributes', '8th row is report attributes' ); |
91 |
is( $report_header[7][1], '', '8th row is report attributes' ); |
92 |
is( $report_header[7][2], undef, '8th row is report attributes' ); |
93 |
|
94 |
# Header row #9 - Exceptions |
95 |
is( $report_header[8][0], 'Exceptions', '9th row is exceptions' ); |
96 |
is( $report_header[8][1], '', '9th row is exceptions' ); |
97 |
is( $report_header[8][2], undef, '9th row is exceptions' ); |
98 |
|
99 |
# Header row #10 - Reporting_Period |
100 |
is( $report_header[9][0], 'Reporting_Period', '10th row is reporting period' ); |
101 |
is( $report_header[9][1], 'Begin_Date=2021-09-01; End_Date=2022-09-30', '10th row is reporting period' ); |
102 |
is( $report_header[9][2], undef, '10th row is reporting period' ); |
103 |
|
104 |
# Header row #11 - Created |
105 |
is( $report_header[10][0], 'Created', '11th row is created' ); |
106 |
is( $report_header[10][1], '2023-08-29T07:11:41Z', '11th row is created' ); |
107 |
is( $report_header[10][2], undef, '11th row is created' ); |
108 |
|
109 |
# Header row #12 - Created |
110 |
is( $report_header[11][0], 'Created_By', '12th row is created by' ); |
111 |
is( $report_header[11][1], 'Test Systems Inc.', '12th row is created by' ); |
112 |
is( $report_header[11][2], undef, '12th row is created by' ); |
113 |
|
114 |
# Header row #13 - Registry_Record |
115 |
is( $report_header[12][0], 'Registry_Record', '13th row is empty' ); |
116 |
|
117 |
# Header row #14 - This needs to be empty |
118 |
is( $report_header[13][0], '', '14th row is empty' ); |
119 |
}; |
120 |
|
121 |
subtest 'TR_J1 _COUNTER_report_column_headings' => sub { |
122 |
|
123 |
plan tests => 19; |
124 |
|
125 |
my @report_column_headings = $sushi_counter_TR_J1->_COUNTER_report_column_headings; |
126 |
|
127 |
# Standard TR_J1 column headings |
128 |
is( $report_column_headings[0][0], 'Title', '1st column heading is title' ); |
129 |
is( $report_column_headings[0][1], 'Publisher', '2nd column heading is publisher' ); |
130 |
is( $report_column_headings[0][2], 'Publisher_ID', '3rd column heading is publisher ID' ); |
131 |
is( $report_column_headings[0][3], 'Platform', '4th column heading is platform' ); |
132 |
is( $report_column_headings[0][4], 'DOI', '5th column heading is DOI' ); |
133 |
is( $report_column_headings[0][5], 'Proprietary_ID', '6th column heading is proprietary ID' ); |
134 |
is( $report_column_headings[0][6], 'Print_ISSN', '7th column heading is print ISSN' ); |
135 |
is( $report_column_headings[0][7], 'Online_ISSN', '8th column heading is online ISSN' ); |
136 |
is( $report_column_headings[0][8], 'URI', '9th column heading is URI' ); |
137 |
is( $report_column_headings[0][9], 'Metric_Type', '10th column heading is metric type' ); |
138 |
is( $report_column_headings[0][10], 'Reporting_Period_Total', '11th column heading is reporting period total' ); |
139 |
|
140 |
# Months column headings |
141 |
is( $report_column_headings[0][11], 'Sep 2021', '12th column is month column heading' ); |
142 |
is( $report_column_headings[0][12], 'Oct 2021', '13th column is month column heading' ); |
143 |
is( $report_column_headings[0][13], 'Nov 2021', '14th column is month column heading' ); |
144 |
is( $report_column_headings[0][14], 'Dec 2021', '15th column is month column heading' ); |
145 |
is( $report_column_headings[0][15], 'Jan 2022', '16th column is month column heading' ); |
146 |
is( $report_column_headings[0][16], 'Feb 2022', '17th column is month column heading' ); |
147 |
|
148 |
# ... period is september 2021 to september 2022, i.e. 13 months |
149 |
is( $report_column_headings[0][23], 'Sep 2022', '23rd column is the last month column heading' ); |
150 |
is( $report_column_headings[0][24], undef, '24th column is empty, no more months' ); |
151 |
}; |
152 |
|
153 |
subtest 'TR_J1 _COUNTER_report_body' => sub { |
154 |
|
155 |
plan tests => 16; |
156 |
|
157 |
my @report_body = $sushi_counter_TR_J1->_COUNTER_report_body; |
158 |
|
159 |
# The same title is sequential but for different metric types |
160 |
is( $report_body[0][0], 'Education and Training', 'same title, different metric type' ); |
161 |
is( $report_body[1][0], 'Education and Training', 'same title, different metric type' ); |
162 |
is( $report_body[0][9], 'Total_Item_Requests', 'same title, different metric type' ); |
163 |
is( $report_body[1][9], 'Unique_Item_Requests', 'same title, different metric type' ); |
164 |
|
165 |
# The data is in the correct column |
166 |
is( $report_body[2][0], 'Test Journal', '1st column is title' ); |
167 |
is( $report_body[2][1], 'Test Publisher', '2nd column is publisher' ); |
168 |
is( $report_body[2][2], '0000000123456789', '3rd column heading is publisher ID' ); |
169 |
is( $report_body[2][3], 'Unit Test Library', '4th column is platform' ); |
170 |
is( $report_body[2][4], '10.1002/(ISSN)1111-2222', '5th column is DOI' ); |
171 |
is( $report_body[2][5], 'TInsti:ABC1', '6th column is proprietary ID' ); |
172 |
is( $report_body[2][6], '7777-8888', '7th column is print ISSN' ); |
173 |
is( $report_body[2][7], '5555-6666', '8th column is online ISSN' ); |
174 |
is( $report_body[2][8], '', '9th column is URI' ); |
175 |
is( $report_body[2][9], 'Total_Item_Requests', '10th column is metric type' ); |
176 |
is( $report_body[2][10], 2, '11th column is reporting period total' ); |
177 |
|
178 |
# The period total is the sum of all the month columns |
179 |
my $stats_total = 0; |
180 |
for ( my $i = 11 ; $i < 24 ; $i++ ) { |
181 |
$stats_total += $report_body[0][$i]; |
182 |
} |
183 |
is( |
184 |
$report_body[0][10], $stats_total, |
185 |
'Reporting period total matches the sum of all the monthly usage statistics' |
186 |
); |
187 |
}; |
188 |
|
189 |
my $sushi_response_file_TR_J2 = dirname(__FILE__) . $test_data_base_dir . "/TR_J2.json"; |
190 |
my $sushi_counter_51_response_TR_J2 = decode_json( read_file($sushi_response_file_TR_J2) ); |
191 |
my $sushi_counter_TR_J2 = Koha::ERM::EUsage::SushiCounter->new( { response => $sushi_counter_51_response_TR_J2 } ); |
192 |
|
193 |
subtest 'TR_J2 _COUNTER_report_header' => sub { |
194 |
|
195 |
plan tests => 42; |
196 |
|
197 |
my @report_header = $sushi_counter_TR_J2->_COUNTER_report_header; |
198 |
|
199 |
# Header row #1 - Report_Name |
200 |
is( $report_header[0][0], 'Report_Name', '1st row is report name' ); |
201 |
is( $report_header[0][1], 'Journal Access Denied', '1st row is report name' ); |
202 |
is( $report_header[0][2], undef, '1st row is report name' ); |
203 |
|
204 |
# Header row #2 - Report_ID |
205 |
is( $report_header[1][0], 'Report_ID', '2nd row is report name' ); |
206 |
is( $report_header[1][1], 'TR_J2', '2nd row is report name' ); |
207 |
is( $report_header[1][2], undef, '2nd row is report name' ); |
208 |
|
209 |
# Header row #3 - Release |
210 |
is( $report_header[2][0], 'Release', '3rd row is counter release' ); |
211 |
is( $report_header[2][1], '5.1', '3rd row is counter release' ); |
212 |
is( $report_header[2][2], undef, '3rd row is counter release' ); |
213 |
|
214 |
# Header row #4 - Institution_Name |
215 |
is( $report_header[3][0], 'Institution_Name', '4th row is institution name' ); |
216 |
is( $report_header[3][1], 'Sample Institution', '4th row is institution name' ); |
217 |
is( $report_header[3][2], undef, '4th row is institution name' ); |
218 |
|
219 |
# Header row #5 - Institution_ID |
220 |
is( $report_header[4][0], 'Institution_ID', '5th row is institution id' ); |
221 |
is( $report_header[4][1], 'ISNI:1234123412341234', '5th row is institution id' ); |
222 |
is( $report_header[4][2], undef, '5th row is institution id' ); |
223 |
|
224 |
# Header row #6 - Metric_Types |
225 |
is( $report_header[5][0], 'Metric_Types', '6th row is metric types' ); |
226 |
is( $report_header[5][1], 'Limit_Exceeded; No_License', '6th row is metric types' ); |
227 |
is( $report_header[5][2], undef, '6th row is metric types' ); |
228 |
|
229 |
# Header row #7 - Report_Filters |
230 |
is( $report_header[6][0], 'Report_Filters', '7th row is report filters' ); |
231 |
like( $report_header[6][1], qr/Metric_Type:Limit_Exceeded\|No_License/, '7th row is report filters' ); |
232 |
like( $report_header[6][1], qr/Begin_Date:2022-01-01/, '7th row is report filters' ); |
233 |
like( $report_header[6][1], qr/End_Date:2022-03-31/, '7th row is report filters' ); |
234 |
like( $report_header[6][1], qr/Access_Method:Regular/, '7th row is report filters' ); |
235 |
like( $report_header[6][1], qr/Data_Type:Journal/, '7th row is report filters' ); |
236 |
|
237 |
is( $report_header[6][2], undef, '7th row is report filters' ); |
238 |
|
239 |
# Header row #8 - Report_Attributes |
240 |
is( $report_header[7][0], 'Report_Attributes', '8th row is report attributes' ); |
241 |
is( $report_header[7][1], '', '8th row is report attributes' ); |
242 |
is( $report_header[7][2], undef, '8th row is report attributes' ); |
243 |
|
244 |
# Header row #9 - Exceptions |
245 |
is( $report_header[8][0], 'Exceptions', '9th row is exceptions' ); |
246 |
is( $report_header[8][1], '', '9th row is exceptions' ); |
247 |
is( $report_header[8][2], undef, '9th row is exceptions' ); |
248 |
|
249 |
# Header row #10 - Reporting_Period |
250 |
is( $report_header[9][0], 'Reporting_Period', '10th row is reporting period' ); |
251 |
is( $report_header[9][1], 'Begin_Date=2022-01-01; End_Date=2022-03-31', '10th row is reporting period' ); |
252 |
is( $report_header[9][2], undef, '10th row is reporting period' ); |
253 |
|
254 |
# Header row #11 - Created |
255 |
is( $report_header[10][0], 'Created', '11th row is created' ); |
256 |
is( $report_header[10][1], '2023-02-15T09:11:12Z', '11th row is created' ); |
257 |
is( $report_header[10][2], undef, '11th row is created' ); |
258 |
|
259 |
# Header row #12 - Created |
260 |
is( $report_header[11][0], 'Created_By', '12th row is created by' ); |
261 |
is( $report_header[11][1], 'Sample Publisher', '12th row is created by' ); |
262 |
is( $report_header[11][2], undef, '12th row is created by' ); |
263 |
|
264 |
# Header row #13 - Registry_Record |
265 |
is( $report_header[12][0], 'Registry_Record', '13th row is Registry_Record' ); |
266 |
|
267 |
# Header row #14 - This needs to be empty |
268 |
is( $report_header[13][0], '', '14th row is empty' ); |
269 |
}; |
270 |
|
271 |
subtest 'TR_J2 _COUNTER_report_column_headings' => sub { |
272 |
|
273 |
plan tests => 15; |
274 |
|
275 |
my @report_column_headings = $sushi_counter_TR_J2->_COUNTER_report_column_headings; |
276 |
|
277 |
# Standard TR_J2 column headings |
278 |
is( $report_column_headings[0][0], 'Title', '1st column heading is title' ); |
279 |
is( $report_column_headings[0][1], 'Publisher', '2nd column heading is publisher' ); |
280 |
is( $report_column_headings[0][2], 'Publisher_ID', '3rd column heading is publisher ID' ); |
281 |
is( $report_column_headings[0][3], 'Platform', '4th column heading is platform' ); |
282 |
is( $report_column_headings[0][4], 'DOI', '5th column heading is DOI' ); |
283 |
is( $report_column_headings[0][5], 'Proprietary_ID', '6th column heading is proprietary ID' ); |
284 |
is( $report_column_headings[0][6], 'Print_ISSN', '7th column heading is print ISSN' ); |
285 |
is( $report_column_headings[0][7], 'Online_ISSN', '8th column heading is online ISSN' ); |
286 |
is( $report_column_headings[0][8], 'URI', '9th column heading is URI' ); |
287 |
is( $report_column_headings[0][9], 'Metric_Type', '10th column heading is metric type' ); |
288 |
is( $report_column_headings[0][10], 'Reporting_Period_Total', '11th column heading is reporting period total' ); |
289 |
|
290 |
# Months column headings |
291 |
is( $report_column_headings[0][11], 'Jan 2022', '12th column is month column heading' ); |
292 |
is( $report_column_headings[0][12], 'Feb 2022', '13th column is another month column heading' ); |
293 |
is( $report_column_headings[0][13], 'Mar 2022', '14th column is the last month column heading' ); |
294 |
is( $report_column_headings[0][14], undef, '15th column is empty, no more months' ); |
295 |
}; |
296 |
|
297 |
subtest 'TR_J2 _COUNTER_report_body' => sub { |
298 |
|
299 |
plan tests => 16; |
300 |
|
301 |
my @report_body = $sushi_counter_TR_J2->_COUNTER_report_body; |
302 |
|
303 |
# The same title is sequential but for different metric types |
304 |
is( $report_body[0][0], 'Title 3', 'same title, different metric type' ); |
305 |
is( $report_body[1][0], 'Title 3', 'same title, same metric type' ); |
306 |
is( $report_body[0][9], 'Limit_Exceeded', '1st title, different metric_type' ); |
307 |
is( $report_body[1][9], 'No_License', '1sd title, different metric_type' ); |
308 |
|
309 |
# The data is in the correct column |
310 |
is( $report_body[2][0], 'Another title', '1st column is title' ); |
311 |
is( $report_body[2][1], 'Another publisher', '2nd column is publisher' ); |
312 |
is( $report_body[2][2], '4321432143214321', '3rd column is publisher ID and shows because there is ISNI' ); |
313 |
is( $report_body[2][3], 'Platform 1', '4th column is platform' ); |
314 |
is( $report_body[2][4], '10.9999/xxxxt03', '5th column is DOI' ); |
315 |
is( $report_body[2][5], 'P1:T03', '6th column is proprietary ID' ); |
316 |
is( $report_body[2][6], '', '7th column is print ISSN' ); |
317 |
is( $report_body[2][7], '1234-4321', '8th column is online ISSN' ); |
318 |
is( $report_body[2][8], '', '9th column is URI' ); |
319 |
is( $report_body[2][9], 'Limit_Exceeded', '10th column is metric type' ); |
320 |
is( $report_body[2][10], 388, '11th column is reporting period total' ); |
321 |
|
322 |
# The period total is the sum of all the month columns |
323 |
my $stats_total = 0; |
324 |
for ( my $i = 11 ; $i < 14 ; $i++ ) { |
325 |
$stats_total += $report_body[0][$i]; |
326 |
} |
327 |
|
328 |
is( |
329 |
$report_body[0][10], $stats_total, |
330 |
'Reporting period total matches the sum of all the monthly usage statistics' |
331 |
); |
332 |
}; |
333 |
|
334 |
my $sushi_response_file_TR_J3 = dirname(__FILE__) . $test_data_base_dir . "/TR_J3.json"; |
335 |
my $sushi_counter_51_response_TR_J3 = decode_json( read_file($sushi_response_file_TR_J3) ); |
336 |
my $sushi_counter_TR_J3 = Koha::ERM::EUsage::SushiCounter->new( { response => $sushi_counter_51_response_TR_J3 } ); |
337 |
|
338 |
subtest 'TR_J3 _COUNTER_report_header' => sub { |
339 |
|
340 |
plan tests => 42; |
341 |
|
342 |
my @report_header = $sushi_counter_TR_J3->_COUNTER_report_header; |
343 |
|
344 |
# Header row #1 - Report_Name |
345 |
is( $report_header[0][0], 'Report_Name', '1st row is report name' ); |
346 |
is( $report_header[0][1], 'Journal Usage by Access Type', '1st row is report name' ); |
347 |
is( $report_header[0][2], undef, '1st row is report name' ); |
348 |
|
349 |
# Header row #2 - Report_ID |
350 |
is( $report_header[1][0], 'Report_ID', '2nd row is report name' ); |
351 |
is( $report_header[1][1], 'TR_J3', '2nd row is report name' ); |
352 |
is( $report_header[1][2], undef, '2nd row is report name' ); |
353 |
|
354 |
# Header row #3 - Release |
355 |
is( $report_header[2][0], 'Release', '3rd row is counter release' ); |
356 |
is( $report_header[2][1], '5.1', '3rd row is counter release' ); |
357 |
is( $report_header[2][2], undef, '3rd row is counter release' ); |
358 |
|
359 |
# Header row #4 - Institution_Name |
360 |
is( $report_header[3][0], 'Institution_Name', '4th row is institution name' ); |
361 |
is( $report_header[3][1], 'Sample Institution', '4th row is institution name' ); |
362 |
is( $report_header[3][2], undef, '4th row is institution name' ); |
363 |
|
364 |
# Header row #5 - Institution_ID |
365 |
is( $report_header[4][0], 'Institution_ID', '5th row is institution id' ); |
366 |
is( $report_header[4][1], 'ISNI:1234123412341234', '5th row is institution id' ); |
367 |
is( $report_header[4][2], undef, '5th row is institution id' ); |
368 |
|
369 |
# Header row #6 - Metric_Types |
370 |
is( $report_header[5][0], 'Metric_Types', '6th row is metric types' ); |
371 |
is( |
372 |
$report_header[5][1], |
373 |
'Total_Item_Investigations; Total_Item_Requests; Unique_Item_Investigations; Unique_Item_Requests', |
374 |
'6th row is metric types' |
375 |
); |
376 |
is( $report_header[5][2], undef, '6th row is metric types' ); |
377 |
|
378 |
# Header row #7 - Report_Filters |
379 |
is( $report_header[6][0], 'Report_Filters', '7th row is report filters' ); |
380 |
like( |
381 |
$report_header[6][1], |
382 |
qr/Metric_Type:Total_Item_Investigations\|Total_Item_Requests\|Unique_Item_Investigations\|Unique_Item_Requests/, |
383 |
'7th row is report filters' |
384 |
); |
385 |
like( $report_header[6][1], qr/Access_Method:Regular/, '7th row is report filters' ); |
386 |
like( $report_header[6][1], qr/End_Date:2022-03-31/, '7th row is report filters' ); |
387 |
like( $report_header[6][1], qr/Data_Type:Journal/, '7th row is report filters' ); |
388 |
like( $report_header[6][1], qr/Begin_Date:2022-01-01/, '7th row is report filters' ); |
389 |
|
390 |
is( $report_header[6][2], undef, '7th row is report filters' ); |
391 |
|
392 |
# Header row #8 - Report_Attributes |
393 |
is( $report_header[7][0], 'Report_Attributes', '8th row is report attributes' ); |
394 |
is( $report_header[7][1], '', '8th row is report attributes' ); |
395 |
is( $report_header[7][2], undef, '8th row is report attributes' ); |
396 |
|
397 |
# Header row #9 - Exceptions |
398 |
is( $report_header[8][0], 'Exceptions', '9th row is exceptions' ); |
399 |
is( $report_header[8][1], '', '9th row is exceptions' ); |
400 |
is( $report_header[8][2], undef, '9th row is exceptions' ); |
401 |
|
402 |
# Header row #10 - Reporting_Period |
403 |
is( $report_header[9][0], 'Reporting_Period', '10th row is reporting period' ); |
404 |
is( $report_header[9][1], 'Begin_Date=2022-01-01; End_Date=2022-03-31', '10th row is reporting period' ); |
405 |
is( $report_header[9][2], undef, '10th row is reporting period' ); |
406 |
|
407 |
# Header row #11 - Created |
408 |
is( $report_header[10][0], 'Created', '11th row is created' ); |
409 |
is( $report_header[10][1], '2023-02-15T09:11:12Z', '11th row is created' ); |
410 |
is( $report_header[10][2], undef, '11th row is created' ); |
411 |
|
412 |
# Header row #12 - Created |
413 |
is( $report_header[11][0], 'Created_By', '12th row is created by' ); |
414 |
is( $report_header[11][1], 'Sample Publisher', '12th row is created by' ); |
415 |
is( $report_header[11][2], undef, '12th row is created by' ); |
416 |
|
417 |
# Header row #13 - Registry_Record |
418 |
is( $report_header[12][0], 'Registry_Record', '13th row is Registry_Record' ); |
419 |
|
420 |
# Header row #14 - This needs to be empty |
421 |
is( $report_header[13][0], '', '14th row is empty' ); |
422 |
}; |
423 |
|
424 |
subtest 'TR_J3 _COUNTER_report_column_headings' => sub { |
425 |
|
426 |
plan tests => 16; |
427 |
|
428 |
my @report_column_headings = $sushi_counter_TR_J3->_COUNTER_report_column_headings; |
429 |
|
430 |
# Standard TR_J3 column headings |
431 |
is( $report_column_headings[0][0], 'Title', '1st column heading is title' ); |
432 |
is( $report_column_headings[0][1], 'Publisher', '2nd column heading is publisher' ); |
433 |
is( $report_column_headings[0][2], 'Publisher_ID', '3rd column heading is publisher ID' ); |
434 |
is( $report_column_headings[0][3], 'Platform', '4th column heading is platform' ); |
435 |
is( $report_column_headings[0][4], 'DOI', '5th column heading is DOI' ); |
436 |
is( $report_column_headings[0][5], 'Proprietary_ID', '6th column heading is proprietary ID' ); |
437 |
is( $report_column_headings[0][6], 'Print_ISSN', '7th column heading is print ISSN' ); |
438 |
is( $report_column_headings[0][7], 'Online_ISSN', '8th column heading is online ISSN' ); |
439 |
is( $report_column_headings[0][8], 'URI', '9th column heading is URI' ); |
440 |
is( $report_column_headings[0][9], 'Access_Type', '10th column heading is access type' ); |
441 |
is( $report_column_headings[0][10], 'Metric_Type', '11th column heading is access type' ); |
442 |
is( $report_column_headings[0][11], 'Reporting_Period_Total', '12th column heading is reporting period total' ); |
443 |
|
444 |
# Months column headings |
445 |
is( $report_column_headings[0][12], 'Jan 2022', '12th column is month column heading' ); |
446 |
is( $report_column_headings[0][13], 'Feb 2022', '13th column is another month column heading' ); |
447 |
is( $report_column_headings[0][14], 'Mar 2022', '13th column is the last month column heading' ); |
448 |
is( $report_column_headings[0][25], undef, '14th column is empty, no more months' ); |
449 |
}; |
450 |
|
451 |
subtest 'TR_J3 _COUNTER_report_body' => sub { |
452 |
|
453 |
plan tests => 25; |
454 |
|
455 |
my @report_body = $sushi_counter_TR_J3->_COUNTER_report_body; |
456 |
|
457 |
# The same title is sequential but for different metric types |
458 |
is( $report_body[0][0], 'Title 3', 'same title, different metric type' ); |
459 |
is( $report_body[1][0], 'Title 3', 'same title, different metric type' ); |
460 |
is( $report_body[2][0], 'Title 3', 'same title, different metric type' ); |
461 |
is( $report_body[3][0], 'Title 3', 'same title, different metric type' ); |
462 |
is( $report_body[0][9], 'Controlled', 'same title, same access_type' ); |
463 |
is( $report_body[1][9], 'Controlled', 'same title, same access_type' ); |
464 |
is( $report_body[2][9], 'Controlled', 'same title, same access_type' ); |
465 |
is( $report_body[3][9], 'Controlled', 'same title, same access_type' ); |
466 |
is( $report_body[0][10], 'Total_Item_Investigations', 'same title, different metric type' ); |
467 |
is( $report_body[1][10], 'Total_Item_Requests', 'same title, different metric type' ); |
468 |
is( $report_body[2][10], 'Unique_Item_Investigations', 'same title, different metric type' ); |
469 |
is( $report_body[3][10], 'Unique_Item_Requests', 'same title, different metric type' ); |
470 |
|
471 |
# The data is in the correct column |
472 |
is( $report_body[2][0], 'Title 3', '1st column is title' ); |
473 |
is( $report_body[2][1], 'Sample Publisher', '2nd column is publisher' ); |
474 |
is( $report_body[2][2], '4321432143214321', '3rd column is publisher ID' ); |
475 |
is( $report_body[2][3], 'Platform 1', '4th column is platform' ); |
476 |
is( $report_body[2][4], '10.9999/xxxxt03', '5th column is DOI' ); |
477 |
is( $report_body[2][5], 'P1:T03', '6th column is proprietary ID' ); |
478 |
is( $report_body[2][6], '', '7th column is print ISSN' ); |
479 |
is( $report_body[2][7], '1234-4321', '8th column is online ISSN' ); |
480 |
is( $report_body[2][8], '', '9th column is URI' ); |
481 |
is( $report_body[2][9], 'Controlled', '10th column is access type' ); |
482 |
is( $report_body[2][10], 'Unique_Item_Investigations', '11th column is metric type' ); |
483 |
is( $report_body[2][11], 1602, '12th column is reporting period total' ); # 608+618+376 |
484 |
|
485 |
# The period total is the sum of all the month columns |
486 |
my $stats_total = 0; |
487 |
for ( my $i = 12 ; $i < 15 ; $i++ ) { |
488 |
$stats_total += $report_body[0][$i]; |
489 |
} |
490 |
is( |
491 |
$report_body[0][11], $stats_total, |
492 |
'Reporting period total matches the sum of all the monthly usage statistics' |
493 |
); |
494 |
}; |
495 |
|
496 |
my $sushi_response_file_TR_J4 = dirname(__FILE__) . $test_data_base_dir . "/TR_J4.json"; |
497 |
my $sushi_counter_51_response_TR_J4 = decode_json( read_file($sushi_response_file_TR_J4) ); |
498 |
my $sushi_counter_TR_J4 = Koha::ERM::EUsage::SushiCounter->new( { response => $sushi_counter_51_response_TR_J4 } ); |
499 |
|
500 |
subtest 'TR_J4 _COUNTER_report_header' => sub { |
501 |
|
502 |
plan tests => 43; |
503 |
|
504 |
my @report_header = $sushi_counter_TR_J4->_COUNTER_report_header; |
505 |
|
506 |
# Header row #1 - Report_Name |
507 |
is( $report_header[0][0], 'Report_Name', '1st row is report name' ); |
508 |
is( $report_header[0][1], 'Journal Requests by YOP (Controlled)', '1st row is report name' ); |
509 |
is( $report_header[0][2], undef, '1st row is report name' ); |
510 |
|
511 |
# Header row #2 - Report_ID |
512 |
is( $report_header[1][0], 'Report_ID', '2nd row is report name' ); |
513 |
is( $report_header[1][1], 'TR_J4', '2nd row is report name' ); |
514 |
is( $report_header[1][2], undef, '2nd row is report name' ); |
515 |
|
516 |
# Header row #3 - Release |
517 |
is( $report_header[2][0], 'Release', '3rd row is counter release' ); |
518 |
is( $report_header[2][1], '5.1', '3rd row is counter release' ); |
519 |
is( $report_header[2][2], undef, '3rd row is counter release' ); |
520 |
|
521 |
# Header row #4 - Institution_Name |
522 |
is( $report_header[3][0], 'Institution_Name', '4th row is institution name' ); |
523 |
is( $report_header[3][1], 'Sample Institution', '4th row is institution name' ); |
524 |
is( $report_header[3][2], undef, '4th row is institution name' ); |
525 |
|
526 |
# Header row #5 - Institution_ID |
527 |
is( $report_header[4][0], 'Institution_ID', '5th row is institution id' ); |
528 |
is( $report_header[4][1], 'ISNI:1234123412341234', '5th row is institution id' ); |
529 |
is( $report_header[4][2], undef, '5th row is institution id' ); |
530 |
|
531 |
# Header row #6 - Metric_Types |
532 |
is( $report_header[5][0], 'Metric_Types', '6th row is metric types' ); |
533 |
is( |
534 |
$report_header[5][1], |
535 |
'Total_Item_Requests; Unique_Item_Requests', |
536 |
'6th row is metric types' |
537 |
); |
538 |
is( $report_header[5][2], undef, '6th row is metric types' ); |
539 |
|
540 |
# Header row #7 - Report_Filters |
541 |
is( $report_header[6][0], 'Report_Filters', '7th row is report filters' ); |
542 |
like( $report_header[6][1], qr/Metric_Type:Total_Item_Requests|Unique_Item_Requests/, '7th row is report filters' ); |
543 |
like( $report_header[6][1], qr/Access_Method:Regular/, '7th row is report filters' ); |
544 |
like( $report_header[6][1], qr/Begin_Date:2022-01-01/, '7th row is report filters' ); |
545 |
like( $report_header[6][1], qr/Access_Type:Controlled/, '7th row is report filters' ); |
546 |
like( $report_header[6][1], qr/End_Date:2022-03-31/, '7th row is report filters' ); |
547 |
like( $report_header[6][1], qr/Data_Type:Journal/, '7th row is report filters' ); |
548 |
|
549 |
is( $report_header[6][2], undef, '7th row is report filters' ); |
550 |
|
551 |
# Header row #8 - Report_Attributes |
552 |
is( $report_header[7][0], 'Report_Attributes', '8th row is report attributes' ); |
553 |
is( $report_header[7][1], '', '8th row is report attributes' ); |
554 |
is( $report_header[7][2], undef, '8th row is report attributes' ); |
555 |
|
556 |
# Header row #9 - Exceptions |
557 |
is( $report_header[8][0], 'Exceptions', '9th row is exceptions' ); |
558 |
is( $report_header[8][1], '', '9th row is exceptions' ); |
559 |
is( $report_header[8][2], undef, '9th row is exceptions' ); |
560 |
|
561 |
# Header row #10 - Reporting_Period |
562 |
is( $report_header[9][0], 'Reporting_Period', '10th row is reporting period' ); |
563 |
is( $report_header[9][1], 'Begin_Date=2022-01-01; End_Date=2022-03-31', '10th row is reporting period' ); |
564 |
is( $report_header[9][2], undef, '10th row is reporting period' ); |
565 |
|
566 |
# Header row #11 - Created |
567 |
is( $report_header[10][0], 'Created', '11th row is created' ); |
568 |
is( $report_header[10][1], '2023-02-15T09:11:12Z', '11th row is created' ); |
569 |
is( $report_header[10][2], undef, '11th row is created' ); |
570 |
|
571 |
# Header row #12 - Created |
572 |
is( $report_header[11][0], 'Created_By', '12th row is created by' ); |
573 |
is( $report_header[11][1], 'Sample Publisher', '12th row is created by' ); |
574 |
is( $report_header[11][2], undef, '12th row is created by' ); |
575 |
|
576 |
# Header row #13 - Registry_Record |
577 |
is( $report_header[12][0], 'Registry_Record', '13th row is Registry_Record' ); |
578 |
|
579 |
# Header row #14 - This needs to be empty |
580 |
is( $report_header[13][0], '', '14th row is empty' ); |
581 |
}; |
582 |
|
583 |
subtest 'TR_J4 _COUNTER_report_column_headings' => sub { |
584 |
|
585 |
plan tests => 16; |
586 |
|
587 |
my @report_column_headings = $sushi_counter_TR_J4->_COUNTER_report_column_headings; |
588 |
|
589 |
# Standard TR_J4 column headings |
590 |
is( $report_column_headings[0][0], 'Title', '1st column heading is title' ); |
591 |
is( $report_column_headings[0][1], 'Publisher', '2nd column heading is publisher' ); |
592 |
is( $report_column_headings[0][2], 'Publisher_ID', '3rd column heading is publisher ID' ); |
593 |
is( $report_column_headings[0][3], 'Platform', '4th column heading is platform' ); |
594 |
is( $report_column_headings[0][4], 'DOI', '5th column heading is DOI' ); |
595 |
is( $report_column_headings[0][5], 'Proprietary_ID', '6th column heading is proprietary ID' ); |
596 |
is( $report_column_headings[0][6], 'Print_ISSN', '7th column heading is print ISSN' ); |
597 |
is( $report_column_headings[0][7], 'Online_ISSN', '8th column heading is online ISSN' ); |
598 |
is( $report_column_headings[0][8], 'URI', '9th column heading is URI' ); |
599 |
is( $report_column_headings[0][9], 'YOP', '10th column heading is yop' ); |
600 |
is( $report_column_headings[0][10], 'Metric_Type', '11th column heading is metric type' ); |
601 |
is( $report_column_headings[0][11], 'Reporting_Period_Total', '12th column heading is reporting period total' ); |
602 |
|
603 |
# Months column headings |
604 |
is( $report_column_headings[0][12], 'Jan 2022', '13th column is month column heading' ); |
605 |
is( $report_column_headings[0][13], 'Feb 2022', '14th column is another month column heading' ); |
606 |
is( $report_column_headings[0][14], 'Mar 2022', '15th column is the last month column heading' ); |
607 |
is( $report_column_headings[0][15], undef, '16th column is empty, no more months' ); |
608 |
}; |
609 |
|
610 |
subtest 'TR_J4 _COUNTER_report_body' => sub { |
611 |
|
612 |
plan tests => 25; |
613 |
|
614 |
my @report_body = $sushi_counter_TR_J4->_COUNTER_report_body; |
615 |
|
616 |
# The same title is sequential but for different metric types |
617 |
is( $report_body[0][0], 'Title 3', 'same title, different metric type' ); |
618 |
is( $report_body[1][0], 'Title 3', 'same title, different metric type' ); |
619 |
is( $report_body[2][0], 'Title 3', 'same title, different metric type' ); |
620 |
is( $report_body[3][0], 'Title 3', 'same title, different metric type' ); |
621 |
is( $report_body[0][10], 'Total_Item_Requests', '1st title, same yop' ); |
622 |
is( $report_body[1][10], 'Unique_Item_Requests', '1st title, same yop' ); |
623 |
is( $report_body[2][10], 'Total_Item_Requests', '1st title, same yop' ); |
624 |
is( $report_body[3][10], 'Unique_Item_Requests', '1st title, same yop' ); |
625 |
is( $report_body[0][9], '2022', '1st title, yop' ); |
626 |
is( $report_body[1][9], '2022', '1st title, yop' ); |
627 |
is( $report_body[2][9], '2021', '1st title, yop' ); |
628 |
is( $report_body[3][9], '2021', '1st title, yop' ); |
629 |
|
630 |
# The data is in the correct column |
631 |
is( $report_body[2][0], 'Title 3', '1st column is title' ); |
632 |
is( $report_body[2][1], 'Sample Publisher', '2nd column is publisher' ); |
633 |
is( $report_body[2][2], '4321432143214321', '3rd column is publisher ID' ); |
634 |
is( $report_body[2][3], 'Platform 1', '4th column is platform' ); |
635 |
is( $report_body[2][4], '10.9999/xxxxt03', '5th column is DOI' ); |
636 |
is( $report_body[2][5], 'P1:T03', '6th column is proprietary ID' ); |
637 |
is( $report_body[2][6], '', '7th column is print ISSN' ); |
638 |
is( $report_body[2][7], '1234-4321', '8th column is online ISSN' ); |
639 |
is( $report_body[2][8], '', '9th column is URI' ); |
640 |
is( $report_body[2][9], '2021', '10th column is yop' ); |
641 |
is( $report_body[2][10], 'Total_Item_Requests', '10th column is metric type' ); |
642 |
is( $report_body[2][11], 640, '11th column is reporting period total' ); #150+247+243 |
643 |
|
644 |
# The period total is the sum of all the month columns |
645 |
my $stats_total = 0; |
646 |
for ( my $i = 12 ; $i < 15 ; $i++ ) { |
647 |
$stats_total += $report_body[0][$i]; |
648 |
} |
649 |
is( |
650 |
$report_body[0][11], $stats_total, |
651 |
'Reporting period total matches the sum of all the monthly usage statistics' |
652 |
); |
653 |
}; |
654 |
|
655 |
my $sushi_response_file_TR_B3 = dirname(__FILE__) . $test_data_base_dir . "/TR_B3.json"; |
656 |
my $sushi_counter_51_response_TR_B3 = decode_json( read_file($sushi_response_file_TR_B3) ); |
657 |
my $sushi_counter_TR_B3 = Koha::ERM::EUsage::SushiCounter->new( { response => $sushi_counter_51_response_TR_B3 } ); |
658 |
|
659 |
subtest 'TR_B3 _COUNTER_report_header' => sub { |
660 |
|
661 |
plan tests => 47; |
662 |
|
663 |
my @report_header = $sushi_counter_TR_B3->_COUNTER_report_header; |
664 |
|
665 |
# Header row #1 - Report_Name |
666 |
is( $report_header[0][0], 'Report_Name', '1st row is report name' ); |
667 |
is( $report_header[0][1], 'Book Usage by Access Type', '1st row is report name' ); |
668 |
is( $report_header[0][2], undef, '1st row is report name' ); |
669 |
|
670 |
# Header row #2 - Report_ID |
671 |
is( $report_header[1][0], 'Report_ID', '2nd row is report name' ); |
672 |
is( $report_header[1][1], 'TR_B3', '2nd row is report name' ); |
673 |
is( $report_header[1][2], undef, '2nd row is report name' ); |
674 |
|
675 |
# Header row #3 - Release |
676 |
is( $report_header[2][0], 'Release', '3rd row is counter release' ); |
677 |
is( $report_header[2][1], '5.1', '3rd row is counter release' ); |
678 |
is( $report_header[2][2], undef, '3rd row is counter release' ); |
679 |
|
680 |
# Header row #4 - Institution_Name |
681 |
is( $report_header[3][0], 'Institution_Name', '4th row is institution name' ); |
682 |
is( $report_header[3][1], 'Sample Institution', '4th row is institution name' ); |
683 |
is( $report_header[3][2], undef, '4th row is institution name' ); |
684 |
|
685 |
# Header row #5 - Institution_ID |
686 |
is( $report_header[4][0], 'Institution_ID', '5th row is institution id' ); |
687 |
is( $report_header[4][1], 'ISNI:1234123412341234', '5th row is institution id' ); |
688 |
is( $report_header[4][2], undef, '5th row is institution id' ); |
689 |
|
690 |
# Header row #6 - Metric_Types |
691 |
is( $report_header[5][0], 'Metric_Types', '6th row is metric types' ); |
692 |
like( $report_header[5][1], qr/Total_Item_Investigations/, '6th row is metric types' ); |
693 |
like( $report_header[5][1], qr/Total_Item_Requests/, '6th row is metric types' ); |
694 |
like( $report_header[5][1], qr/Unique_Item_Investigations/, '6th row is metric types' ); |
695 |
like( $report_header[5][1], qr/Unique_Item_Requests/, '6th row is metric types' ); |
696 |
like( $report_header[5][1], qr/Unique_Title_Investigations/, '6th row is metric types' ); |
697 |
like( $report_header[5][1], qr/Unique_Title_Requests/, '6th row is metric types' ); |
698 |
|
699 |
is( $report_header[5][2], undef, '6th row is metric types' ); |
700 |
|
701 |
# Header row #7 - Report_Filters |
702 |
is( $report_header[6][0], 'Report_Filters', '7th row is report filters' ); |
703 |
like( $report_header[6][1], qr/Data_Type:Book/, '7th row is report filters' ); |
704 |
like( $report_header[6][1], qr/Access_Method:Regular/, '7th row is report filters' ); |
705 |
like( |
706 |
$report_header[6][1], |
707 |
qr/Metric_Type:Total_Item_Investigations\|Total_Item_Requests\|Unique_Item_Investigations\|Unique_Item_Requests\|Unique_Title_Investigations\|Unique_Title_Requests/, |
708 |
'7th row is report filters' |
709 |
); |
710 |
like( $report_header[6][1], qr/Begin_Date:2022-01-01/, '7th row is report filters' ); |
711 |
like( $report_header[6][1], qr/End_Date:2022-03-31/, '7th row is report filters' ); |
712 |
|
713 |
is( $report_header[6][2], undef, '7th row is report filters' ); |
714 |
|
715 |
# Header row #8 - Report_Attributes |
716 |
is( $report_header[7][0], 'Report_Attributes', '8th row is report attributes' ); |
717 |
is( $report_header[7][1], '', '8th row is report attributes' ); |
718 |
is( $report_header[7][2], undef, '8th row is report attributes' ); |
719 |
|
720 |
# Header row #9 - Exceptions |
721 |
is( $report_header[8][0], 'Exceptions', '9th row is exceptions' ); |
722 |
is( $report_header[8][1], '', '9th row is exceptions' ); |
723 |
is( $report_header[8][2], undef, '9th row is exceptions' ); |
724 |
|
725 |
# Header row #10 - Reporting_Period |
726 |
is( $report_header[9][0], 'Reporting_Period', '10th row is reporting period' ); |
727 |
is( $report_header[9][1], 'Begin_Date=2022-01-01; End_Date=2022-03-31', '10th row is reporting period' ); |
728 |
is( $report_header[9][2], undef, '10th row is reporting period' ); |
729 |
|
730 |
# Header row #11 - Created |
731 |
is( $report_header[10][0], 'Created', '11th row is created' ); |
732 |
is( $report_header[10][1], '2023-02-15T09:11:12Z', '11th row is created' ); |
733 |
is( $report_header[10][2], undef, '11th row is created' ); |
734 |
|
735 |
# Header row #12 - Created |
736 |
is( $report_header[11][0], 'Created_By', '12th row is created by' ); |
737 |
is( $report_header[11][1], 'Sample Publisher', '12th row is created by' ); |
738 |
is( $report_header[11][2], undef, '12th row is created by' ); |
739 |
|
740 |
# Header row #13 - Registry_Record |
741 |
is( $report_header[12][0], 'Registry_Record', '13th row is Registry_Record' ); |
742 |
|
743 |
# Header row #14 - This needs to be empty |
744 |
is( $report_header[13][0], '', '14th row is empty' ); |
745 |
}; |
746 |
|
747 |
subtest 'TR_B3 _COUNTER_report_column_headings' => sub { |
748 |
|
749 |
plan tests => 19; |
750 |
|
751 |
my @report_column_headings = $sushi_counter_TR_B3->_COUNTER_report_column_headings; |
752 |
|
753 |
# Standard TR_J4 column headings |
754 |
is( $report_column_headings[0][0], 'Title', '1st column heading is title' ); |
755 |
is( $report_column_headings[0][1], 'Publisher', '2nd column heading is publisher' ); |
756 |
is( $report_column_headings[0][2], 'Publisher_ID', '3rd column heading is publisher ID' ); |
757 |
is( $report_column_headings[0][3], 'Platform', '4th column heading is platform' ); |
758 |
is( $report_column_headings[0][4], 'DOI', '5th column heading is DOI' ); |
759 |
is( $report_column_headings[0][5], 'Proprietary_ID', '6th column heading is proprietary ID' ); |
760 |
is( $report_column_headings[0][6], 'ISBN', '7th column heading is ISBN' ); |
761 |
is( $report_column_headings[0][7], 'Print_ISSN', '8th column heading is print ISSN' ); |
762 |
is( $report_column_headings[0][8], 'Online_ISSN', '9th column heading is online ISSN' ); |
763 |
is( $report_column_headings[0][9], 'URI', '10th column heading is URI' ); |
764 |
is( $report_column_headings[0][10], 'Data_Type', '11th column heading is data type' ); |
765 |
is( $report_column_headings[0][11], 'YOP', '12th column heading is yop' ); |
766 |
is( $report_column_headings[0][12], 'Access_Type', '13th column heading is access type' ); |
767 |
is( $report_column_headings[0][13], 'Metric_Type', '14th column heading is metric type' ); |
768 |
is( $report_column_headings[0][14], 'Reporting_Period_Total', '15th column heading is reporting period total' ); |
769 |
|
770 |
# Months column headings |
771 |
is( $report_column_headings[0][15], 'Jan 2022', '16th column is month column heading' ); |
772 |
is( $report_column_headings[0][16], 'Feb 2022', '17th column another month column heading' ); |
773 |
is( $report_column_headings[0][17], 'Mar 2022', '18th column is the last month column heading' ); |
774 |
is( $report_column_headings[0][18], undef, '19th column is empty, no more months' ); |
775 |
}; |
776 |
|
777 |
subtest 'TR_B3 _COUNTER_report_body' => sub { |
778 |
|
779 |
plan tests => 49; |
780 |
|
781 |
my @report_body = $sushi_counter_TR_B3->_COUNTER_report_body; |
782 |
|
783 |
# The same title is sequential but for different metric types |
784 |
is( |
785 |
$report_body[0][0], 'Title 1', |
786 |
'first title, different metric type' |
787 |
); |
788 |
is( |
789 |
$report_body[1][0], 'Title 1', |
790 |
'first title, different metric type' |
791 |
); |
792 |
is( |
793 |
$report_body[2][0], 'Title 1', |
794 |
'first title, different metric type' |
795 |
); |
796 |
is( |
797 |
$report_body[3][0], 'Title 1', |
798 |
'first title, different metric type' |
799 |
); |
800 |
is( |
801 |
$report_body[4][0], 'Title 1', |
802 |
'first title, different metric type' |
803 |
); |
804 |
is( |
805 |
$report_body[5][0], 'Title 1', |
806 |
'first title, different metric type' |
807 |
); |
808 |
is( |
809 |
$report_body[6][0], 'Title 7', |
810 |
'second title, different metric type' |
811 |
); |
812 |
is( |
813 |
$report_body[7][0], 'Title 7', |
814 |
'second title, different metric type' |
815 |
); |
816 |
is( |
817 |
$report_body[8][0], 'Title 7', |
818 |
'second title, different metric type' |
819 |
); |
820 |
is( $report_body[0][10], 'Book', '6 rows for 1st title' ); |
821 |
is( $report_body[1][10], 'Book', '6 rows for 1st title' ); |
822 |
is( $report_body[2][10], 'Book', '6 rows for 1st title' ); |
823 |
is( $report_body[3][10], 'Book', '6 rows for 1st title' ); |
824 |
is( $report_body[4][10], 'Book', '6 rows for 1st title' ); |
825 |
is( $report_body[5][10], 'Book', '6 rows for 1st title' ); |
826 |
is( $report_body[0][11], '2022', '1st title, yop' ); |
827 |
is( $report_body[1][11], '2022', '1st title, yop' ); |
828 |
is( $report_body[2][11], '2022', '1st title,yop' ); |
829 |
is( $report_body[3][11], '2022', '1st title, 2nd yop has 6 metric types' ); |
830 |
is( $report_body[4][11], '2022', '1st title, 2nd yop has 6 metric types' ); |
831 |
is( $report_body[5][11], '2022', '1st title, 2nd yop has 6 metric types' ); |
832 |
is( $report_body[0][12], 'Controlled', '6 rows for 1st title' ); |
833 |
is( $report_body[1][12], 'Controlled', '6 rows for 1st title' ); |
834 |
is( $report_body[2][12], 'Controlled', '6 rows for 1st title' ); |
835 |
is( $report_body[3][12], 'Controlled', '6 rows for 1st title' ); |
836 |
is( $report_body[4][12], 'Controlled', '6 rows for 1st title' ); |
837 |
is( $report_body[5][12], 'Controlled', '6 rows for 1st title' ); |
838 |
is( $report_body[0][13], 'Total_Item_Investigations', '1st title, metric type' ); |
839 |
is( $report_body[1][13], 'Total_Item_Requests', '1st title, metric type' ); |
840 |
is( $report_body[2][13], 'Unique_Item_Investigations', '1st title, metric type' ); |
841 |
is( $report_body[3][13], 'Unique_Item_Requests', '1st title, metric type' ); |
842 |
is( $report_body[4][13], 'Unique_Title_Investigations', '1st title, metric type' ); |
843 |
is( $report_body[5][13], 'Unique_Title_Requests', '1st title, metric type' ); |
844 |
|
845 |
# The data is in the correct column |
846 |
is( $report_body[2][0], 'Title 1', '1st column is title' ); |
847 |
is( $report_body[2][1], 'Sample Publisher', '2nd column is publisher' ); |
848 |
is( $report_body[2][2], '4321432143214321', '3rd column is publisher ID' ); |
849 |
is( $report_body[2][3], 'Platform 1', '4th column is platform' ); |
850 |
is( $report_body[2][4], '10.9999/xxxxt01', '5th column is DOI' ); |
851 |
is( $report_body[2][5], 'P1:T01', '6th column is proprietary ID' ); |
852 |
is( $report_body[2][6], '979-8-88888-888-8', '7th column is ISBN' ); |
853 |
is( $report_body[2][7], '', '8th column is print ISSN' ); |
854 |
is( $report_body[2][8], '', '9th column is online ISSN' ); |
855 |
is( $report_body[2][9], '', '10th column is URI' ); |
856 |
is( $report_body[2][10], 'Book', '11th column is data_type' ); |
857 |
is( $report_body[2][11], '2022', '12th column is yop' ); |
858 |
is( $report_body[2][12], 'Controlled', '12th column is access type' ); |
859 |
is( $report_body[2][13], 'Unique_Item_Investigations', '13th column is metric type' ); |
860 |
is( $report_body[2][14], 2760, '14th column is reporting period total' ); #828+935+997 |
861 |
|
862 |
# The period total is the sum of all the month columns |
863 |
my $stats_total = 0; |
864 |
for ( my $i = 15 ; $i < 18 ; $i++ ) { |
865 |
$stats_total += $report_body[0][$i]; |
866 |
} |
867 |
is( |
868 |
$report_body[0][14], $stats_total, |
869 |
'Reporting period total matches the sum of all the monthly usage statistics' |
870 |
); |
871 |
}; |
872 |
|
873 |
my $sushi_response_file_TR_B2 = dirname(__FILE__) . $test_data_base_dir . "/TR_B2.json"; |
874 |
my $sushi_counter_51_response_TR_B2 = decode_json( read_file($sushi_response_file_TR_B2) ); |
875 |
my $sushi_counter_TR_B2 = Koha::ERM::EUsage::SushiCounter->new( { response => $sushi_counter_51_response_TR_B2 } ); |
876 |
|
877 |
subtest 'TR_B2 _COUNTER_report_header' => sub { |
878 |
|
879 |
plan tests => 42; |
880 |
|
881 |
my @report_header = $sushi_counter_TR_B2->_COUNTER_report_header; |
882 |
|
883 |
# Header row #1 - Report_Name |
884 |
is( $report_header[0][0], 'Report_Name', '1st row is report name' ); |
885 |
is( $report_header[0][1], 'Book Access Denied', '1st row is report name' ); |
886 |
is( $report_header[0][2], undef, '1st row is report name' ); |
887 |
|
888 |
# Header row #2 - Report_ID |
889 |
is( $report_header[1][0], 'Report_ID', '2nd row is report name' ); |
890 |
is( $report_header[1][1], 'TR_B2', '2nd row is report name' ); |
891 |
is( $report_header[1][2], undef, '2nd row is report name' ); |
892 |
|
893 |
# Header row #3 - Release |
894 |
is( $report_header[2][0], 'Release', '3rd row is counter release' ); |
895 |
is( $report_header[2][1], '5.1', '3rd row is counter release' ); |
896 |
is( $report_header[2][2], undef, '3rd row is counter release' ); |
897 |
|
898 |
# Header row #4 - Institution_Name |
899 |
is( $report_header[3][0], 'Institution_Name', '4th row is institution name' ); |
900 |
is( $report_header[3][1], 'Sample Institution', '4th row is institution name' ); |
901 |
is( $report_header[3][2], undef, '4th row is institution name' ); |
902 |
|
903 |
# Header row #5 - Institution_ID |
904 |
is( $report_header[4][0], 'Institution_ID', '5th row is institution id' ); |
905 |
is( $report_header[4][1], 'ISNI:1234123412341234', '5th row is institution id' ); |
906 |
is( $report_header[4][2], undef, '5th row is institution id' ); |
907 |
|
908 |
# Header row #6 - Metric_Types |
909 |
is( $report_header[5][0], 'Metric_Types', '6th row is metric types' ); |
910 |
is( |
911 |
$report_header[5][1], |
912 |
'Limit_Exceeded; No_License', |
913 |
'6th row is metric types' |
914 |
); |
915 |
is( $report_header[5][2], undef, '6th row is metric types' ); |
916 |
|
917 |
# Header row #7 - Report_Filters |
918 |
is( $report_header[6][0], 'Report_Filters', '7th row is report filters' ); |
919 |
like( $report_header[6][1], qr/Data_Type:Book/, '7th row is report filters' ); |
920 |
like( $report_header[6][1], qr/Access_Method:Regular/, '7th row is report filters' ); |
921 |
like( $report_header[6][1], qr/Metric_Type:Limit_Exceeded\|No_License/, '7th row is report filters' ); |
922 |
like( $report_header[6][1], qr/Begin_Date:2022-01-01/, '7th row is report filters' ); |
923 |
like( $report_header[6][1], qr/End_Date:2022-03-31/, '7th row is report filters' ); |
924 |
|
925 |
is( $report_header[6][2], undef, '7th row is report filters' ); |
926 |
|
927 |
# Header row #8 - Report_Attributes |
928 |
is( $report_header[7][0], 'Report_Attributes', '8th row is report attributes' ); |
929 |
is( $report_header[7][1], '', '8th row is report attributes' ); |
930 |
is( $report_header[7][2], undef, '8th row is report attributes' ); |
931 |
|
932 |
# Header row #9 - Exceptions |
933 |
is( $report_header[8][0], 'Exceptions', '9th row is exceptions' ); |
934 |
is( $report_header[8][1], '', '9th row is exceptions' ); |
935 |
is( $report_header[8][2], undef, '9th row is exceptions' ); |
936 |
|
937 |
# Header row #10 - Reporting_Period |
938 |
is( $report_header[9][0], 'Reporting_Period', '10th row is reporting period' ); |
939 |
is( $report_header[9][1], 'Begin_Date=2022-01-01; End_Date=2022-03-31', '10th row is reporting period' ); |
940 |
is( $report_header[9][2], undef, '10th row is reporting period' ); |
941 |
|
942 |
# Header row #11 - Created |
943 |
is( $report_header[10][0], 'Created', '11th row is created' ); |
944 |
is( $report_header[10][1], '2023-02-15T09:11:12Z', '11th row is created' ); |
945 |
is( $report_header[10][2], undef, '11th row is created' ); |
946 |
|
947 |
# Header row #12 - Created |
948 |
is( $report_header[11][0], 'Created_By', '12th row is created by' ); |
949 |
is( $report_header[11][1], 'Sample Publisher', '12th row is created by' ); |
950 |
is( $report_header[11][2], undef, '12th row is created by' ); |
951 |
|
952 |
# Header row #13 - Registry_Record |
953 |
is( $report_header[12][0], 'Registry_Record', '13th row is Registry_Record' ); |
954 |
|
955 |
# Header row #14 - This needs to be empty |
956 |
is( $report_header[13][0], '', '14th row is empty' ); |
957 |
}; |
958 |
|
959 |
subtest 'TR_B2 _COUNTER_report_column_headings' => sub { |
960 |
|
961 |
plan tests => 18; |
962 |
|
963 |
my @report_column_headings = $sushi_counter_TR_B2->_COUNTER_report_column_headings; |
964 |
|
965 |
# Standard TR_J4 column headings |
966 |
is( $report_column_headings[0][0], 'Title', '1st column heading is title' ); |
967 |
is( $report_column_headings[0][1], 'Publisher', '2nd column heading is publisher' ); |
968 |
is( $report_column_headings[0][2], 'Publisher_ID', '3rd column heading is publisher ID' ); |
969 |
is( $report_column_headings[0][3], 'Platform', '4th column heading is platform' ); |
970 |
is( $report_column_headings[0][4], 'DOI', '5th column heading is DOI' ); |
971 |
is( $report_column_headings[0][5], 'Proprietary_ID', '6th column heading is proprietary ID' ); |
972 |
is( $report_column_headings[0][6], 'ISBN', '7th column heading is ISBN' ); |
973 |
is( $report_column_headings[0][7], 'Print_ISSN', '8th column heading is print ISSN' ); |
974 |
is( $report_column_headings[0][8], 'Online_ISSN', '9th column heading is online ISSN' ); |
975 |
is( $report_column_headings[0][9], 'URI', '10th column heading is URI' ); |
976 |
is( $report_column_headings[0][10], 'Data_Type', '11th column heading is data type' ); |
977 |
is( $report_column_headings[0][11], 'YOP', '12th column heading is yop' ); |
978 |
is( $report_column_headings[0][12], 'Metric_Type', '13th column heading is metric type' ); |
979 |
is( $report_column_headings[0][13], 'Reporting_Period_Total', '14th column heading is reporting period total' ); |
980 |
|
981 |
# Months column headings |
982 |
is( $report_column_headings[0][14], 'Jan 2022', '14th column is month column heading' ); |
983 |
is( $report_column_headings[0][15], 'Feb 2022', '15th column is another column heading' ); |
984 |
is( $report_column_headings[0][16], 'Mar 2022', '16th column is the last month column heading' ); |
985 |
is( $report_column_headings[0][17], undef, '17th column is empty, no more months' ); |
986 |
}; |
987 |
|
988 |
subtest 'TR_B2 _COUNTER_report_body' => sub { |
989 |
|
990 |
plan tests => 19; |
991 |
|
992 |
my @report_body = $sushi_counter_TR_B2->_COUNTER_report_body; |
993 |
|
994 |
# The same title is sequential but for different metric types |
995 |
is( |
996 |
$report_body[0][0], 'Title 1', |
997 |
'same title, different metric type' |
998 |
); |
999 |
is( |
1000 |
$report_body[1][0], 'Title 1', |
1001 |
'same title, different metric type' |
1002 |
); |
1003 |
is( $report_body[0][12], 'Limit_Exceeded', '2 rows for 1st title, metric type' ); |
1004 |
is( $report_body[1][12], 'No_License', '2 rows for 1st title, metric type' ); |
1005 |
|
1006 |
# The data is in the correct column |
1007 |
is( $report_body[2][0], 'Title 7', '1st column is title' ); |
1008 |
is( $report_body[2][1], 'Sample Publisher', '2nd column is publisher' ); |
1009 |
is( $report_body[2][2], '4321432143214321', '3rd column heading is publisher ID' ); |
1010 |
is( $report_body[2][3], 'Platform 1', '4th column is platform' ); |
1011 |
is( $report_body[2][4], '10.9999/xxxxt07', '5th column is DOI' ); |
1012 |
is( $report_body[2][5], 'P1:T07', '6th column is proprietary ID' ); |
1013 |
is( $report_body[2][6], '979-8-88888-888-9', '7th column is ISBN' ); |
1014 |
is( $report_body[2][7], '', '8th column is print ISSN' ); |
1015 |
is( $report_body[2][8], '', '9th column is online ISSN' ); |
1016 |
is( $report_body[2][9], '', '10th column is URI' ); |
1017 |
is( $report_body[2][10], 'Reference_Work', '11th column is data type' ); |
1018 |
is( $report_body[2][11], '2019', '11th column is yop' ); |
1019 |
is( $report_body[2][12], 'Limit_Exceeded', '12th column is access type' ); |
1020 |
is( $report_body[2][13], 217, '13th column is reporting period total' ); #84+84+49 |
1021 |
|
1022 |
# The period total is the sum of all the month columns |
1023 |
my $stats_total = 0; |
1024 |
for ( my $i = 14 ; $i < 17 ; $i++ ) { |
1025 |
$stats_total += $report_body[0][$i]; |
1026 |
} |
1027 |
is( |
1028 |
$report_body[0][13], $stats_total, |
1029 |
'Reporting period total matches the sum of all the monthly usage statistics' |
1030 |
); |
1031 |
}; |