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

(-)a/t/db_dependent/Heading.t (-2 / +59 lines)
Lines 18-26 Link Here
18
use strict;
18
use strict;
19
use warnings;
19
use warnings;
20
20
21
use Test::More tests => 3;
21
use Test::More tests => 4;
22
22
23
use t::lib::Mocks;
23
use t::lib::Mocks;
24
use Test::MockModule;;
24
25
25
BEGIN {
26
BEGIN {
26
    use_ok('C4::Heading', qw( field valid_heading_subfield ));
27
    use_ok('C4::Heading', qw( field valid_heading_subfield ));
Lines 60-63 subtest "UNIMARC tests" => sub { Link Here
60
    ok(!C4::Heading::valid_heading_subfield('600', 'i'), '600i not valid for bib');
61
    ok(!C4::Heading::valid_heading_subfield('600', 'i'), '600i not valid for bib');
61
62
62
    ok(!C4::Heading::valid_heading_subfield('012', 'a'), '012a invalid field for bib');
63
    ok(!C4::Heading::valid_heading_subfield('012', 'a'), '012a invalid field for bib');
63
}
64
};
65
66
subtest "_search tests" => sub {
67
    plan tests => 4;
68
69
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
70
    t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch');
71
    my $search = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Search');
72
73
    $search->mock('search_auth_compat', sub {
74
        my $self = shift;
75
        my $search_query = shift;
76
        return $search_query;
77
    });
78
79
    my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' );
80
    my $heading = C4::Heading->new_from_field($field);
81
    my $search_query = $heading->_search( 'match-heading' );
82
    my $terms = $search_query->{query}->{bool}->{must};
83
    my $expected_terms = [
84
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
85
        { term => { 'subject-heading-thesaurus.ci_raw' => 'a' } },
86
    ];
87
    is_deeply( $terms, $expected_terms, "Search formed as expected for a subject with second indicator 0");
88
89
    $field = MARC::Field->new( '650', ' ', '3', a => 'Uncles', x => 'Fiction' );
90
    $heading = C4::Heading->new_from_field($field);
91
    $search_query = $heading->_search( 'match-heading' );
92
    $terms = $search_query->{query}->{bool}->{must};
93
    $expected_terms = [
94
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
95
        { term => { 'subject-heading-thesaurus.ci_raw' => 'd' } },
96
    ];
97
    is_deeply( $terms, $expected_terms, "Search formed as expected with second indicator 3");
98
99
    $field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' );
100
    $heading = C4::Heading->new_from_field($field);
101
    $search_query = $heading->_search( 'match-heading' );
102
    $terms = $search_query->{query}->{bool}->{must};
103
    $expected_terms = [
104
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
105
        { term => { 'subject-heading-thesaurus-conventions.ci_raw' => 'special_sauce' } },
106
        { term => { 'subject-heading-thesaurus.ci_raw' => 'z' } },
107
    ];
108
    is_deeply( $terms, $expected_terms, "Search formed as expected with second indicator 7 and subfield 2");
109
110
    $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,', e => '[author]' );
111
    $heading = C4::Heading->new_from_field($field);
112
    $search_query = $heading->_search( 'match-heading' );
113
    $terms = $search_query->{query}->{bool}->{must};
114
    $expected_terms = [
115
        { term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959-' } },
116
        { term => { 'subject-heading-thesaurus.ci_raw' => 'a' } },
117
    ];
118
    is_deeply( $terms, $expected_terms, "Search formed as expected for a non-subject field");
119
120
};
(-)a/t/db_dependent/Heading_MARC21.t (-3 / +10 lines)
Lines 6-12 Link Here
6
use strict;
6
use strict;
7
use warnings;
7
use warnings;
8
8
9
use Test::More tests => 5;
9
use Test::More tests => 10;
10
use C4::Context;
10
use C4::Context;
11
11
12
BEGIN {
12
BEGIN {
Lines 15-28 BEGIN { Link Here
15
15
16
SKIP: {
16
SKIP: {
17
    skip "MARC21 heading tests not applicable to UNIMARC", 2 if C4::Context->preference('marcflavour') eq 'UNIMARC';
17
    skip "MARC21 heading tests not applicable to UNIMARC", 2 if C4::Context->preference('marcflavour') eq 'UNIMARC';
18
    my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' );
18
    my $field = MARC::Field->new( '650', ' ', '2', a => 'Uncles', x => 'Fiction' );
19
    my $heading = C4::Heading->new_from_field($field);
19
    my $heading = C4::Heading->new_from_field($field);
20
    is($heading->display_form(), 'Uncles--Fiction', 'Display form generation');
20
    is($heading->display_form(), 'Uncles--Fiction', 'Display form generation');
21
    is($heading->search_form(), 'Uncles generalsubdiv Fiction', 'Search form generation');
21
    is($heading->search_form(), 'Uncles generalsubdiv Fiction', 'Search form generation');
22
    is($heading->{thesaurus}, 'mesh', 'Thesaurus generation');
22
23
23
    $field = MARC::Field->new( '830', ' ', '4', a => 'The dark is rising ;', v => '3' );
24
    $field = MARC::Field->new( '830', ' ', '4', a => 'The dark is rising ;', v => '3' );
24
    $heading = C4::Heading->new_from_field($field);
25
    $heading = C4::Heading->new_from_field($field);
25
    is($heading->display_form(), 'The dark is rising ;', 'Display form generation');
26
    is($heading->display_form(), 'The dark is rising ;', 'Display form generation');
26
    is($heading->search_form(), 'The dark is rising', 'Search form generation');
27
    is($heading->search_form(), 'The dark is rising', 'Search form generation');
28
    is($heading->{thesaurus}, 'lcsh', 'Thesaurus generation');
29
30
    $field = MARC::Field->new( '100', '1', '', a => 'Yankovic, Al', d => '1959-' );
31
    $heading = C4::Heading->new_from_field($field);
32
    is($heading->display_form(), 'Yankovic, Al 1959-', 'Display form generation');
33
    is($heading->search_form(), 'Yankovic, Al 1959', 'Search form generation');
34
    is($heading->{thesaurus}, 'lcsh', 'Thesaurus generation');
27
35
28
}
36
}
29
- 

Return to bug 33159