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

(-)a/t/db_dependent/Heading.t (-2 / +62 lines)
Lines 66-72 subtest "UNIMARC tests" => sub { Link Here
66
66
67
subtest "_search tests" => sub {
67
subtest "_search tests" => sub {
68
68
69
    plan tests => 10;
69
    plan tests => 14;
70
70
71
    t::lib::Mocks::mock_preference( 'marcflavour',  'MARC21' );
71
    t::lib::Mocks::mock_preference( 'marcflavour',  'MARC21' );
72
    t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' );
72
    t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' );
Lines 86-91 subtest "_search tests" => sub { Link Here
86
    );
86
    );
87
87
88
    t::lib::Mocks::mock_preference( 'LinkerConsiderThesaurus', '0' );
88
    t::lib::Mocks::mock_preference( 'LinkerConsiderThesaurus', '0' );
89
    t::lib::Mocks::mock_preference( 'ConsiderHeadingUse',      '0' );
89
90
90
    my $field          = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' );
91
    my $field          = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' );
91
    my $heading        = C4::Heading->new_from_field($field);
92
    my $heading        = C4::Heading->new_from_field($field);
Lines 219-222 subtest "_search tests" => sub { Link Here
219
        "When thesaurus in subfield 2, and nothing is found, we don't search again if LinkerConsiderThesaurusDisabled"
220
        "When thesaurus in subfield 2, and nothing is found, we don't search again if LinkerConsiderThesaurusDisabled"
220
    );
221
    );
221
222
223
    # return to the "original" mocked version of search_auth_compat:
224
    $search->mock(
225
        'search_auth_compat',
226
        sub {
227
            my $self         = shift;
228
            my $search_query = shift;
229
            return ( $search_query, 1 );
230
        }
231
    );
232
    t::lib::Mocks::mock_preference( 'ConsiderHeadingUse', '1' );
233
234
    ($search_query) = $heading->_search('match-heading');
235
    $terms          = $search_query->{query}->{bool}->{must};
236
    $expected_terms = [
237
        { term => { 'match-heading.ci_raw'                   => 'Uncles generalsubdiv Fiction' } },
238
        { term => { 'heading-use-subject-added-entry.ci_raw' => 'a' } },
239
    ];
240
    is_deeply(
241
        $terms, $expected_terms,
242
        "With ConsiderHeadingUse on and 650 tag Heading-use-subject-added-entry = 'a' is required in search query"
243
    );
244
245
    my $field_700   = MARC::Field->new( '700', '1', '2', a => 'Shakespeare William', t => 'Othello' );
246
    my $heading_700 = C4::Heading->new_from_field($field_700);
247
    ($search_query) = $heading_700->_search('match-heading');
248
    $terms          = $search_query->{query}->{bool}->{must};
249
    $expected_terms = [
250
        { term => { 'match-heading.ci_raw'                   => 'Shakespeare William Othello' } },
251
        { term => { 'heading-use-main-or-added-entry.ci_raw' => 'a' } },
252
    ];
253
    is_deeply(
254
        $terms, $expected_terms,
255
        "With ConsiderHeadingUse on and 700 tag Heading-use-main-or-added-entry = 'a' is required in search query"
256
    );
257
258
    my $field_800   = MARC::Field->new( '800', '1', ' ', a => 'Shakespeare William', t => 'Collected works' );
259
    my $heading_800 = C4::Heading->new_from_field($field_800);
260
    ($search_query) = $heading_800->_search('match-heading');
261
    $terms          = $search_query->{query}->{bool}->{must};
262
    $expected_terms = [
263
        { term => { 'match-heading.ci_raw'                  => 'Shakespeare William Collected works' } },
264
        { term => { 'heading-use-series-added-entry.ci_raw' => 'a' } },
265
    ];
266
    is_deeply(
267
        $terms, $expected_terms,
268
        "With ConsiderHeadingUse on and 800 tag Heading-use-series-added-entry = 'a' is required in search query"
269
    );
270
271
    t::lib::Mocks::mock_preference( 'ConsiderHeadingUse', '0' );
272
273
    ($search_query) = $heading_800->_search('match-heading');
274
    $terms          = $search_query->{query}->{bool}->{must};
275
    $expected_terms = [
276
        { term => { 'match-heading.ci_raw' => 'Shakespeare William Collected works' } },
277
    ];
278
    is_deeply(
279
        $terms, $expected_terms,
280
        "With ConsiderHeadingUse off and 800 tag there is no Heading-use-series-added-entry condition in search query"
281
    );
282
222
};
283
};
223
- 

Return to bug 33296