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 => 12;
22
use Test::More tests => 13;
23
use Test::Exception;
23
use Test::Exception;
24
use Time::Fake;
24
use Time::Fake;
25
25
Lines 1279-1281 $retrieved_item_1->delete; Link Here
1279
is( Koha::Items->search->count, $nb_of_items - 1, 'Delete should have deleted the item' );
1279
is( Koha::Items->search->count, $nb_of_items - 1, 'Delete should have deleted the item' );
1280
1280
1281
$schema->storage->txn_rollback;
1281
$schema->storage->txn_rollback;
1282
- 
1282
1283
subtest 'filter_by_visible_in_opac() tests' => sub {
1284
1285
    plan tests => 8;
1286
1287
    $schema->storage->txn_begin;
1288
1289
    # have a fresh biblio
1290
    my $biblio = $builder->build_sample_biblio;
1291
    # have two itemtypes
1292
    my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' });
1293
    my $itype_2 = $builder->build_object({ class => 'Koha::ItemTypes' });
1294
    # have 5 items on that biblio
1295
    my $item_1 = $builder->build_sample_item(
1296
        {
1297
            biblionumber => $biblio->biblionumber,
1298
            itemlost     => -1,
1299
            itype        => $itype_1->itemtype,
1300
            withdrawn    => 1
1301
        }
1302
    );
1303
    my $item_2 = $builder->build_sample_item(
1304
        {
1305
            biblionumber => $biblio->biblionumber,
1306
            itemlost     => 0,
1307
            itype        => $itype_2->itemtype,
1308
            withdrawn    => 2
1309
        }
1310
    );
1311
    my $item_3 = $builder->build_sample_item(
1312
        {
1313
            biblionumber => $biblio->biblionumber,
1314
            itemlost     => 1,
1315
            itype        => $itype_1->itemtype,
1316
            withdrawn    => 3
1317
        }
1318
    );
1319
    my $item_4 = $builder->build_sample_item(
1320
        {
1321
            biblionumber => $biblio->biblionumber,
1322
            itemlost     => 0,
1323
            itype        => $itype_2->itemtype,
1324
            withdrawn    => 4
1325
        }
1326
    );
1327
    my $item_5 = $builder->build_sample_item(
1328
        {
1329
            biblionumber => $biblio->biblionumber,
1330
            itemlost     => undef,
1331
            itype        => $itype_1->itemtype,
1332
            withdrawn    => 5
1333
        }
1334
    );
1335
1336
    my $rules = {};
1337
1338
    t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
1339
    is( $biblio->items->filter_by_visible_in_opac->count,
1340
        5, 'No rules passed, hidelostitems unset' );
1341
1342
    t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
1343
    is(
1344
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
1345
        4,
1346
        'No rules passed, hidelostitems set'
1347
    );
1348
1349
    $rules = { withdrawn => [ 1, 2 ] };
1350
    is(
1351
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
1352
        2,
1353
        'Rules on withdrawn, hidelostitems set'
1354
    );
1355
1356
    $rules = { itype => [ $itype_1->itemtype ] };
1357
    is(
1358
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
1359
        2,
1360
        'Rules on itype, hidelostitems set'
1361
    );
1362
1363
    $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_1->itemtype ] };
1364
    is(
1365
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
1366
        1,
1367
        'Rules on itype and withdrawn, hidelostitems set'
1368
    );
1369
    is(
1370
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )
1371
          ->next->itemnumber,
1372
        $item_4->itemnumber,
1373
        'The right item is returned'
1374
    );
1375
1376
    $rules = { withdrawn => [ 1, 2 ], itype => [ $itype_2->itemtype ] };
1377
    is(
1378
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )->count,
1379
        1,
1380
        'Rules on itype and withdrawn, hidelostitems set'
1381
    );
1382
    is(
1383
        $biblio->items->filter_by_visible_in_opac( { rules => $rules } )
1384
          ->next->itemnumber,
1385
        $item_5->itemnumber,
1386
        'The right item is returned'
1387
    );
1388
1389
    $schema->storage->txn_rollback;
1390
};

Return to bug 24254