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

(-)a/t/db_dependent/Koha/Biblio.t (-2 / +99 lines)
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 1954-1956 subtest 'check_booking tests' => sub { Link Here
1954
1954
1955
    $schema->storage->txn_rollback;
1955
    $schema->storage->txn_rollback;
1956
};
1956
};
1957
- 
1957
1958
subtest 'get_first_callnumber() tests' => sub {
1959
1960
    plan tests => 4;
1961
1962
    $schema->storage->txn_begin;
1963
1964
    my $biblio = $builder->build_sample_biblio();
1965
    my $record = $biblio->record;
1966
1967
    my $cn_1 = q{PA522};
1968
    my $in_1 = q{.M38 1993};
1969
1970
    my $cn_2 = q{PA523};
1971
    my $in_2 = q{.M38 2024};
1972
1973
    $record->insert_fields_ordered( MARC::Field->new( '050', ' ', ' ', a => $cn_1, b => $in_1 ) );
1974
    $record->insert_fields_ordered( MARC::Field->new( '051', ' ', ' ', a => $cn_2, b => $in_2 ) );
1975
1976
    ModBiblio( $record, $biblio->id );
1977
    $biblio = $biblio->get_from_storage;    # refresh object to avoid internal cache
1978
1979
    my $expected_callnumber_1 = $cn_1 . $in_1;
1980
    my $expected_callnumber_2 = $cn_2 . $in_2;
1981
1982
    t::lib::Mocks::mock_preference( 'itemcallnumber', '' );
1983
1984
    throws_ok { $biblio->get_first_callnumber(); }
1985
    'Koha::Exceptions::SysPref::NotSet',
1986
        'Exception thrown if method called but missing configuration';
1987
1988
    t::lib::Mocks::mock_preference( 'itemcallnumber', '050ab,051ab' );
1989
1990
    is( $biblio->get_first_callnumber(), $expected_callnumber_1 );
1991
1992
    $record->delete_fields( $record->field('050') );
1993
    ModBiblio( $record, $biblio->id );
1994
    $biblio = $biblio->get_from_storage;    # refresh object to avoid internal cache
1995
1996
    is( $biblio->get_first_callnumber(), $expected_callnumber_2 );
1997
1998
    t::lib::Mocks::mock_preference( 'itemcallnumber', '050ab' );
1999
    throws_ok { $biblio->get_first_callnumber(); }
2000
    'Koha::Exceptions::Biblio::MissingField',
2001
        'Exception thrown if requested field is not present';
2002
2003
    $schema->storage->txn_rollback;
2004
};
2005
2006
subtest 'populate_item_callnumbers() tests' => sub {
2007
2008
    plan tests => 7;
2009
2010
    $schema->storage->txn_begin;
2011
2012
    my $biblio = $builder->build_sample_biblio();
2013
    my $record = $biblio->record;
2014
2015
    my $cn = q{PA522};
2016
    my $in = q{.M38 1993};
2017
2018
    $record->insert_fields_ordered( MARC::Field->new( '050', ' ', ' ', a => $cn, b => $in ) );
2019
2020
    my $expected_callnumber = $cn . $in;
2021
2022
    t::lib::Mocks::mock_preference( 'itemcallnumber', '' );
2023
2024
    throws_ok { $biblio->populate_item_callnumbers() }
2025
    q{Koha::Exceptions::SysPref::NotSet};
2026
2027
    t::lib::Mocks::mock_preference( 'itemcallnumber', '050ab' );
2028
2029
    throws_ok { $biblio->populate_item_callnumbers() }
2030
    q{Koha::Exceptions::Biblio::MissingField};
2031
2032
    ModBiblio( $record, $biblio->id );
2033
    $biblio = $biblio->get_from_storage();
2034
2035
    $biblio->populate_item_callnumbers();
2036
2037
    my $message = $biblio->object_messages()->[0];
2038
    is( $message->{payload}->{callnumber},          $expected_callnumber );
2039
    is( $message->{payload}->{updated_items_count}, 0 );
2040
2041
    my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->id, itemcallnumber => q{yes} } );
2042
    my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->id, itemcallnumber => q{boo} } );
2043
    my $item_3 = $builder->build_sample_item( { biblionumber => $biblio->id, itemcallnumber => q{yes} } );
2044
2045
    $biblio = $biblio->get_from_storage();
2046
    $biblio->populate_item_callnumbers( { itemcallnumber => { '!=' => q{boo} } } );
2047
2048
    $message = $biblio->object_messages()->[0];
2049
    is( $message->{payload}->{callnumber},          $expected_callnumber );
2050
    is( $message->{payload}->{updated_items_count}, 2 );
2051
    is_deeply( $message->{payload}->{modified_item_ids}, [ $item_1->id, $item_3->id ] );
2052
2053
    $schema->storage->txn_rollback;
2054
};

Return to bug 38224