Bug 28328: Adjust tests

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2023-05-03 15:42:15 +02:00 committed by Tomas Cohen Arazi
parent eb3505c7e8
commit 4e933cbc11
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -44,22 +44,22 @@ Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
my $builder = t::lib::TestBuilder->new; my $builder = t::lib::TestBuilder->new;
subtest 'AddBiblio' => sub { subtest 'AddBiblio' => sub {
plan tests => 5; plan tests => 9;
my $marcflavour = 'MARC21'; my $marcflavour = 'MARC21';
t::lib::Mocks::mock_preference( 'marcflavour', $marcflavour ); t::lib::Mocks::mock_preference( 'marcflavour', $marcflavour );
my $record = MARC::Record->new();
my ( $f, $sf ) = GetMarcFromKohaField('biblioitems.lccn'); my ( $f, $sf ) = GetMarcFromKohaField('biblioitems.cn_item');
my $lccn_field = MARC::Field->new( $f, ' ', ' ', my $cn_item_field = MARC::Field->new( $f, ' ', ' ',
$sf => 'ThisisgoingtobetoomanycharactersfortheLCCNfield' ); $sf => 'Thisisgoingtobetoomanycharactersforthe.cn_item.field' );
$record->append_fields($lccn_field); my $record = MARC::Record->new();
$record->append_fields($cn_item_field);
my $nb_biblios = Koha::Biblios->count; my $nb_biblios = Koha::Biblios->count;
my ( $biblionumber, $biblioitemnumber ); my ( $biblionumber, $biblioitemnumber );
warnings_like { ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ) } warnings_like { ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ) }
[ qr/Data too long for column 'lccn'/, qr/Data too long for column 'lccn'/ ], [ qr/Data too long for column 'cn_item'/, qr/Data too long for column 'cn_item'/ ],
"expected warnings when adding too long LCCN"; "expected warnings when adding too long cn_item";
is( $biblionumber, undef, is( $biblionumber, undef,
'AddBiblio returns undef for biblionumber if something went wrong' ); 'AddBiblio returns undef for biblionumber if something went wrong' );
is( $biblioitemnumber, undef, is( $biblioitemnumber, undef,
@ -68,6 +68,23 @@ subtest 'AddBiblio' => sub {
is( Koha::Biblios->count, $nb_biblios, is( Koha::Biblios->count, $nb_biblios,
'No biblio should have been added if something went wrong' ); 'No biblio should have been added if something went wrong' );
( $f, $sf ) = GetMarcFromKohaField('biblioitems.lccn');
my $lccn_field = MARC::Field->new( $f, ' ', ' ',
$sf => 'ThisisNOTgoingtobetoomanycharactersfortheLCCNfield' );
$record = MARC::Record->new();
$record->append_fields($lccn_field);
warnings_like { ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ) }
[],
"No warning expected when adding a long LCCN";
isnt( $biblionumber, undef,
'AddBiblio returns the biblionumber' );
isnt( $biblioitemnumber, undef,
'AddBiblio returns the biblioitemnumber'
);
is( Koha::Biblios->count, $nb_biblios + 1,
'The biblio should have been added if nothing went wrong' );
t::lib::Mocks::mock_preference( 'AutoLinkBiblios', $marcflavour ); t::lib::Mocks::mock_preference( 'AutoLinkBiblios', $marcflavour );
t::lib::Mocks::mock_preference( 'AutoCreateAuthorities', $marcflavour ); t::lib::Mocks::mock_preference( 'AutoCreateAuthorities', $marcflavour );
t::lib::Mocks::mock_preference( 'autoControlNumber', "OFF" ); t::lib::Mocks::mock_preference( 'autoControlNumber', "OFF" );