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

(-)a/t/db_dependent/Koha/Item.t (-2 / +197 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
use utf8;
21
use utf8;
22
22
23
use Test::More tests => 27;
23
use Test::More tests => 28;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
26
26
Lines 1441-1446 subtest 'columns_to_str' => sub { Link Here
1441
1441
1442
};
1442
};
1443
1443
1444
subtest 'strings_map() tests' => sub {
1445
1446
    plan tests => 6;
1447
1448
    $schema->storage->txn_begin;
1449
1450
    my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField("items.itemnumber");
1451
1452
    my $cache = Koha::Caches->get_instance();
1453
    $cache->clear_from_cache("MarcStructure-0-");
1454
    $cache->clear_from_cache("MarcStructure-1-");
1455
    $cache->clear_from_cache("MarcSubfieldStructure-");
1456
1457
    # Recreating subfields just to be sure tests will be ok
1458
    # 1 => av (LOST)
1459
    # 3 => no link
1460
    # a => branches
1461
    # y => itemtypes
1462
    Koha::MarcSubfieldStructures->search(
1463
        {
1464
            frameworkcode => '',
1465
            tagfield      => $itemtag,
1466
            tagsubfield   => [ '1', '2', '3', 'a', 'y' ],
1467
        }
1468
    )->delete;    # In case it exist already
1469
1470
    Koha::MarcSubfieldStructure->new(
1471
        {
1472
            authorised_value => 'LOST',
1473
            defaultvalue     => '',
1474
            frameworkcode    => '',
1475
            kohafield        => 'items.itemlost',
1476
            repeatable       => 1,
1477
            tab              => 10,
1478
            tagfield         => $itemtag,
1479
            tagsubfield      => '1',
1480
        }
1481
    )->store;
1482
    Koha::MarcSubfieldStructure->new(
1483
        {
1484
            authorised_value => 'cn_source',
1485
            defaultvalue     => '',
1486
            frameworkcode    => '',
1487
            kohafield        => 'items.cn_source',
1488
            repeatable       => 1,
1489
            tab              => 10,
1490
            tagfield         => $itemtag,
1491
            tagsubfield      => '2',
1492
        }
1493
    )->store;
1494
    Koha::MarcSubfieldStructure->new(
1495
        {
1496
            authorised_value => '',
1497
            defaultvalue     => '',
1498
            frameworkcode    => '',
1499
            kohafield        => 'items.materials',
1500
            repeatable       => 1,
1501
            tab              => 10,
1502
            tagfield         => $itemtag,
1503
            tagsubfield      => '3',
1504
        }
1505
    )->store;
1506
    Koha::MarcSubfieldStructure->new(
1507
        {
1508
            authorised_value => 'branches',
1509
            defaultvalue     => '',
1510
            frameworkcode    => '',
1511
            kohafield        => 'items.homebranch',
1512
            repeatable       => 1,
1513
            tab              => 10,
1514
            tagfield         => $itemtag,
1515
            tagsubfield      => 'a',
1516
        }
1517
    )->store;
1518
    Koha::MarcSubfieldStructure->new(
1519
        {
1520
            authorised_value => 'itemtypes',
1521
            defaultvalue     => '',
1522
            frameworkcode    => '',
1523
            kohafield        => 'items.itype',
1524
            repeatable       => 1,
1525
            tab              => 10,
1526
            tagfield         => $itemtag,
1527
            tagsubfield      => 'y',
1528
        }
1529
    )->store;
1530
1531
    my $itype   = $builder->build_object( { class => 'Koha::ItemTypes' } );
1532
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1533
    my $biblio  = $builder->build_sample_biblio( { frameworkcode => '' } );
1534
    my $item    = $builder->build_sample_item(
1535
        {
1536
            biblionumber => $biblio->id,
1537
            library      => $library->id
1538
        }
1539
    );
1540
1541
    Koha::AuthorisedValues->search( { authorised_value => 3, category => 'LOST' } )->delete;
1542
    my $lost_av = $builder->build_object(
1543
        {
1544
            class => 'Koha::AuthorisedValues',
1545
            value => {
1546
                authorised_value => 3,
1547
                category         => 'LOST',
1548
                lib              => 'internal description',
1549
                lib_opac         => 'public description',
1550
            }
1551
        }
1552
    );
1553
1554
    my $class_sort_rule  = $builder->build_object( { class => 'Koha::ClassSortRules', value => { sort_routine => 'Generic' } } );
1555
    my $class_split_rule = $builder->build_object( { class => 'Koha::ClassSplitRules' } );
1556
    my $class_source     = $builder->build_object(
1557
        {
1558
            class => 'Koha::ClassSources',
1559
            value => {
1560
                class_sort_rule  => $class_sort_rule->class_sort_rule,
1561
                class_split_rule => $class_split_rule->class_split_rule,
1562
            }
1563
        }
1564
    );
1565
1566
    $item->set(
1567
        {
1568
            cn_source => $class_source->id,
1569
            itemlost  => $lost_av->authorised_value,
1570
            itype     => $itype->itemtype,
1571
            materials => 'Suff',
1572
        }
1573
    )->store->discard_changes;
1574
1575
    my $strings = $item->strings_map;
1576
1577
    subtest 'unmapped field tests' => sub {
1578
1579
        plan tests => 1;
1580
1581
        ok( !exists $strings->{materials}, "Unmapped field not present" );
1582
    };
1583
1584
    subtest 'av handling' => sub {
1585
1586
        plan tests => 4;
1587
1588
        ok( exists $strings->{itemlost}, "'itemlost' entry exists" );
1589
        is( $strings->{itemlost}->{str},      $lost_av->lib, "'str' set to av->lib" );
1590
        is( $strings->{itemlost}->{type},     'av',          "'type' is 'av'" );
1591
        is( $strings->{itemlost}->{category}, 'LOST',        "'category' exists and set to 'LOST'" );
1592
    };
1593
1594
    subtest 'cn_source handling' => sub {
1595
1596
        plan tests => 3;
1597
1598
        ok( exists $strings->{cn_source}, "'cn_source' entry exists" );
1599
        is( $strings->{cn_source}->{str},  $class_source->description,    "'str' set to \$class_source->description" );
1600
        is( $strings->{cn_source}->{type}, 'call_number_source', "type is 'library'" );
1601
    };
1602
1603
    subtest 'branches handling' => sub {
1604
1605
        plan tests => 3;
1606
1607
        ok( exists $strings->{homebranch}, "'homebranch' entry exists" );
1608
        is( $strings->{homebranch}->{str},  $library->branchname, "'str' set to 'branchname'" );
1609
        is( $strings->{homebranch}->{type}, 'library',            "type is 'library'" );
1610
    };
1611
1612
    subtest 'itemtype handling' => sub {
1613
1614
        plan tests => 3;
1615
1616
        ok( exists $strings->{itype}, "'itype' entry exists" );
1617
        is( $strings->{itype}->{str},  $itype->description, "'str' correctly set" );
1618
        is( $strings->{itype}->{type}, 'item_type',         "'type' is 'item_type'" );
1619
    };
1620
1621
    subtest 'public flag tests' => sub {
1622
1623
        plan tests => 4;
1624
1625
        $strings = $item->strings_map( { public => 1 } );
1626
1627
        ok( exists $strings->{itemlost}, "'itemlost' entry exists" );
1628
        is( $strings->{itemlost}->{str},      $lost_av->lib_opac, "'str' set to av->lib" );
1629
        is( $strings->{itemlost}->{type},     'av',               "'type' is 'av'" );
1630
        is( $strings->{itemlost}->{category}, 'LOST',             "'category' exists and set to 'LOST'" );
1631
    };
1632
1633
    $cache->clear_from_cache("MarcStructure-0-");
1634
    $cache->clear_from_cache("MarcStructure-1-");
1635
    $cache->clear_from_cache("MarcSubfieldStructure-");
1636
1637
    $schema->storage->txn_rollback;
1638
};
1639
1444
subtest 'store() tests' => sub {
1640
subtest 'store() tests' => sub {
1445
1641
1446
    plan tests => 3;
1642
    plan tests => 3;
1447
- 

Return to bug 33161