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

(-)a/t/db_dependent/Koha/Items.t (-2 / +110 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 11;
22
use Test::More tests => 13;
23
use Test::Exception;
23
use Test::Exception;
24
24
25
use C4::Circulation;
25
use C4::Circulation;
Lines 241-243 $retrieved_item_1->delete; Link Here
241
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' );
241
is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' );
242
242
243
$schema->storage->txn_rollback;
243
$schema->storage->txn_rollback;
244
- 
244
245
subtest 'filter_by_visible_in_opac() tests' => sub {
246
247
    plan tests => 8;
248
249
    $schema->storage->txn_begin;
250
251
    # have a fresh biblio
252
    my $biblio = $builder->build_sample_biblio;
253
    # have two itemtypes
254
    my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' });
255
    my $itype_2 = $builder->build_object({ class => 'Koha::ItemTypes' });
256
    # have 5 items on that biblio
257
    my $item_1 = $builder->build_sample_item(
258
        {
259
            biblionumber => $biblio->biblionumber,
260
            itemlost     => -1,
261
            itype        => $itype_1->itemtype,
262
            withdrawn    => 1
263
        }
264
    );
265
    my $item_2 = $builder->build_sample_item(
266
        {
267
            biblionumber => $biblio->biblionumber,
268
            itemlost     => 0,
269
            itype        => $itype_2->itemtype,
270
            withdrawn    => 2
271
        }
272
    );
273
    my $item_3 = $builder->build_sample_item(
274
        {
275
            biblionumber => $biblio->biblionumber,
276
            itemlost     => 1,
277
            itype        => $itype_1->itemtype,
278
            withdrawn    => 3
279
        }
280
    );
281
    my $item_4 = $builder->build_sample_item(
282
        {
283
            biblionumber => $biblio->biblionumber,
284
            itemlost     => 0,
285
            itype        => $itype_2->itemtype,
286
            withdrawn    => 4
287
        }
288
    );
289
    my $item_5 = $builder->build_sample_item(
290
        {
291
            biblionumber => $biblio->biblionumber,
292
            itemlost     => undef,
293
            itype        => $itype_1->itemtype,
294
            withdrawn    => 5
295
        }
296
    );
297
298
    my $rules = {};
299
300
    t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
301
    is( $biblio->items->filter_by_visible_in_opac->count,
302
        5, 'No rules passed, hidelostitems unset' );
303
304
    t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
305
    is(
306
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
307
        4,
308
        'No rules passed, hidelostitems set'
309
    );
310
311
    $rules = { withdrawn => [ 1, 2 ] };
312
    is(
313
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
314
        2,
315
        'Rules on withdrawn, hidelostitems set'
316
    );
317
318
    $rules = { itype => [ $itype_1->itemtype ] };
319
    is(
320
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
321
        2,
322
        'Rules on itype, hidelostitems set'
323
    );
324
325
    $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_1->itemtype ] };
326
    is(
327
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
328
        1,
329
        'Rules on itype and withdrawn, hidelostitems set'
330
    );
331
    is(
332
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )
333
          ->next->itemnumber,
334
        $item_4->itemnumber,
335
        'The right item is returned'
336
    );
337
338
    $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_2->itemtype ] };
339
    is(
340
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
341
        1,
342
        'Rules on itype and withdrawn, hidelostitems set'
343
    );
344
    is(
345
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )
346
          ->next->itemnumber,
347
        $item_5->itemnumber,
348
        'The right item is returned'
349
    );
350
351
    $schema->storage->txn_rollback;
352
};

Return to bug 24254