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

(-)a/t/db_dependent/Koha_Elasticsearch.t (-18 / +1 lines)
Lines 22-29 use Test::MockModule; Link Here
22
22
23
use t::lib::Mocks;
23
use t::lib::Mocks;
24
use MARC::Record;
24
use MARC::Record;
25
use Koha::SearchEngine::Elasticsearch::Indexer;
26
use JSON::XS;
27
25
28
my $schema = Koha::Database->schema;
26
my $schema = Koha::Database->schema;
29
27
Lines 31-37 use_ok('Koha::SearchEngine::Elasticsearch'); Link Here
31
29
32
subtest 'get_fixer_rules() tests' => sub {
30
subtest 'get_fixer_rules() tests' => sub {
33
31
34
    plan tests => 47;
32
    plan tests => 45;
35
33
36
    $schema->storage->txn_begin;
34
    $schema->storage->txn_begin;
37
35
Lines 79-99 subtest 'get_fixer_rules() tests' => sub { Link Here
79
        },
77
        },
80
    );
78
    );
81
79
82
    my $marc_record = MARC::Record->new();
83
    $marc_record->append_fields(
84
        MARC::Field->new( '001', '1234567' ),
85
        MARC::Field->new( '020', '', '', 'a' => '1234567890123' ),
86
        MARC::Field->new( '100', '', '', 'a' => 'Author' ),
87
        MARC::Field->new( '110', '', '', 'a' => 'Corp Author' ),
88
        MARC::Field->new( '245', '', '', 'a' => 'Title' ),
89
    );
90
    my @records = ( $marc_record );
91
92
    my $importer = Koha::SearchEngine::Elasticsearch::Indexer->new({ index => 'biblios' });
93
    my $conv = $importer->_convert_marc_to_json( \@records )->next();
94
    is( $conv->{author}[0][0], "Author", "First mapped author should be 100a");
95
    is( $conv->{author}[1][0], "Corp Author", "Second mapped author should be 110a");
96
97
    my $result = $see->get_fixer_rules();
80
    my $result = $see->get_fixer_rules();
98
    is( $result->[0], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{.$append', -split => 1)});
81
    is( $result->[0], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{.$append', -split => 1)});
99
    is( $result->[1], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__facet', -split => 1)});
82
    is( $result->[1], q{marc_map('} . $mappings[0]->{marc_field} . q{','} . $mappings[0]->{name} . q{__facet', -split => 1)});
(-)a/t/db_dependent/Koha_Elasticsearch_Indexer.t (-2 / +72 lines)
Lines 17-26 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 5;
20
use Test::More tests => 6;
21
use Test::MockModule;
22
use t::lib::Mocks;
21
23
22
use MARC::Record;
24
use MARC::Record;
23
25
26
use Koha::Database;
27
28
my $schema = Koha::Database->schema();
29
24
use_ok('Koha::SearchEngine::Elasticsearch::Indexer');
30
use_ok('Koha::SearchEngine::Elasticsearch::Indexer');
25
31
26
my $indexer;
32
my $indexer;
Lines 52-55 SKIP: { Link Here
52
    ok( $indexer->update_index(undef,$records), 'Update Index' );
58
    ok( $indexer->update_index(undef,$records), 'Update Index' );
53
}
59
}
54
60
61
subtest '_convert_marc_to_json() tests' => sub {
62
63
    plan tests => 2;
64
65
    $schema->storage->txn_begin;
66
67
    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
68
69
    my @mappings = (
70
        {
71
            name => 'author',
72
            type => 'string',
73
            facet => 1,
74
            suggestible => 1,
75
            sort => '~',
76
            marc_type => 'marc21',
77
            marc_field => '100a',
78
        },
79
        {
80
            name => 'author',
81
            type => 'string',
82
            facet => 1,
83
            suggestible => 1,
84
            sort => '~',
85
            marc_type => 'marc21',
86
            marc_field => '110a',
87
        },
88
    );
89
90
91
    my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' );
92
    $se->mock( '_foreach_mapping', sub {
93
        my ($self, $sub ) = @_;
94
95
        foreach my $map ( @mappings ) {
96
            $sub->(
97
                $map->{name},
98
                $map->{type},
99
                $map->{facet},
100
                $map->{suggestible},
101
                $map->{sort},
102
                $map->{marc_type},
103
                $map->{marc_field}
104
            );
105
        }
106
    });
107
108
    my $marc_record = MARC::Record->new();
109
    $marc_record->append_fields(
110
        MARC::Field->new( '001', '1234567' ),
111
        MARC::Field->new( '020', '', '', 'a' => '1234567890123' ),
112
        MARC::Field->new( '100', '', '', 'a' => 'Author' ),
113
        MARC::Field->new( '110', '', '', 'a' => 'Corp Author' ),
114
        MARC::Field->new( '245', '', '', 'a' => 'Title' ),
115
    );
116
    my @records = ( $marc_record );
117
118
    my $importer = Koha::SearchEngine::Elasticsearch::Indexer->new({ index => 'biblios' });
119
    my $conv = $importer->_convert_marc_to_json( \@records )->next();
120
    is( $conv->{author}[0][0], "Author", "First mapped author should be 100a");
121
    is( $conv->{author}[1][0], "Corp Author", "Second mapped author should be 110a");
122
123
    $schema->storage->txn_rollback;
124
};
125
55
1;
126
1;
56
- 

Return to bug 18434