Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 7; |
20 |
use Test::More tests => 8; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
|
23 |
|
Lines 39-45
subtest 'enqueue' => sub {
Link Here
|
39 |
|
39 |
|
40 |
$schema->storage->txn_begin; |
40 |
$schema->storage->txn_begin; |
41 |
|
41 |
|
42 |
# FIXME: Should be an exception |
|
|
43 |
my $job_id = Koha::BackgroundJob::ImportKBARTFile->new->enqueue(); |
42 |
my $job_id = Koha::BackgroundJob::ImportKBARTFile->new->enqueue(); |
44 |
is( $job_id, undef, 'Nothing enqueued if missing file param' ); |
43 |
is( $job_id, undef, 'Nothing enqueued if missing file param' ); |
45 |
|
44 |
|
Lines 50-64
subtest 'calculate_chunked_params_size' => sub {
Link Here
|
50 |
|
49 |
|
51 |
plan tests => 2; |
50 |
plan tests => 2; |
52 |
|
51 |
|
53 |
my $max_number_of_lines = |
52 |
my $max_number_of_lines = Koha::ERM::EHoldings::Title::calculate_chunked_params_size( 500000, 100000, 50000 ); |
54 |
Koha::BackgroundJob::ImportKBARTFile::calculate_chunked_params_size( 500000, 100000, 50000 ); |
|
|
55 |
is( $max_number_of_lines, 7500, 'Number of lines calculated correctly' ); |
53 |
is( $max_number_of_lines, 7500, 'Number of lines calculated correctly' ); |
56 |
my $max_number_of_lines2 = |
54 |
my $max_number_of_lines2 = Koha::ERM::EHoldings::Title::calculate_chunked_params_size( 400000, 100000, 60000 ); |
57 |
Koha::BackgroundJob::ImportKBARTFile::calculate_chunked_params_size( 400000, 100000, 60000 ); |
|
|
58 |
is( $max_number_of_lines2, 11250, 'Number of lines calculated correctly' ); |
55 |
is( $max_number_of_lines2, 11250, 'Number of lines calculated correctly' ); |
59 |
}; |
56 |
}; |
60 |
|
57 |
|
61 |
subtest 'format_title' => sub { |
58 |
subtest '_format_title' => sub { |
62 |
|
59 |
|
63 |
plan tests => 4; |
60 |
plan tests => 4; |
64 |
|
61 |
|
Lines 67-73
subtest 'format_title' => sub {
Link Here
|
67 |
coverage_notes => 'Test notes' |
64 |
coverage_notes => 'Test notes' |
68 |
}; |
65 |
}; |
69 |
|
66 |
|
70 |
my $formatted_title = Koha::BackgroundJob::ImportKBARTFile::format_title($title); |
67 |
my $formatted_title = Koha::BackgroundJob::ImportKBARTFile::_format_title($title); |
71 |
|
68 |
|
72 |
is( $formatted_title->{external_id}, 1, 'external_id formatted correctly' ); |
69 |
is( $formatted_title->{external_id}, 1, 'external_id formatted correctly' ); |
73 |
is( $formatted_title->{notes}, 'Test notes', 'notes formatted correctly' ); |
70 |
is( $formatted_title->{notes}, 'Test notes', 'notes formatted correctly' ); |
Lines 77-83
subtest 'format_title' => sub {
Link Here
|
77 |
|
74 |
|
78 |
subtest 'read_file' => sub { |
75 |
subtest 'read_file' => sub { |
79 |
|
76 |
|
80 |
plan tests => 7; |
77 |
plan tests => 6; |
81 |
|
78 |
|
82 |
my $file = { |
79 |
my $file = { |
83 |
filename => 'Test_file.csv', |
80 |
filename => 'Test_file.csv', |
Lines 88-94
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb
Link Here
|
88 |
) |
85 |
) |
89 |
}; |
86 |
}; |
90 |
|
87 |
|
91 |
my ( $column_headers, $lines, $error ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file); |
88 |
my ( $column_headers, $lines, $error ) = Koha::ERM::EHoldings::Title::read_file($file); |
92 |
|
89 |
|
93 |
is( @{$column_headers}, 25, '25 column headers found' ); |
90 |
is( @{$column_headers}, 25, '25 column headers found' ); |
94 |
is( @{$column_headers}[0], 'publication_title', 'First header correctly extracted' ); |
91 |
is( @{$column_headers}[0], 'publication_title', 'First header correctly extracted' ); |
Lines 112-118
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb
Link Here
|
112 |
], |
109 |
], |
113 |
'Line correctly identified' |
110 |
'Line correctly identified' |
114 |
); |
111 |
); |
|
|
112 |
}; |
113 |
|
114 |
subtest '_detect_delimiter_and_quote' => sub { |
115 |
|
116 |
plan tests => 3; |
117 |
|
118 |
my $file = { |
119 |
filename => 'Test_file.txt', |
120 |
file_content => encode_base64( |
121 |
'publication_title,print_identifier,online_identifier,date_first_issue_online,num_first_vol_online,num_first_issue_online,date_last_issue_online,num_last_vol_online,num_last_issue_online,title_url,first_author,title_id,embargo_info,coverage_depth,coverage_notes,publisher_name,publication_type,date_monograph_published_print,date_monograph_published_online,monograph_volume,monograph_edition,first_editor,parent_publication_title_id,preceding_publication_title_id,access_type |
122 |
Nature Plants,,2055-0278,2015-01,1,1,,,,https://www.nature.com/nplants,,4aaa7,,fulltext,Hybrid (Open Choice),Nature Publishing Group UK,serial,,,,,,,,P |
123 |
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bbb0,,fulltext,Hybrid (Open Choice),Nature Publishing Group UK,serial,,,,,,,,P' |
124 |
) |
125 |
}; |
115 |
|
126 |
|
|
|
127 |
my ( $delimiter, $quote_char ) = Koha::ERM::EHoldings::Title::_detect_delimiter_and_quote($file); |
128 |
is( $delimiter, ',', 'Comma delimiter identified' ); |
129 |
is( $quote_char, '"', 'Quote character identified' ); |
116 |
my $file2 = { |
130 |
my $file2 = { |
117 |
filename => 'Test_file2.csv', |
131 |
filename => 'Test_file2.csv', |
118 |
file_content => encode_base64( |
132 |
file_content => encode_base64( |
Lines 122-133
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb
Link Here
|
122 |
) |
136 |
) |
123 |
}; |
137 |
}; |
124 |
warning_is { |
138 |
warning_is { |
125 |
Koha::BackgroundJob::ImportKBARTFile::read_file($file2); |
139 |
Koha::ERM::EHoldings::Title::read_file($file2); |
126 |
} |
140 |
} |
127 |
'2023, EIQ - QUO character not allowed, 157', 'Error message correctly reported'; |
141 |
'2023, EIQ - QUO character not allowed, 157', 'Error message correctly reported'; |
128 |
}; |
142 |
}; |
129 |
|
143 |
|
130 |
subtest 'create_title_hash_from_line_data' => sub { |
144 |
subtest '_create_title_hash_from_line_data' => sub { |
131 |
|
145 |
|
132 |
plan tests => 2; |
146 |
plan tests => 2; |
133 |
|
147 |
|
Lines 140-153
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb
Link Here
|
140 |
) |
154 |
) |
141 |
}; |
155 |
}; |
142 |
|
156 |
|
143 |
my ( $column_headers, $lines ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file); |
157 |
my ( $column_headers, $lines ) = Koha::ERM::EHoldings::Title::read_file($file); |
144 |
my @invalid_columns; |
158 |
my @invalid_columns; |
145 |
|
159 |
|
146 |
my $title_from_line1 = Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data( |
160 |
my $title_from_line1 = Koha::BackgroundJob::ImportKBARTFile::_create_title_hash_from_line_data( |
147 |
@{$lines}[0], $column_headers, |
161 |
@{$lines}[0], $column_headers, |
148 |
\@invalid_columns |
162 |
\@invalid_columns |
149 |
); |
163 |
); |
150 |
my $title_from_line2 = Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data( |
164 |
my $title_from_line2 = Koha::BackgroundJob::ImportKBARTFile::_create_title_hash_from_line_data( |
151 |
@{$lines}[1], $column_headers, |
165 |
@{$lines}[1], $column_headers, |
152 |
\@invalid_columns |
166 |
\@invalid_columns |
153 |
); |
167 |
); |
Lines 211-217
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb
Link Here
|
211 |
is_deeply( $title_from_line2, $line2_match, 'Title hash created correctly' ); |
225 |
is_deeply( $title_from_line2, $line2_match, 'Title hash created correctly' ); |
212 |
}; |
226 |
}; |
213 |
|
227 |
|
214 |
subtest 'create_title_hash_from_line_data with invalid columns using csv' => sub { |
228 |
subtest '_create_title_hash_from_line_data with invalid columns using csv' => sub { |
215 |
|
229 |
|
216 |
plan tests => 2; |
230 |
plan tests => 2; |
217 |
|
231 |
|
Lines 224-237
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb
Link Here
|
224 |
) |
238 |
) |
225 |
}; |
239 |
}; |
226 |
|
240 |
|
227 |
my ( $column_headers, $lines ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file); |
241 |
my ( $column_headers, $lines ) = Koha::ERM::EHoldings::Title::read_file($file); |
228 |
my @invalid_columns = ('invalid_column'); |
242 |
my @invalid_columns = ('invalid_column'); |
229 |
|
243 |
|
230 |
my $title_from_line1 = Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data( |
244 |
my $title_from_line1 = Koha::BackgroundJob::ImportKBARTFile::_create_title_hash_from_line_data( |
231 |
@{$lines}[0], $column_headers, |
245 |
@{$lines}[0], $column_headers, |
232 |
\@invalid_columns |
246 |
\@invalid_columns |
233 |
); |
247 |
); |
234 |
my $title_from_line2 = Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data( |
248 |
my $title_from_line2 = Koha::BackgroundJob::ImportKBARTFile::_create_title_hash_from_line_data( |
235 |
@{$lines}[1], $column_headers, |
249 |
@{$lines}[1], $column_headers, |
236 |
\@invalid_columns |
250 |
\@invalid_columns |
237 |
); |
251 |
); |
Lines 317-323
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb
Link Here
|
317 |
) |
331 |
) |
318 |
}; |
332 |
}; |
319 |
|
333 |
|
320 |
my ( $column_headers, $rows, $error ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file); |
334 |
my ( $column_headers, $rows, $error ) = Koha::ERM::EHoldings::Title::read_file($file); |
321 |
my $data = { |
335 |
my $data = { |
322 |
column_headers => $column_headers, |
336 |
column_headers => $column_headers, |
323 |
rows => $rows, |
337 |
rows => $rows, |
Lines 373-379
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb
Link Here
|
373 |
|
387 |
|
374 |
my $module = Test::MockModule->new('Koha::BackgroundJob::ImportKBARTFile'); |
388 |
my $module = Test::MockModule->new('Koha::BackgroundJob::ImportKBARTFile'); |
375 |
$module->mock( |
389 |
$module->mock( |
376 |
'create_title_hash_from_line_data', |
390 |
'_create_title_hash_from_line_data', |
377 |
sub { |
391 |
sub { |
378 |
my ( $row, $column_headers ) = @_; |
392 |
my ( $row, $column_headers ) = @_; |
379 |
|
393 |
|
Lines 413-422
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb
Link Here
|
413 |
$job3->messages, |
427 |
$job3->messages, |
414 |
[ |
428 |
[ |
415 |
{ |
429 |
{ |
416 |
'type' => 'error', |
430 |
'type' => 'error', |
417 |
'code' => 'no_title_found', |
431 |
'code' => 'no_title_found', |
418 |
'title_id' => '12345', |
432 |
'title_id' => '12345', |
419 |
'title' => '(Unknown)' |
433 |
'title' => '(Unknown)' |
420 |
}, |
434 |
}, |
421 |
{ |
435 |
{ |
422 |
'code' => 'title_already_exists', |
436 |
'code' => 'title_already_exists', |
Lines 429-435
Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb
Link Here
|
429 |
); |
443 |
); |
430 |
|
444 |
|
431 |
$module->mock( |
445 |
$module->mock( |
432 |
'create_title_hash_from_line_data', |
446 |
'_create_title_hash_from_line_data', |
433 |
sub { |
447 |
sub { |
434 |
my ( $row, $column_headers ) = @_; |
448 |
my ( $row, $column_headers ) = @_; |
435 |
|
449 |
|
436 |
- |
|
|