|
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 => 5; |
| 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 'av handling' => sub { |
| 1578 |
|
| 1579 |
plan tests => 4; |
| 1580 |
|
| 1581 |
ok( exists $strings->{itemlost}, "'itemlost' entry exists" ); |
| 1582 |
is( $strings->{itemlost}->{str}, $lost_av->lib, "'str' set to av->lib" ); |
| 1583 |
is( $strings->{itemlost}->{type}, 'av', "'type' is 'av'" ); |
| 1584 |
is( $strings->{itemlost}->{category}, 'LOST', "'category' exists and set to 'LOST'" ); |
| 1585 |
}; |
| 1586 |
|
| 1587 |
subtest 'cn_source handling' => sub { |
| 1588 |
|
| 1589 |
plan tests => 3; |
| 1590 |
|
| 1591 |
ok( exists $strings->{cn_source}, "'cn_source' entry exists" ); |
| 1592 |
is( $strings->{cn_source}->{str}, $class_source->description, "'str' set to \$class_source->description" ); |
| 1593 |
is( $strings->{cn_source}->{type}, 'call_number_source', "type is 'library'" ); |
| 1594 |
}; |
| 1595 |
|
| 1596 |
subtest 'branches handling' => sub { |
| 1597 |
|
| 1598 |
plan tests => 3; |
| 1599 |
|
| 1600 |
ok( exists $strings->{homebranch}, "'homebranch' entry exists" ); |
| 1601 |
is( $strings->{homebranch}->{str}, $library->branchname, "'str' set to 'branchname'" ); |
| 1602 |
is( $strings->{homebranch}->{type}, 'library', "type is 'library'" ); |
| 1603 |
}; |
| 1604 |
|
| 1605 |
subtest 'itemtype handling' => sub { |
| 1606 |
|
| 1607 |
plan tests => 3; |
| 1608 |
|
| 1609 |
ok( exists $strings->{itype}, "'itype' entry exists" ); |
| 1610 |
is( $strings->{itype}->{str}, $itype->description, "'str' correctly set" ); |
| 1611 |
is( $strings->{itype}->{type}, 'item_type', "'type' is 'item_type'" ); |
| 1612 |
}; |
| 1613 |
|
| 1614 |
subtest 'public flag tests' => sub { |
| 1615 |
|
| 1616 |
plan tests => 4; |
| 1617 |
|
| 1618 |
$strings = $item->strings_map( { public => 1 } ); |
| 1619 |
|
| 1620 |
ok( exists $strings->{itemlost}, "'itemlost' entry exists" ); |
| 1621 |
is( $strings->{itemlost}->{str}, $lost_av->lib_opac, "'str' set to av->lib" ); |
| 1622 |
is( $strings->{itemlost}->{type}, 'av', "'type' is 'av'" ); |
| 1623 |
is( $strings->{itemlost}->{category}, 'LOST', "'category' exists and set to 'LOST'" ); |
| 1624 |
}; |
| 1625 |
|
| 1626 |
$cache->clear_from_cache("MarcStructure-0-"); |
| 1627 |
$cache->clear_from_cache("MarcStructure-1-"); |
| 1628 |
$cache->clear_from_cache("MarcSubfieldStructure-"); |
| 1629 |
|
| 1630 |
$schema->storage->txn_rollback; |
| 1631 |
}; |
| 1632 |
|
| 1444 |
subtest 'store() tests' => sub { |
1633 |
subtest 'store() tests' => sub { |
| 1445 |
|
1634 |
|
| 1446 |
plan tests => 3; |
1635 |
plan tests => 3; |
| 1447 |
- |
|
|