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

(-)a/t/db_dependent/Search.t (-2 / +95 lines)
Lines 27-33 require C4::Context; Link Here
27
use open ':std', ':encoding(utf8)';
27
use open ':std', ':encoding(utf8)';
28
28
29
use Test::NoWarnings;
29
use Test::NoWarnings;
30
use Test::More tests => 4;
30
use Test::More tests => 5;
31
use Test::MockModule;
31
use Test::MockModule;
32
use Test::Warn;
32
use Test::Warn;
33
use t::lib::Mocks;
33
use t::lib::Mocks;
Lines 235-240 sub mock_GetMarcSubfieldStructure { Link Here
235
    }
235
    }
236
}
236
}
237
237
238
subtest 'searchResults branch-specific counts for Bug 37883' => sub {
239
    plan tests => 8;
240
241
    use C4::Search qw( searchResults );
242
243
    my $record = MARC::Record->new();
244
    $record->add_fields(
245
        [ '001', '123' ],
246
        [ '245', ' ', ' ', a => 'Test record for branch counting' ],
247
        [ '999', ' ', ' ', c => '123', d => '123' ],
248
249
        # Available item from CPL
250
        [
251
            '952', ' ', ' ',
252
            a   => 'CPL',        # homebranch
253
            b   => 'CPL',        # holdingbranch
254
            p   => 'TEST001',    # barcode
255
            y   => 'BK',         # itemtype
256
            '9' => '1001',       # itemnumber
257
            '0' => '0',          # withdrawn
258
            '1' => '0',          # itemlost
259
            '4' => '0',          # damaged
260
            '7' => '0',          # notforloan
261
            q   => '',           # onloan
262
        ],
263
264
        # Withdrawn item from CPL
265
        [
266
            '952', ' ', ' ',
267
            a   => 'CPL',        # homebranch
268
            b   => 'CPL',        # holdingbranch
269
            p   => 'TEST002',    # barcode
270
            y   => 'BK',         # itemtype
271
            '9' => '1002',       # itemnumber
272
            '0' => '1',          # withdrawn = yes
273
            '1' => '0',          # itemlost
274
            '4' => '0',          # damaged
275
            '7' => '0',          # notforloan
276
            q   => '',           # onloan
277
        ],
278
279
        # Available item from MPL
280
        [
281
            '952', ' ', ' ',
282
            a   => 'MPL',        # homebranch
283
            b   => 'MPL',        # holdingbranch
284
            p   => 'TEST003',    # barcode
285
            y   => 'BK',         # itemtype
286
            '9' => '1003',       # itemnumber
287
            '0' => '0',          # withdrawn
288
            '1' => '0',          # itemlost
289
            '4' => '0',          # damaged
290
            '7' => '0',          # notforloan
291
            q   => '',           # onloan
292
        ],
293
    );
294
295
    # Mock userenv for CPL branch
296
    my $context_mock = Test::MockModule->new('C4::Context');
297
    $context_mock->mock(
298
        'userenv',
299
        sub {
300
            return {
301
                branchcode => 'CPL',
302
                branch     => 'CPL',
303
                number     => 123,
304
            };
305
        }
306
    );
307
308
    my @results = searchResults(
309
        { interface => 'intranet' },
310
        'test query',
311
        1,     # total hits
312
        10,    # results per page
313
        0,     # offset
314
        0,     # scan
315
        [ $record->as_xml() ]
316
    );
317
318
    # Test that new branch count fields exist in search results
319
    ok( defined $results[0]->{branchavailablecount}, 'branchavailablecount exists' );
320
    ok( defined $results[0]->{branchonloancount},    'branchonloancount exists' );
321
    ok( defined $results[0]->{branchothercount},     'branchothercount  exists' );
322
    ok( defined $results[0]->{branchtotalcount},     'branchtotalcount  exists' );
323
324
    is( $results[0]->{branchavailablecount}, 1, 'Branch available count: 1 available item at CPL' );
325
    is( $results[0]->{branchothercount},     1, 'Branch other count: 1 withdrawn item at CPL' );
326
    is( $results[0]->{branchtotalcount},     2, 'Branch total count: 2 items total at CPL' );
327
328
    # Test that global counts still include all items from all branches
329
    is( $results[0]->{availablecount}, 2, 'Global available count: 2 items available at all branches' );
330
};
331
238
sub run_marc21_search_tests {
332
sub run_marc21_search_tests {
239
333
240
    $marcflavour = 'MARC21';
334
    $marcflavour = 'MARC21';
241
- 

Return to bug 37883