|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 39; |
20 |
use Test::More tests => 41; |
| 21 |
use Test::Exception; |
21 |
use Test::Exception; |
| 22 |
use Test::Warn; |
22 |
use Test::Warn; |
| 23 |
|
23 |
|
|
Lines 1989-1991
subtest 'check_booking tests' => sub {
Link Here
|
| 1989 |
|
1989 |
|
| 1990 |
$schema->storage->txn_rollback; |
1990 |
$schema->storage->txn_rollback; |
| 1991 |
}; |
1991 |
}; |
| 1992 |
- |
1992 |
|
|
|
1993 |
subtest 'get_first_callnumber() tests' => sub { |
| 1994 |
|
| 1995 |
plan tests => 4; |
| 1996 |
|
| 1997 |
$schema->storage->txn_begin; |
| 1998 |
|
| 1999 |
my $biblio = $builder->build_sample_biblio(); |
| 2000 |
my $record = $biblio->record; |
| 2001 |
|
| 2002 |
my $cn_1 = q{PA522}; |
| 2003 |
my $in_1 = q{.M38 1993}; |
| 2004 |
|
| 2005 |
my $cn_2 = q{PA523}; |
| 2006 |
my $in_2 = q{.M38 2024}; |
| 2007 |
|
| 2008 |
$record->insert_fields_ordered( MARC::Field->new( '050', ' ', ' ', a => $cn_1, b => $in_1 ) ); |
| 2009 |
$record->insert_fields_ordered( MARC::Field->new( '051', ' ', ' ', a => $cn_2, b => $in_2 ) ); |
| 2010 |
|
| 2011 |
ModBiblio( $record, $biblio->id ); |
| 2012 |
$biblio = $biblio->get_from_storage; # refresh object to avoid internal cache |
| 2013 |
|
| 2014 |
my $expected_callnumber_1 = $cn_1 . $in_1; |
| 2015 |
my $expected_callnumber_2 = $cn_2 . $in_2; |
| 2016 |
|
| 2017 |
t::lib::Mocks::mock_preference( 'itemcallnumber', '' ); |
| 2018 |
|
| 2019 |
throws_ok { $biblio->get_first_callnumber(); } |
| 2020 |
'Koha::Exceptions::SysPref::NotSet', |
| 2021 |
'Exception thrown if method called but missing configuration'; |
| 2022 |
|
| 2023 |
t::lib::Mocks::mock_preference( 'itemcallnumber', '050ab,051ab' ); |
| 2024 |
|
| 2025 |
is( $biblio->get_first_callnumber(), $expected_callnumber_1 ); |
| 2026 |
|
| 2027 |
$record->delete_fields( $record->field('050') ); |
| 2028 |
ModBiblio( $record, $biblio->id ); |
| 2029 |
$biblio = $biblio->get_from_storage; # refresh object to avoid internal cache |
| 2030 |
|
| 2031 |
is( $biblio->get_first_callnumber(), $expected_callnumber_2 ); |
| 2032 |
|
| 2033 |
t::lib::Mocks::mock_preference( 'itemcallnumber', '050ab' ); |
| 2034 |
throws_ok { $biblio->get_first_callnumber(); } |
| 2035 |
'Koha::Exceptions::Biblio::MissingField', |
| 2036 |
'Exception thrown if requested field is not present'; |
| 2037 |
|
| 2038 |
$schema->storage->txn_rollback; |
| 2039 |
}; |
| 2040 |
|
| 2041 |
subtest 'populate_item_callnumbers() tests' => sub { |
| 2042 |
|
| 2043 |
plan tests => 7; |
| 2044 |
|
| 2045 |
$schema->storage->txn_begin; |
| 2046 |
|
| 2047 |
my $biblio = $builder->build_sample_biblio(); |
| 2048 |
my $record = $biblio->record; |
| 2049 |
|
| 2050 |
my $cn = q{PA522}; |
| 2051 |
my $in = q{.M38 1993}; |
| 2052 |
|
| 2053 |
$record->insert_fields_ordered( MARC::Field->new( '050', ' ', ' ', a => $cn, b => $in ) ); |
| 2054 |
|
| 2055 |
my $expected_callnumber = $cn . $in; |
| 2056 |
|
| 2057 |
t::lib::Mocks::mock_preference( 'itemcallnumber', '' ); |
| 2058 |
|
| 2059 |
throws_ok { $biblio->populate_item_callnumbers() } |
| 2060 |
q{Koha::Exceptions::SysPref::NotSet}; |
| 2061 |
|
| 2062 |
t::lib::Mocks::mock_preference( 'itemcallnumber', '050ab' ); |
| 2063 |
|
| 2064 |
throws_ok { $biblio->populate_item_callnumbers() } |
| 2065 |
q{Koha::Exceptions::Biblio::MissingField}; |
| 2066 |
|
| 2067 |
ModBiblio( $record, $biblio->id ); |
| 2068 |
$biblio = $biblio->get_from_storage(); |
| 2069 |
|
| 2070 |
$biblio->populate_item_callnumbers(); |
| 2071 |
|
| 2072 |
my $message = $biblio->object_messages()->[0]; |
| 2073 |
is( $message->{payload}->{callnumber}, $expected_callnumber ); |
| 2074 |
is( $message->{payload}->{updated_items_count}, 0 ); |
| 2075 |
|
| 2076 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->id, itemcallnumber => q{yes} } ); |
| 2077 |
my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->id, itemcallnumber => q{boo} } ); |
| 2078 |
my $item_3 = $builder->build_sample_item( { biblionumber => $biblio->id, itemcallnumber => q{yes} } ); |
| 2079 |
|
| 2080 |
$biblio = $biblio->get_from_storage(); |
| 2081 |
$biblio->populate_item_callnumbers( { itemcallnumber => { '!=' => q{boo} } } ); |
| 2082 |
|
| 2083 |
$message = $biblio->object_messages()->[0]; |
| 2084 |
is( $message->{payload}->{callnumber}, $expected_callnumber ); |
| 2085 |
is( $message->{payload}->{updated_items_count}, 2 ); |
| 2086 |
is_deeply( $message->{payload}->{modified_item_ids}, [ $item_1->id, $item_3->id ] ); |
| 2087 |
|
| 2088 |
$schema->storage->txn_rollback; |
| 2089 |
}; |