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

(-)a/Koha/MetadataExtractor.pm (-5 / +5 lines)
Lines 1-4 Link Here
1
package Koha::MetadataExtractor;
1
package Koha::Biblio::Metadata::Extractor;
2
2
3
# Copyright ByWater Solutions 2023
3
# Copyright ByWater Solutions 2023
4
#
4
#
Lines 19-25 package Koha::MetadataExtractor; Link Here
19
19
20
=head1 NAME
20
=head1 NAME
21
21
22
Koha::MetadataExtractor - Extract specific metadata from MARC::Record objects
22
Koha::Biblio::Metadata::Extractor - Extract specific metadata from MARC::Record objects
23
23
24
=cut
24
=cut
25
25
Lines 33-41 use Koha::Exceptions; Link Here
33
33
34
=head3 new
34
=head3 new
35
35
36
    my $extractor = Koha::MetadataExtractor->new;
36
    my $extractor = Koha::Biblio::Metadata::Extractor->new;
37
37
38
Constructor for the I<Koha::MetadataExtractor> class.
38
Constructor for the I<Koha::Biblio::Metadata::Extractor> class.
39
39
40
=cut
40
=cut
41
41
Lines 89-95 sub get_extractor { Link Here
89
        unless $valid_schemas->{$schema};
89
        unless $valid_schemas->{$schema};
90
90
91
    unless ( $self->{extractors}->{$schema} ) {
91
    unless ( $self->{extractors}->{$schema} ) {
92
        my $extractor_class = "Koha::MetadataExtractor::MARC::$schema";
92
        my $extractor_class = "Koha::Biblio::Metadata::Extractor::MARC::$schema";
93
        eval "require $extractor_class";
93
        eval "require $extractor_class";
94
        $self->{extractors}->{$schema} = $extractor_class->new;
94
        $self->{extractors}->{$schema} = $extractor_class->new;
95
    }
95
    }
(-)a/Koha/MetadataExtractor/MARC/MARC21.pm (-4 / +4 lines)
Lines 1-4 Link Here
1
package Koha::MetadataExtractor::MARC::MARC21;
1
package Koha::Biblio::Metadata::Extractor::MARC::MARC21;
2
2
3
# Copyright ByWater Solutions 2023
3
# Copyright ByWater Solutions 2023
4
#
4
#
Lines 19-25 package Koha::MetadataExtractor::MARC::MARC21; Link Here
19
19
20
=head1 NAME
20
=head1 NAME
21
21
22
Koha::MetadataExtractor - Extract specific metadata from MARC::Record objects
22
Koha::Biblio::Metadata::Extractor - Extract specific metadata from MARC::Record objects
23
23
24
=cut
24
=cut
25
25
Lines 33-41 use Koha::Exceptions; Link Here
33
33
34
=head3 new
34
=head3 new
35
35
36
    my $extractor = Koha::MetadataExtractor::MARC::MARC21->new;
36
    my $extractor = Koha::Biblio::Metadata::Extractor::MARC::MARC21->new;
37
37
38
Constructor for the I<Koha::MetadataExtractor> class.
38
Constructor for the I<Koha::Biblio::Metadata::Extractor> class.
39
39
40
=cut
40
=cut
41
41
(-)a/Koha/MetadataExtractor/MARC/UNIMARC.pm (-4 / +4 lines)
Lines 1-4 Link Here
1
package Koha::MetadataExtractor::MARC::UNIMARC;
1
package Koha::Biblio::Metadata::Extractor::MARC::UNIMARC;
2
2
3
# Copyright ByWater Solutions 2023
3
# Copyright ByWater Solutions 2023
4
#
4
#
Lines 19-25 package Koha::MetadataExtractor::MARC::UNIMARC; Link Here
19
19
20
=head1 NAME
20
=head1 NAME
21
21
22
Koha::MetadataExtractor - Extract specific metadata from MARC::Record objects
22
Koha::Biblio::Metadata::Extractor - Extract specific metadata from MARC::Record objects
23
23
24
=cut
24
=cut
25
25
Lines 33-41 use Koha::Exceptions; Link Here
33
33
34
=head3 new
34
=head3 new
35
35
36
    my $extractor = Koha::MetadataExtractor::MARC::UNIMARC->new;
36
    my $extractor = Koha::Biblio::Metadata::Extractor::MARC::UNIMARC->new;
37
37
38
Constructor for the I<Koha::MetadataExtractor::MARC::UNIMARC> class.
38
Constructor for the I<Koha::Biblio::Metadata::Extractor::MARC::UNIMARC> class.
39
39
40
=cut
40
=cut
41
41
(-)a/t/Koha/MetadataExtractor.t (-8 / +8 lines)
Lines 25-50 use Test::MockModule; Link Here
25
25
26
use MARC::Record;
26
use MARC::Record;
27
27
28
use Koha::MetadataExtractor;
28
use Koha::Biblio::Metadata::Extractor;
29
29
30
subtest 'new() tests' => sub {
30
subtest 'new() tests' => sub {
31
31
32
    plan tests => 1;
32
    plan tests => 1;
33
33
34
    my $extractor = Koha::MetadataExtractor->new;
34
    my $extractor = Koha::Biblio::Metadata::Extractor->new;
35
    is( ref($extractor), 'Koha::MetadataExtractor' );
35
    is( ref($extractor), 'Koha::Biblio::Metadata::Extractor' );
36
};
36
};
37
37
38
subtest 'get_extractor() tests' => sub {
38
subtest 'get_extractor() tests' => sub {
39
39
40
    plan tests => 8;
40
    plan tests => 8;
41
41
42
    my $extractor = Koha::MetadataExtractor->new;
42
    my $extractor = Koha::Biblio::Metadata::Extractor->new;
43
43
44
    foreach my $schema (qw{ MARC21 UNIMARC }) {
44
    foreach my $schema (qw{ MARC21 UNIMARC }) {
45
        my $specific_extractor = $extractor->get_extractor( { schema => $schema } );
45
        my $specific_extractor = $extractor->get_extractor( { schema => $schema } );
46
        is(
46
        is(
47
            ref($specific_extractor), "Koha::MetadataExtractor::MARC::$schema",
47
            ref($specific_extractor), "Koha::Biblio::Metadata::Extractor::MARC::$schema",
48
            "Returns the right extractor library for schema ($schema)"
48
            "Returns the right extractor library for schema ($schema)"
49
        );
49
        );
50
        ok( exists $extractor->{extractors}->{$schema}, "Extractor for $schema cached" );
50
        ok( exists $extractor->{extractors}->{$schema}, "Extractor for $schema cached" );
Lines 73-86 subtest 'get_normalized_upc() tests' => sub { Link Here
73
73
74
    plan tests => 6;
74
    plan tests => 6;
75
75
76
    my $extractor = Koha::MetadataExtractor->new;
76
    my $extractor = Koha::Biblio::Metadata::Extractor->new;
77
77
78
    my $record = MARC::Record->new();
78
    my $record = MARC::Record->new();
79
79
80
    my $mock_marc21 = Test::MockModule->new('Koha::MetadataExtractor::MARC::MARC21');
80
    my $mock_marc21 = Test::MockModule->new('Koha::Biblio::Metadata::Extractor::MARC::MARC21');
81
    $mock_marc21->mock( 'get_normalized_upc', sub { return 'MARC21' } );
81
    $mock_marc21->mock( 'get_normalized_upc', sub { return 'MARC21' } );
82
82
83
    my $mock_unimarc = Test::MockModule->new('Koha::MetadataExtractor::MARC::UNIMARC');
83
    my $mock_unimarc = Test::MockModule->new('Koha::Biblio::Metadata::Extractor::MARC::UNIMARC');
84
    $mock_unimarc->mock( 'get_normalized_upc', sub { return 'UNIMARC' } );
84
    $mock_unimarc->mock( 'get_normalized_upc', sub { return 'UNIMARC' } );
85
85
86
    foreach my $schema (qw{ MARC21 UNIMARC }) {
86
    foreach my $schema (qw{ MARC21 UNIMARC }) {
(-)a/t/Koha/MetadataExtractor/MARC/MARC21.t (-4 / +4 lines)
Lines 24-44 use Test::Exception; Link Here
24
24
25
use MARC::Record;
25
use MARC::Record;
26
26
27
use Koha::MetadataExtractor::MARC::MARC21;
27
use Koha::Biblio::Metadata::Extractor::MARC::MARC21;
28
28
29
subtest 'new() tests' => sub {
29
subtest 'new() tests' => sub {
30
30
31
    plan tests => 1;
31
    plan tests => 1;
32
32
33
    my $extractor = Koha::MetadataExtractor::MARC::MARC21->new;
33
    my $extractor = Koha::Biblio::Metadata::Extractor::MARC::MARC21->new;
34
    is( ref($extractor), 'Koha::MetadataExtractor::MARC::MARC21' );
34
    is( ref($extractor), 'Koha::Biblio::Metadata::Extractor::MARC::MARC21' );
35
};
35
};
36
36
37
subtest 'get_normalized_upc() tests' => sub {
37
subtest 'get_normalized_upc() tests' => sub {
38
38
39
    plan tests => 6;
39
    plan tests => 6;
40
40
41
    my $extractor = Koha::MetadataExtractor::MARC::MARC21->new;
41
    my $extractor = Koha::Biblio::Metadata::Extractor::MARC::MARC21->new;
42
42
43
    my $record = MARC::Record->new();
43
    my $record = MARC::Record->new();
44
    $record->append_fields( MARC::Field->new( '024', '1', ' ', a => "9-123345345X" ) );
44
    $record->append_fields( MARC::Field->new( '024', '1', ' ', a => "9-123345345X" ) );
(-)a/t/Koha/MetadataExtractor/MARC/UNIMARC.t (-5 / +4 lines)
Lines 24-44 use Test::Exception; Link Here
24
24
25
use MARC::Record;
25
use MARC::Record;
26
26
27
use Koha::MetadataExtractor::MARC::UNIMARC;
27
use Koha::Biblio::Metadata::Extractor::MARC::UNIMARC;
28
28
29
subtest 'new() tests' => sub {
29
subtest 'new() tests' => sub {
30
30
31
    plan tests => 1;
31
    plan tests => 1;
32
32
33
    my $extractor = Koha::MetadataExtractor::MARC::UNIMARC->new;
33
    my $extractor = Koha::Biblio::Metadata::Extractor::MARC::UNIMARC->new;
34
    is( ref($extractor), 'Koha::MetadataExtractor::MARC::UNIMARC' );
34
    is( ref($extractor), 'Koha::Biblio::Metadata::Extractor::MARC::UNIMARC' );
35
};
35
};
36
36
37
subtest 'get_normalized_upc() tests' => sub {
37
subtest 'get_normalized_upc() tests' => sub {
38
38
39
    plan tests => 6;
39
    plan tests => 6;
40
40
41
    my $extractor = Koha::MetadataExtractor::MARC::UNIMARC->new;
41
    my $extractor = Koha::Biblio::Metadata::Extractor::MARC::UNIMARC->new;
42
42
43
    my $record = MARC::Record->new();
43
    my $record = MARC::Record->new();
44
    $record->append_fields( MARC::Field->new( '072', '1', ' ', a => "9-123345345X" ) );
44
    $record->append_fields( MARC::Field->new( '072', '1', ' ', a => "9-123345345X" ) );
45
- 

Return to bug 34828