View | Details | Raw Unified | Return to bug 36831
Collapse All | Expand All

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

Return to bug 36831